If this is your first visit, check our documentation. To post, register or login.

Checking Sale Status

Started by mattbough on 4 Jul 2017, 8:12 AM · Views: 4,842

Results 1 to 6 of 6
4 Jul 2017, 8:12 AM
#1
mattbough avatar

mattbough

New Zenner

Join Date:
Feb 2015
Location:
UK
Posts:
13
Plugin Contributions:
0

Post #1 by mattbough

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!

5 Jul 2017, 12:58 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Post #2 by mc12345678

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

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

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

6 Jul 2017, 12:52 PM
#3
mattbough avatar

mattbough

New Zenner

Join Date:
Feb 2015
Location:
UK
Posts:
13
Plugin Contributions:
0

Post #3 by mattbough

Thanks for this, would it be possible to use ```
$sale->Recordcount() > 0


That way I could check and carry on with the pricing logic that I'm doing for the structured data.
6 Jul 2017, 2:40 PM
#4
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,974
Plugin Contributions:
8

Post #4 by carlwhat

mattbough:

Thanks for this, would it be possible to use ```
$sale->Recordcount() > 0

> 
> 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
if ($products_base_price !== $specials_price) {
//your stuff here
}

good luck.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

6 Jul 2017, 6:05 PM
#5
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Post #5 by mc12345678

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:

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

10 Jul 2017, 7:21 AM
#6
mattbough avatar

mattbough

New Zenner

Join Date:
Feb 2015
Location:
UK
Posts:
13
Plugin Contributions:
0

Post #6 by mattbough

Excellent thank you, this seems to work as expected!

mc12345678:

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:

if ($new_price !== false) {
// action to take if product has either or both a special or a sale
}