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

#1 04-22-2008 08:03:56

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

ADMIN SIDE - Email administrator when inventory level reaches Zero

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.


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#2 04-22-2008 12:37:34

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

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

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

 

#3 04-25-2008 04:46:30

picstart
Member
From: United Kingdom
Registered: 07-11-2006
Posts: 428

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

Hi antsevo,

did you get any further with this idea ,


"It may be my worst nightmare at present..... but soon it will be my dream"

Offline

 

#4 04-27-2008 11:49:29

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

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

Sorry - have not started on it yet - will look at it Monday/tuesday, will let you know how i get on


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#5 09-06-2008 12:36:05

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

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

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?

Code:

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.

Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#6 09-06-2008 12:41:42

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

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

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

Code:

mail( $to, $subject, $body );

will work.  When it's working put the @ back in front of it.

Offline

 

#7 09-06-2008 13:12:11

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

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

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


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#8 09-08-2008 07:55:41

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

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

My latest code is:

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.

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:

Code:

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...


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#9 09-08-2008 08:18:52

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

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

Not sure why you have the additional conditional testing in there but something like this should work for what you're trying to do:

Code:

<?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

 

#10 09-08-2008 08:24:33

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

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

Hi Dave, thanks for replying

The additional clause is in there by default

Code:

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...


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#11 09-08-2008 08:31:57

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

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

When I use this code:

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

Code:

// +--
// | 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

Code:

 // +--
// | If our option array is not empty, work with it to update
// | product inventories.
// +--

I have also tried:

Code:

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)


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#12 09-08-2008 08:57:34

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

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

Thanks Dave, from what you put, I think I have it:

Code:

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.

Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#13 09-08-2008 09:57:14

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

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

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.

Code:

 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?


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#14 09-08-2008 10:01:30

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

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

Sorry, that was a quick and easy resolve

Code:

$body = $this->KHXC_DB->quote($row['id']);

Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#15 09-08-2008 10:05:34

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

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

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

Code:

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...

Code:

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)


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#16 09-16-2008 07:44:04

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

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

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

 

#17 09-16-2008 09:29:51

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

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

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

Code:

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

Code:

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


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#18 09-16-2008 11:01:36

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

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

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

 

#19 09-16-2008 12:15:42

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

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

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

 

#20 09-16-2008 12:26:06

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

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

Hi, it runs everytime an order is processed


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#21 09-16-2008 12:28:07

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

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

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

 

#22 09-16-2008 12:44:47

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

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

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.


Anthony - Personalised and Celebrity Face Masks
Anthony - Adult Toys

Offline

 

#23 09-16-2008 12:52:26

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

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

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

 

#24 09-16-2008 14:57:04

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

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

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

 

#25 09-16-2008 15:12:08

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

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

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

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

Board footer