You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.
Can anyone give me any pointers to where I should be looking to create an automatic message to an email address if the last product is bought and so makes it out of stock.
This would be easier to control our inventory for items that we only stock very few of.
Offline
Look at the 0400_Custom routine in the {private}/apps/ccp0/CCP_Orders/ext directory. That routine is called every time an order is processed and, as you'll probably notice, it is called after 0300_inventory which adjusts inventory counts. You could hook into 0400 (and probably even 0300) to accomplish what you're looking for.
Offline
Hi antsevo,
did you get any further with this idea ,
Offline
Sorry - have not started on it yet - will look at it Monday/tuesday, will let you know how i get on
Offline
Ok, taking a look at this again...
I am looking at the 0300 inventory file and have added this, just to get me started, but nothing happens, am I missing something again?
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['inventory'] - $cartinv_opt[$row['id']]; if ($inv <= 0) {$inv = '0';} if ($inv == 0) { $to = "anthony@forafters.co.uk"; $subject = "PRODUCT OUT OF STOCK"; $body = "A product has just gone out of stock"; $mail_sent = @mail( $to, $subject, $body ); } else { $data = array('inventory' => $inv); } // End of if statement.
Offline
Remove the $mail_sent = @ from the call to mail and see what it's reporting. You don't need to assign the result of mail to a variable so simply using
mail( $to, $subject, $body );
will work. When it's working put the @ back in front of it.
Offline
Hmm, I tried that (and turned off my junk mail - just in case)
And it's still not sending any mail, don't know why though...
It must be something simple
Offline
My latest code is:
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['inventory'] - $cartinv_opt[$row['id']]; if ($inv <= 0) {$inv = '0';} if ($inv == 0) { $data = array('inventory' => $inv); $to = "anthony@forafters.co.uk"; $subject = "PRODUCT OUT OF STOCK"; $body = "A product has just gone out of stock"; mail( $to, $subject, $body ); } else { $data = array('inventory' => $inv); } // End of if statement.
This updates the inventory, but does not send an email, I know the email send works as I tested it from within this php.
So it must be something to do with:
if ($inv <= 0) {$inv = '0';} if ($inv == 0) {
I can't see anywhere else as to why this does not work.
Can someone confirm that this statement does indeed say "if inventory is equal to zero" the do something...
Offline
Not sure why you have the additional conditional testing in there but something like this should work for what you're trying to do:
<?php if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['inventory'] - $cartinv_opt[$row['id']]; if ($inv <= 0) { $data = array('inventory' => $inv); $to = "anthony@forafters.co.uk"; $subject = "PRODUCT OUT OF STOCK"; $body = "A product has just gone out of stock"; mail( $to, $subject, $body ); } } } else { $data = array('inventory' => $inv); } // End of if statement. ?>
Offline
Hi Dave, thanks for replying
The additional clause is in there by default
if ($inv <= 0) {$inv = '0';}
when I ran the alterations you wrote, the cart stopped again, and I have tried be-bugging, but nothing comes up for that screen.
I just can't understand why it wont work...
Offline
When I use this code:
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['inventory'] - $cartinv_opt[$row['id']]; if ($inv <= 0) {$inv = '0';} if ($inv == 0) { $data = array('inventory' => $inv); $to = "anthony@forafters.co.uk"; $subject = "PRODUCT OUT OF STOCK"; $body = "A product has just gone out of stock"; mail( $to, $subject, $body ); } else { $data = array('inventory' => $inv); } // End of if statement.
in the
// +-- // | If our product array is not empty, work with it to update // | product inventories. // +--
Actually it's the same now if i use it in
// +-- // | If our option array is not empty, work with it to update // | product inventories. // +--
I have also tried:
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['inventory'] - $cartinv_opt[$row['id']]; if ($inv <= 0) {$inv = '0';} $to = "anthony@forafters.co.uk"; $subject = "PRODUCT OUT OF STOCK"; $body = "A product has just gone out of stock"; mail( $to, $subject, $body ); $data = array('inventory' => $inv); $update_clause = $this->KHXC_DB->clause_update(array('table' => $table, 'data' => $data)); if (!($this->IsError($update_clause))) { $sql = $update_clause . ' WHERE id=' . $this->KHXC_DB->quote($row['id']); $this->KHXC_DB->sql_do(array('sql' => $sql, 'table' => $table)); } // End of if statement. } // End of foreach statement. } // End of if statement. } // End of if statement.
but to no avail
part of the code, the it sends me an email and the order but does not update the inventory, in fact I could have 500 units left, and it still sends me an email saying it is out of stock
Last edited by antsevo (09-08-2008 08:54:52)
Offline
Thanks Dave, from what you put, I think I have it:
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['invlevel'] - $cartinv_prd[$row['id']]; if ($inv <= 0) {$inv = '0';$to = "anthony@forafters.co.uk"; $subject = "PRODUCT OUT OF STOCK"; $body = "A product has just gone out of stock"; mail( $to, $subject, $body );} $data = array('invlevel' => $inv); $update_clause = $this->KHXC_DB->clause_update(array('table' => $table, 'data' => $data)); if (!($this->IsError($update_clause))) { $sql = $update_clause . ' WHERE id=' . $this->KHXC_DB->quote($row['id']); $this->KHXC_DB->sql_do(array('sql' => $sql, 'table' => $table)); } // End of if statement. } // End of foreach statement. } // End of if statement. } // End of if statement.
Offline
Ok, I now have 1 final problem.
I get an email with the product number that has gone out of stock, however if 2 prodcuts go out od stock at the same time, then I get 2 emails but only one of the products id number in both emails.
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['invlevel'] - $cartinv_prd[$row['id']]; if ($inv <= 0) {$inv = '0'; $to = "anthony@forafters.co.uk"; $subject = "PRODUCT OUT OF STOCK"; $body = $this->KHXC_DB->quote($id); mail( $to, $subject, $body ); } $data = array('invlevel' => $inv); $update_clause = $this->KHXC_DB->clause_update(array('table' => $table, 'data' => $data)); if (!($this->IsError($update_clause))) { $sql = $update_clause . ' WHERE id=' . $this->KHXC_DB->quote($row['id']); $this->KHXC_DB->sql_do(array('sql' => $sql, 'table' => $table)); } // End of if statement.
I suppose I could try and latch onto the order id, look at the order and see what product may have gone out of stock, but that seems long winded.
Any ideas as to why it is not sending me both products out of stock?
Offline
Sorry, that was a quick and easy resolve
$body = $this->KHXC_DB->quote($row['id']);
Offline
Sorry, last one in this, how do I also move the sort order of the product to 99
this is what I thought, but it did not work
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['invlevel'] - $cartinv_prd[$row['id']]; if ($inv <= 0) {$inv = '0'; $data = array('sortorder' => '99'); $to = "anthony@forafters.co.uk"; $subject = "PRODUCT OUT OF STOCK"; $body = $this->KHXC_DB->quote($row['id']); mail( $to, $subject, $body ); }
In the meantime this seems to be my almost final version, and works a treat
... if anyone is interested - this also sends a email with the direct link to the admin side of ccp straight into the product i need, which saves lots of time...
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['invlevel'] - $cartinv_prd[$row['id']]; if ($inv <= 0) {$inv = '0'; $to = "your@email.co.uk;your2nd@email.co.uk"; $subject = 'PRODUCT OUT OF STOCK--- ' . $row['id']; $body = 'http://www.YOURWEBADDRESS.co.uk/admin.php?app=gbu&ns=manageprod&func=dbupdate&funcid=' . $row['id']; mail($to, $subject, $body); } $data = array('invlevel' => $inv);
Last edited by antsevo (09-08-2008 12:04:00)
Offline
Antsevo, I've read through the thread but I'm getting a bit lost - could you make one final post with the full working code and where it's supposed to go? Why are you changing the sort order? To move the the product to the bottom of the page?
Regards,
James...
Offline
Hi James,
Ignore the bit about the sort order, as I have not come up with a solution to this, the only reason i wanted it in, is because I can then move that product to the bottom of the list of products, so customer only see in stock products first.
I would also say that it has transformed the inventory part of our business, in fact so much so it saves us an hour a day.. anyway here is the code:
Alter the code (backup first) in the:
{private}/apps/ccp0/CCP_Orders/ext directory. and look for the 0300_inventory
Around line 223 change
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['invlevel'] - $cartinv_prd[$row['id']]; if ($inv <= 0) {$inv = '0';} $data = array('invlevel' => $inv); $update_clause = $this->KHXC_DB->clause_update(array('table' => $table, 'data' => $data)); if (!($this->IsError($update_clause))) { $sql = $update_clause . ' WHERE id=' . $this->KHXC_DB->quote($row['id']); $this->KHXC_DB->sql_do(array('sql' => $sql, 'table' => $table)); } // End of if statement. } // End of foreach statement. } // End of if statement. } // End of if statement.
to
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['invlevel'] - $cartinv_prd[$row['id']]; if ($inv <= 0) {$inv = '0'; $to = "name@forafters.co.uk;name2@forafters.co.uk"; $subject = 'PRODUCT OUT OF STOCK--- ' . $row['id']; $body = 'http://www.forafters.co.uk/admin.php?app=gbu&ns=manageprod&func=dbupdate&funcid=' . $row['id']; mail($to, $subject, $body); } $data = array('invlevel' => $inv); $update_clause = $this->KHXC_DB->clause_update(array('table' => $table, 'data' => $data)); if (!($this->IsError($update_clause))) { $sql = $update_clause . ' WHERE id=' . $this->KHXC_DB->quote($row['id']); $this->KHXC_DB->sql_do(array('sql' => $sql, 'table' => $table)); } // End of if statement. } // End of foreach statement. } // End of if statement. } // End of if statement.
Hope that helps.
I have not touched on product option, as we do that a different way, this will email you everytime a product goes out of stock, and give you a link to click which will take you directly to the admin product page to simply change the inventory levels, or do what ever
Offline
Thanks! I was telling my wife about this and she had a great suggestion...what if it emails ALSO when stock is less than 10 or 5 so you know it's getting low to reorder? I would also want the stock = 0 email but can an 'elseif' be added?
Offline
I was curious, when is the email sent? Does this script run every time any order is placed to check if the inventory dropped to 0? Or does it run once at night?
James...
Offline
The 0300_inventory program is executed when an order is processed. From the looks of where the changes are being made it will only do the checking and note sending if an order is complete.
Offline
Ah, yes sorry, thats correct, however if you have a pending order, that then completes (ie cheque cleared, etc), then run the update inventory, it will then go through the right process, and notify you when out of stock.
I suppose everyone has different circumstances, this was modified in the way that our company runs.
Offline
Actually the way you've done it is the correct way. Until an order is complete the inventory shouldn't be adjusted. And you don't want to do your testing until after an adjustment has taken place.
Offline
i'd like to modify it to send us an email if the product drops to 5 or less or 10 or less...but I'm not sure I understand why the test for 0 or less than 0...why does it then assign 0 to it if it's already holding that value? and how could it ever get to less than 0?
Offline
wyattea wrote:
but I'm not sure I understand why the test for 0 or less than 0...why does it then assign 0 to it if it's already holding that value? and how could it ever get to less than 0?
It's defensive programming. The database could have been updated manually and made the field either negative somehow or a non-numeric value. Forcing it to zero ensures that the resulting update of the inventory level has a valid value again and prevents other errors if the value was in fact non-numeric or less than zero.
Offline