Results 1 to 2 of 2
  1. #1

    Default Send low stock email based on value in custom minimum field for individual products

    Giving back to the community here is what I did that may help some others in creating this functionality. I created a custom field in product for minimum stock amount and Maximum stock to have on hand. This code will check the minumum field instead of default zen field against actual inventory and then send a low stock email if falls below the minimum field. It allows you to have individually set email notifications for each product instead of one value only for all like default zencart. FYI I am not much of a coder so hope there are no mistakes in this, but it works.

    File to change: Includes/classes/order.php Zen 1.5.1
    Add yellow sections, created these variables $stock_minvaljp, $stock_maxvaljp

    Around line 734
    // Stock Update - Joao Correia
    //JP Added line below to add to query p.products_minmaxjp, p.products_maxjp
    if (STOCK_LIMITED == 'true') {
    if (DOWNLOAD_ENABLED == 'true') {
    $stock_query_raw = "select p.products_quantity, pad.products_attributes_filename, p.product_is_always_free_shipping, p.products_minmaxjp, p.products_maxjp
    from " . TABLE_PRODUCTS . " p
    left join " . TABLE_PRODUCTS_ATTRIBUTES . " pa
    on p.products_id=pa.products_id
    left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
    on pa.products_attributes_id=pad.products_attributes_id
    WHERE p.products_id = '" . zen_get_prid($this->products[$i]['id']) . "'";

    // Will work with only one option for downloadable products
    // otherwise, we have to build the query dynamically with a loop
    $products_attributes = $this->products[$i]['attributes'];
    if (is_array($products_attributes)) {
    $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
    }
    $stock_values = $db->Execute($stock_query_raw);


    } else {
    $stock_values = $db->Execute("select * from " . TABLE_PRODUCTS . " where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'");

    Around line 766- Get info from our custom fields entered in products
    // do not decrement quantities if products_attributes_filename exists
    if ((DOWNLOAD_ENABLED != 'true') || $stock_values->fields['product_is_always_free_shipping'] == 2 || (!$stock_values->fields['products_attributes_filename']) ) {
    $stock_left = $stock_values->fields['products_quantity'] - $this->products[$i]['qty'];
    //JP Added 2lines below and custom variable $stock_minvaljp and $stock_maxvaljp
    $stock_minvaljp = $stock_values->fields['products_minmaxjp'];
    $stock_maxvaljp = $stock_values->fields['products_maxjp'];

    $this->products[$i]['stock_reduce'] = $this->products[$i]['qty'];
    } else {
    $stock_left = $stock_values->fields['products_quantity'];

    }

    Around line 786 – Change to check our new variable to determine if need to send email.
    // for low stock email
    //JP Added changed line below to use variable $stock_min
    if ( $stock_left <= $stock_minvaljp ) {
    // WebMakers.com Added: add to low stock email
    //JP Added changed to add low stock min value and added () to make easier to read in email
    $this->email_low_stock .= 'ID# ' . zen_get_prid($this->products[$i]['id']) . "\t\t" . ' (Item: ' . $this->products[$i]['model'] . "\t\t" . ') ' . $this->products[$i]['name'] . "\t\t" . ' (Qty Left:) ' . $stock_left . ' (Stock Min/Max:) ' . $stock_minvaljp . '/' . $stock_maxvaljp . "\n";

  2. #2
    Join Date
    May 2006
    Posts
    15
    Plugin Contributions
    0

    Default Re: Send low stock email based on value in custom minimum field for individual produc

    Hello.. I'm having trouble implementing this.. where are the edits for the products page to put the actual quantity levels?

 

 

Similar Threads

  1. Replies: 3
    Last Post: 9 Dec 2013, 05:32 PM
  2. Shipping Costs based on Total Value for individual cartons
    By sivivatu in forum Built-in Shipping and Payment Modules
    Replies: 1
    Last Post: 1 Jun 2009, 05:37 PM
  3. allow ordering less than Product Qty Minimum when stock is low
    By dandan in forum Customization from the Admin
    Replies: 1
    Last Post: 30 May 2008, 10:13 PM
  4. automatic sales for low stock products - possible ?
    By sanji in forum General Questions
    Replies: 1
    Last Post: 25 Jan 2007, 06:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR