Post by Sledge69 » Thu Nov 20, 2008 3:36 pm

Hi. I'm looking for a script that will reduce every price in the store by a certain percentage (a variable that can be set). Each time I run the script (can cron job it as well) it will reduce every price in the shop by a percentage of itself.

If something costs $100 and the reduction is 2%, after the script is ran the new price would be $98. If I ran the script again the next day, the new price would be $96.04, then $94.11, and on and on. I'm not looking for a script that will reduce everything by the same percentage, but replaces the price of each item with a percent of itself. Have I confused you yet? Sorry.

I'd also like it to have a feature where everything in the store can be listed in one page (so admin can check all the prices at one time).

If something like that is not available I'm willing to pay someone to create such a script. Please send me a PM.

Newbie

Posts

Joined
Thu Nov 20, 2008 3:34 pm

Post by bruce » Thu Nov 20, 2008 5:13 pm

This functionality does not exist as you describe.

However, you could use the import/export module to export your catalog to a spreadsheet, modify all the prices and import the modified catalog back to the store. This process also gives you a global view of all prices from within the spreadsheet.

Obviously the import/export process does not lend itself to being driven by cron but I just wanted you to see an alternative.

cheers

Bruce

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by Qphoria » Thu Nov 20, 2008 9:03 pm

I suppose a php script like this:
http://drupal.org/node/50103

could be used with cron.. or simply by loading it once per day.

Just do a database query on all product prices
and for each loop to set product['price'] *= .02.

Something like:

Code: Select all

$products= $database->getRows("select product_id, price from product");
foreach ($products as $product) {
    $sql = "update product set price = '?' where product_id= '?'";
    $database->query($this->database->parse($sql, ($product[price] - ($product[price] * 0.02)), $product['product_id']));
}

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Sledge69 » Thu Nov 20, 2008 11:14 pm

Thanks for the quick response. I think the sql query would be the best way to go. It could even be written into a php file that can be run by cron. I'm not good at sql, though, and it appears there are some syntax errors in the above query. You probably just meant that as an example of a way to do it. Here's the error that was returned when I ran it on my test store:
Error

There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem

ERROR: Unknown Punctuation String @ 21
STR: ->
SQL: $products= $database->getRows("select product_id, price from product");$products= $database->getRows("select product_id, price from product");$products= $database->getRows("select product_id, price from product");$products= $database->getRows("select product_id, price from product");$products= $database->getRows("select product_id, price from product");


SQL query: Documentation

$products= $database->getRows("select product_id, price from product");

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$products= $database->getRows("select product_id, price from product")' at line 1

Newbie

Posts

Joined
Thu Nov 20, 2008 3:34 pm

Post by Qphoria » Thu Nov 20, 2008 11:19 pm

I gave you the php version of it. Just put it in a file called price_reduce.php and load the file

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Sledge69 » Thu Nov 20, 2008 11:24 pm

:D Shows how much I know...lol.

If I put it in a php file, how will the script know what sql db to run the query on?

*edit*
Fatal error: Call to a member function getRows() on a non-object in /home/eastcoa1/public_html/ecoastelectronics/pricetest/price_reduce.php on line 2
Last edited by Sledge69 on Thu Nov 20, 2008 11:31 pm, edited 1 time in total.

Newbie

Posts

Joined
Thu Nov 20, 2008 3:34 pm

Post by Qphoria » Thu Nov 20, 2008 11:54 pm

lol yea.. i guess you need the rest of the info

Try adding this to your admin/controller/product.php file

Code: Select all

function reducePrice() {
        $response =& $this->locator->get('response');
        $database =& $this->locator->get('database');
        $url      =& $this->locator->get('url');
       
        $products= $database->getRows("select product_id, price from product");
        foreach ($products as $product) {
            $sql = "update product set price = '?' where product_id= '?'";
            $database->query($database->parse($sql, ($product['price'] - ($product['price'] * 0.02)), $product['product_id']));
        }
        
        $response->redirect($url->ssl('product'));        
    }
And call url:
http://www.xxxxxxx.com/admin/index.php? ... educePrice

It should return you back to the admin/product page but the prices should be 2%lower
(Not tested)
Last edited by Qphoria on Fri Nov 21, 2008 1:32 am, edited 1 time in total.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Sledge69 » Fri Nov 21, 2008 1:14 am

(Not tested)
Well I'm happy to test it for you  ;)

Here's what it returned:
Notice: Undefined property: ControllerProduct::$database in /home/eastcoa1/public_html/ecoastelectronics/pricetest/admin/controller/product.php on line 12

Fatal error: Call to a member function parse() on a non-object in /home/eastcoa1/public_html/ecoastelectronics/pricetest/admin/controller/product.php on line 12
Looks like it doesn't like line 12.

Newbie

Posts

Joined
Thu Nov 20, 2008 3:34 pm

Post by Qphoria » Fri Nov 21, 2008 1:19 am

Ah yea... ok I edited the code above your post. Recopy it and try again.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Sledge69 » Fri Nov 21, 2008 1:26 am

IT'S  WORKING!

The prices are falling. Only now the url returns this:
Notice: Use of undefined constant price - assumed 'price' in /home/eastcoa1/public_html/ecoastelectronics/pricetest/admin/controller/product.php on line 12

Notice: Use of undefined constant price - assumed 'price' in /home/eastcoa1/public_html/ecoastelectronics/pricetest/admin/controller/product.php on line 12

Notice: Use of undefined constant price - assumed 'price' in /home/eastcoa1/public_html/ecoastelectronics/pricetest/admin/controller/product.php on line 12

Notice: Use of undefined constant price - assumed 'price' in /home/eastcoa1/public_html/ecoastelectronics/pricetest/admin/controller/product.php on line 12

Notice: Use of undefined constant price - assumed 'price' in /home/eastcoa1/public_html/ecoastelectronics/pricetest/admin/controller/product.php on line 12

Notice: Use of undefined constant price - assumed 'price' in /home/eastcoa1/public_html/ecoastelectronics/pricetest/admin/controller/product.php on line 12

Notice: Use of undefined constant price - assumed 'price' in /home/eastcoa1/public_html/ecoastelectronics/pricetest/admin/controller/product.php on line 12

Notice: Use of undefined constant price - assumed 'price' in /home/eastcoa1/public_html/ecoastelectronics/pricetest/admin/controller/product.php on line 12

Warning: Cannot modify header information - headers already sent by (output started at /home/eastcoa1/public_html/ecoastelectronics/pricetest/admin/controller/product.php:12) in /home/eastcoa1/public_html/ecoastelectronics/pricetest/library/environment/response.php on line 22

Newbie

Posts

Joined
Thu Nov 20, 2008 3:34 pm

Post by Qphoria » Fri Nov 21, 2008 1:32 am

Ok.. i fixed the code again. Recopy it :)

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Sledge69 » Fri Nov 21, 2008 1:51 am

It works perfectly! Thanks. I've had the same request on a few other shopping cart forums (Zen, OS) and no one seems interested. OC just got a new loyal fan. I'm moving some cash to PayPal as we speak, when the move is complete I'll donate to you and the project.

Thanks again. http://www.thepoliticalcapital.com/Smil ... tiphat.gif[/img]

Newbie

Posts

Joined
Thu Nov 20, 2008 3:34 pm
Who is online

Users browsing this forum: No registered users and 26 guests