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.
hmm...so I can just change the if to 'if inv <= 5' since we don't actually want to change the inventory amount. What if I just dupe the whole section of code and change my version to not update the inventory amount but to fire off an email. If I understand it correctly, all we add is this:
$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);
Ths is added after the inv assignment. I can dupe this and change the subject to say only 5 or less...right? Just do it as a separate if statement above. Like this:
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['invlevel'] - $cartinv_prd[$row['id']]; ///// my add-in ///// if ($inv <= 5) { $to = "name@forafters.co.uk;name2@forafters.co.uk"; $subject = 'PRODUCT AT 5 OR LESS --- ' . $row['id']; $body = 'http://www.forafters.co.uk/admin.php?app=gbu&ns=manageprod&func=dbupdate&funcid=' . $row['id']; mail($to, $subject, $body); } //// end of my add-in //// 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.
How does this sound? Would it fire off only the one email if 5 or less, or both emails if inv = 0?
Offline
You'd get 2 notes from the looks of it.
Offline
Ok, I set inventory on a particular item to 11. I created a fake order that was listed as 'not completed' (didn't want to actually PAY for it). Then I went in and changed status to 'Pending Shipment', logged out of admin, logged back in and no change in inventory. Then changed status to 'Completed' and logged out of admin again, logged back in and still no change to inventory?
When is inventory ACTUALLY updated?
James...
Offline
You have to update product and product option inventory in the post order update task for that to take effect
Offline
But I never have to do that when a regular order is placed by a customer?
Offline
Thats because that automatically happens when a customer makes an order and pays for it, as long as the "Perform post order updates" is selected in the payment processor type
Offline
Ok, so that worked (but I'd like to know why I had to do it manually), the inventory for that product is now 10 - my 0300_inventory.php file has the following code:
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['inventory'] - $cartinv_opt[$row['id']]; if ($inv <= 10) { $to = "james@mysite.com;rich@mysite.com;baskets@mysite.com"; $subject = 'PRODUCT AT 10 OR LESS --- ' . $row['id']; $body = 'http://www.mysite.com/admin.php?app=ccp0&ns=manageprod&func=dbupdate&funcid=' . $row['id']; mail($to, $subject, $body); } if ($inv <= 0) {$inv = '0'; $to = "james@mysite.com;baskets@mysite.com;rich@mysite.com"; $subject = 'PRODUCT OUT OF STOCK--- ' . $row['id']; $body = 'https://www.mysite.com/admin.php?app=ccp0&ns=manageprod&func=dbupdate&funcid=' . $row['id']; 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.
So when will i get the email for that product being at 10 or less?
Last edited by wyattea (09-19-2008 06:14:45)
Offline
When you say 'pays for it', does that mean the inventory drops when the status automatically changes to 'pending shipment'? That's technically when we have a confirmed order. That's when inventory should go down. "Completed" is changed manually by us when we ship, which could be two weeks later if a later date is requested.
Offline
Obviously it all depends on how you have set up your cart to work.
With us, if a customer pays by credit card, the it runs everything automatically and we get the order printed out and also an email notification if the item has gone out of stock.
If a customer pays by cheque,bank transfer or paypal (long story), then one we have the payment received or cleared we run the post order updates for that order, it then does as above, prints the invoice and labels out and also emails us if a product is out of stock, as those payment methods are set NOT to update the inventory.
Offline
The only payment option we have is Credit Card (real-time processing). No other payment choice. We get the email from the credit card processor and an email from the cart. We have to manually print it out. How do you make it automatically print? Inventory is updated but I wasnt' sure exactly when since I know it goes down when an order is placed but don't know exactly when it reduces it. Perform post order updates is set to true, so would that mean it'll update inventory when order is confirmed and status is changed automatically to 'pending shipment'?
Offline
Sorry, I may have made it a bit confusing,
The email that we get sent from the cart, is actually a modified email which when received on the orders computer, automatically prints the order onto integrated labels, so we have the invoice,labels and postage paid image all on 1 sheet, ready to pack and send.
Also our store does not have pending shipment, I changed this to "completed", and the computer hadling just the orders, pick this up to automatically print the order
Offline
how many orders do you get per day to require this automation?
Offline
So my question still stands, I did the post order update for inventory but I still haven't received an email even though inventory is confirmed to have dropped to 10 and my code says if inv <= 10, send the emails. Why wouldn't an email have been sent yet?
Offline
Sorry, I don't know the answer to that, as I have not done what you have done, in regards to the notify if inventory drops below 10 etc, so have not tried it, sorry
Offline
Dave, wouldn't this code mean that at 10 it should send an email, then at 9 too, and 8 too, etc.? Inventory dropped to 10 (faked an order and did the post order update) but the email was never sent. Anything obviously wrong with my code?
wyattea wrote:
Ok, so that worked (but I'd like to know why I had to do it manually), the inventory for that product is now 10 - my 0300_inventory.php file has the following code:
Code:
if (!(empty($result))) { foreach ($result as $num => $row) { $inv = $row['inventory'] - $cartinv_opt[$row['id']]; if ($inv <= 10) { $to = "james@mysite.com;rich@mysite.com;baskets@mysite.com"; $subject = 'PRODUCT AT 10 OR LESS --- ' . $row['id']; $body = 'http://www.mysite.com/admin.php?app=ccp0&ns=manageprod&func=dbupdate&funcid=' . $row['id']; mail($to, $subject, $body); } if ($inv <= 0) {$inv = '0'; $to = "james@mysite.com;baskets@mysite.com;rich@mysite.com"; $subject = 'PRODUCT OUT OF STOCK--- ' . $row['id']; $body = 'https://www.mysite.com/admin.php?app=ccp0&ns=manageprod&func=dbupdate&funcid=' . $row['id']; 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.So when will i get the email for that product being at 10 or less?
Offline
A quick glance says yes, it probably should be doing that.
Offline
that, i can deal with...but i haven't gotten an email yet. I even changed the quantity to 1, placed another order, did the post order update and inventory dropped to 0, but i still haven't gotten any emails.
Offline
Do you know for a fact that the PHP mail function works on your installation James?
Offline
hmmm..that's a loaded question. I get contact us mail, order emails, etc. I'm guessing since you're asking the question, those must use sendmail. How can I test for the mail function?
Offline
Nothing within CCP uses the built in PHP mail function which is indeed why I asked the question. Make yourself a little test file that does nothing but call mail with all PHP error reporting turned on (error_reporting (E_ALL); ).
Offline
http://www.grenvillestation.com/PHPTEST.php
run that and tell me if it's working - i don't know php remember
Offline
That's simply calling phpinfo James (don't leave that page up .. it reveals quite a bit about your server).
Offline
I read through and thought the same thing (it revealed a lot) so I was ready to delete once you saw it I don't know how to 'call mail with error reporting turned on'. I can read through code, and understand the basics but I don't know php to write it.
Offline
Ok, I ran this test and it sent me an email and also pasted to the screen 'Mail function succeeded'. Here's the code I used:
<html> <head> <title> PHP Test Script </title> </head> <body> <?php // A test script for sending mail. Put your email address below // and open this script in your browser. $ADDR = "james@mysite.com"; if (mail($ADDR,"Testing","This is a test")) echo "Mail function succeeded<br />"; else echo "Mail function FAILED<br />"; ?> </body> </html>
So this means my mail function is working fine so it's the not the problem...what else could be?
James...
Last edited by wyattea (09-19-2008 09:13:04)
Offline
The format of your to variable is incorrect in the modification you made. If you have a list of addresses they must be in the form:
user@example.com, anotheruser@example.com
It looks like you may be using a ; instead of a ,
Offline