Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2015
    Location
    UK
    Posts
    13
    Plugin Contributions
    0

    Default Checking Sale Status

    Hi,

    Does anyone have an idea how I can check if an item is on sale? I've already set this up for specials using (SHOW_SALE_DISCOUNT ==1) and also for standard prices, but the last bit of the logic is the Salemaker offers.

    I am trying to implement Google structured data within the page for the merchant centre to auto update and doing it like this is the easiest way without messing with any of zen carts core features. If we can keep along with this idea that would be great.

    Thanks!

  2. #2
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Checking Sale Status

    So from the includes/functions/functions_prices.php file from within zen_get_products_specials_price there is the following code which pulls up sale information about/for the given product. The if statement has been "reversed" so that it identifies that a sale is present as compared to the ZC version that asks if there is nothing (<1) to identify that a sale is not present.

    There is other logic throughout ZC that identifies how that sale data is to be used, typically pairing the function with itself but changing the last parameter. Reason for that if not mistaken is to identify how the results from both calls are to be used/applied (ie, if there is a special, if there is a sale, if there are both or obviously neither).

    Code:
          $product_to_categories = $db->Execute("select master_categories_id from " . TABLE_PRODUCTS . " where products_id = '" . $product_id . "'");
          $category = $product_to_categories->fields['master_categories_id'];
          $sale = $db->Execute("select sale_specials_condition, sale_deduction_value, sale_deduction_type from " . TABLE_SALEMAKER_SALES . " where sale_categories_all like '%," . $category . ",%' and sale_status = '1' and (sale_date_start <= now() or sale_date_start = '0001-01-01') and (sale_date_end >= now() or sale_date_end = '0001-01-01') and (sale_pricerange_from <= '" . $product_price . "' or sale_pricerange_from = '0') and (sale_pricerange_to >= '" . $product_price . "' or sale_pricerange_to = '0')");
          if ($sale->RecordCount() > 0) {
            // the product is within a sale condition
          } else {
            // the product does not exist in a sale condition at the moment.
          }
    Depending on how this is being used, could replace the first two lines of code with a single ZC function:
    Code:
    $category = zen_get_products_category_id($product_id);
    Or substitute that function (right hand side without the semicolon) where $category is already used...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Feb 2015
    Location
    UK
    Posts
    13
    Plugin Contributions
    0

    Default Re: Checking Sale Status

    Thanks for this, would it be possible to use
    Code:
    $sale->Recordcount() > 0
    within the tpl_product_info.php file?

    That way I could check and carry on with the pricing logic that I'm doing for the structured data.

  4. #4
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,688
    Plugin Contributions
    9

    Default Re: Checking Sale Status

    Quote Originally Posted by mattbough View Post
    Thanks for this, would it be possible to use
    Code:
    $sale->Recordcount() > 0
    within the tpl_product_info.php file?

    That way I could check and carry on with the pricing logic that I'm doing for the structured data.
    no, that would not work; unless you added all of that additional logic in the above post..

    depending on how your store is set up, this (easier solution) could work in your template file:

    PHP Code:
    if ($products_base_price !== $specials_price) {
    //your stuff here

    good luck.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  5. #5
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Checking Sale Status

    Note that by using the above comparison would be identifying that there is a special or a sale or neither, not just a sale. In both cases yes a price other than the normal price is being reported, but the $specials_price (generated in includes/modules/pages/YOUR_PRODUCT_TYPE/main_template_vars.php) is intended to represent conditions associated with a special/sale, though neither is specifically identified as a result. If though, there is neither a special nor a sale, then $specials_price is not defined because $new_price is false and therefore $specials_price is not set.

    So, in actuality, to identify that a product has a special price or a sale price, the preferred "easier" analysis would be:
    Code:
    if ($new_price !== false) {
     // action to take if product has either or both a special or a sale
    }
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Feb 2015
    Location
    UK
    Posts
    13
    Plugin Contributions
    0

    Default Re: Checking Sale Status

    Excellent thank you, this seems to work as expected!

    Quote Originally Posted by mc12345678 View Post
    Note that by using the above comparison would be identifying that there is a special or a sale or neither, not just a sale. In both cases yes a price other than the normal price is being reported, but the $specials_price (generated in includes/modules/pages/YOUR_PRODUCT_TYPE/main_template_vars.php) is intended to represent conditions associated with a special/sale, though neither is specifically identified as a result. If though, there is neither a special nor a sale, then $specials_price is not defined because $new_price is false and therefore $specials_price is not set.

    So, in actuality, to identify that a product has a special price or a sale price, the preferred "easier" analysis would be:
    Code:
    if ($new_price !== false) {
     // action to take if product has either or both a special or a sale
    }

 

 

Similar Threads

  1. Checking Customer Login status from my Flash application?
    By xanabobana in forum General Questions
    Replies: 7
    Last Post: 1 Aug 2011, 03:21 AM
  2. Replies: 0
    Last Post: 23 Apr 2011, 10:01 AM
  3. Replies: 1
    Last Post: 8 Mar 2011, 04:20 AM
  4. coupon restrictions: by sale status
    By roni in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 3
    Last Post: 19 May 2007, 06:45 AM
  5. Replies: 2
    Last Post: 15 Nov 2006, 07:59 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