Post by osaeed » Tue Feb 16, 2010 3:38 am

I was wondering, is there any option to setup so that when a product is out of stock, I will be notified by email? It would be handy if I was away and checking my emails.

Thank you very much for this great shopping cart software. I left zencart, because of its ugly design and hard to configure admin options. This software is a piece of art.

Newbie

Posts

Joined
Tue Feb 16, 2010 3:32 am

Post by Qphoria » Tue Feb 16, 2010 9:27 am

1. EDIT: catalog/model/checkout/order.php

2. FIND:

Code: Select all

$this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$product['quantity'] . ") WHERE product_id = '" . (int)$product['product_id'] . "'");
3. AFTER, ADD:

Code: Select all

//Q: Alert store owner on low stock
					$qry = $this->db->query("SELECT quantity, model FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product['product_id'] . "'");
					if ($qry->row['quantity'] < 2) {
					$mail = new Mail($this->config->get('config_mail_protocol'), $this->config->get('config_smtp_host'), $this->config->get('config_smtp_username'), html_entity_decode($this->config->get('config_smtp_password'), ENT_QUOTES, 'UTF-8'), $this->config->get('config_smtp_port'), $this->config->get('config_smtp_timeout')); 						
$mail->setTo($this->config->get('config_email'));
						$mail->setFrom($this->config->get('config_email'));
						$mail->setSender(html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'));
						$mail->setSubject('Low Stock on model: '. $qry->row['model']);
						$mail->setText('Low Stock on model: '. $qry->row['model']);
						$mail->send();
					}
					//

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by osaeed » Tue Feb 16, 2010 9:41 am

I will try this after I reupload the files to my webhost.

I really really appreciate your help. I think you should work for Google, since you know a lot about coding, etc.

Thanks again! :D

Newbie

Posts

Joined
Tue Feb 16, 2010 3:32 am

Post by DLeon » Wed Mar 10, 2010 4:38 am

It doesn't work for me, it sends the mail always! :(

New member

Posts

Joined
Fri Oct 23, 2009 12:23 am

Post by kedgetech » Tue Apr 20, 2010 4:34 pm

Mate here the problem I see.
1. Code is triggred everytime some one orders a product and sends email if product is less than 2

Looks like you need to change the code a little. I am no php king but getting into code because of our friend Open Cart :)

Code: Select all

//Q: Alert store owner on low stock
               $qry = $this->db->query("SELECT quantity, model FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product['product_id'] . "'");
               if ($qry->row['quantity'] [color=#FF0000][b]==[/b][/color] 2) {
               $mail = new Mail($this->config->get('config_mail_protocol'), $this->config->get('config_smtp_host'), $this->config->get('config_smtp_username'), html_entity_decode($this->config->get('config_smtp_password'), ENT_QUOTES, 'UTF-8'), $this->config->get('config_smtp_port'), $this->config->get('config_smtp_timeout'));                   
$mail->setTo($this->config->get('config_email'));
                  $mail->setFrom($this->config->get('config_email'));
                  $mail->setSender(html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'));
                  $mail->setSubject('Low Stock on model: '. $qry->row['model']);
                  $mail->setText('Low Stock on model: '. $qry->row['model']);
                  $mail->send();
               }
               //
>>Should only trigger once when the quantity reaches two. Give it a try and let me know how you go.

User avatar
Active Member

Posts

Joined
Mon Mar 22, 2010 5:20 pm
Location - USA, Australia, India

Post by dramony » Tue Apr 20, 2010 5:23 pm

What is the difference between
(int)$result[] and (int)$product[]?

Because on your example its:

Code: Select all

$this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$product['quantity'] . ") WHERE product_id = '" . (int)$product['product_id'] . "'");
But on my OC1.3.2, its:

Code: Select all

$this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$result['quantity'] . ") WHERE product_id = '" . (int)$result['product_id'] . "'");
Thank you.

Active Member

Posts

Joined
Sat Oct 24, 2009 12:34 pm

Post by kedgetech » Tue Apr 20, 2010 7:40 pm

I am using V1.4.4. There may have been some changes in DB since your version. Did you make any head way on the issue getting several emails. Also I just noticed the mailing logic goes inside 'for loop' you may get more than one emails.

Let me know how you go.

User avatar
Active Member

Posts

Joined
Mon Mar 22, 2010 5:20 pm
Location - USA, Australia, India

Post by karman » Wed Feb 08, 2012 5:27 pm

Sorry old thread, but i made a quick vqmod for 1.5 for this:

http://forum.opencart.com/viewtopic.php ... 54&start=0

Newbie

Posts

Joined
Wed Feb 08, 2012 5:10 pm
Who is online

Users browsing this forum: No registered users and 12 guests