Kryptronic Software Support Forum

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.

  • Index
  •  » ClickCartPro 6
  •  » ADMIN SIDE - Email administrator when inventory level reaches Zero

#26 09-16-2008 15:52:00

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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:

Code:

$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:

Code:

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

 

#27 09-16-2008 21:50:59

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

You'd get 2 notes from the looks of it.

Offline

 

#28 09-19-2008 05:40:36

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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

 

#29 09-19-2008 05:49:06

antsevo
Member
From: Surrey, UK
Registered: 02-08-2005
Posts: 592
Website

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

You have to update product and product option inventory in the post order update task for that to take effect


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#30 09-19-2008 06:09:22

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

But I never have to do that when a regular order is placed by a customer?

Offline

 

#31 09-19-2008 06:11:10

antsevo
Member
From: Surrey, UK
Registered: 02-08-2005
Posts: 592
Website

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#32 09-19-2008 06:14:11

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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?

Last edited by wyattea (09-19-2008 06:14:45)

Offline

 

#33 09-19-2008 06:16:31

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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

 

#34 09-19-2008 06:21:04

antsevo
Member
From: Surrey, UK
Registered: 02-08-2005
Posts: 592
Website

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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.


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#35 09-19-2008 06:25:22

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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

 

#36 09-19-2008 06:30:31

antsevo
Member
From: Surrey, UK
Registered: 02-08-2005
Posts: 592
Website

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#37 09-19-2008 06:38:27

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

how many orders do you get per day to require this automation?

Offline

 

#38 09-19-2008 06:39:37

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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

 

#39 09-19-2008 06:42:01

antsevo
Member
From: Surrey, UK
Registered: 02-08-2005
Posts: 592
Website

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#40 09-19-2008 06:46:31

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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

 

#41 09-19-2008 06:59:13

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

A quick glance says yes, it probably should be doing that.

Offline

 

#42 09-19-2008 07:00:57

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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

 

#43 09-19-2008 07:58:30

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

Do you know for a fact that the PHP mail function works on your installation James?

Offline

 

#44 09-19-2008 08:24:35

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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

 

#45 09-19-2008 08:26:13

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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

 

#46 09-19-2008 08:33:43

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

http://www.grenvillestation.com/PHPTEST.php

run that and tell me if it's working - i don't know php remember smile

Offline

 

#47 09-19-2008 08:36:56

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

That's simply calling phpinfo James (don't leave that page up .. it reveals quite a bit about your server).

Offline

 

#48 09-19-2008 08:39:27

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

I read through and thought the same thing (it revealed a lot) so I was ready to delete once you saw it smile 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

 

#49 09-19-2008 09:12:39

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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:

Code:

<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

 

#50 09-19-2008 09:39:19

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: ADMIN SIDE - Email administrator when inventory level reaches Zero

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

 
  • Index
  •  » ClickCartPro 6
  •  » ADMIN SIDE - Email administrator when inventory level reaches Zero

Board footer