Forums / Basic Configuration / Can I automatically Free Shipping Icon if product qualifies by price?

Can I automatically Free Shipping Icon if product qualifies by price?

Views: 3,876

Results 1 to 11 of 11
14 Jun 2016, 7:41 AM
#1
enzo_ita avatar

enzo_ita

Zen Follower

Join Date:
Jul 2009
Posts:
402
Plugin Contributions:
0

Can I automatically Free Shipping Icon if product qualifies by price?

Hi,
I have finally completed the transition from 1.5.1 to 1.5.5
It took me a lot of work, but I have learned a lot during the prepration.
I have a question that I can not solve on my own.
I want to have the free shipping icon to show automatically when a product costs more than the value set in the freeoption module.
Is this possible? How can I do it?
In tpl_product_info_display-php I can see

<!--bof free ship icon  -->
<?php if(zen_get_product_is_always_free_shipping($products_id_current) && $flag_show_product_info_free_shipping) { ?>
<div id="freeShippingIcon"><?php echo TEXT_PRODUCT_FREE_SHIPPING_ICON; ?></div>
<?php } ?>
<!--eof free ship icon  -->

I think it could be possible to add something like

<!--bof free ship icon --> <?php if(zen_get_product_is_always_free_shipping($products_id_current) && $flag_show_product_info_free_shipping or $products_price>I do not kno what ) { ?> <div id="freeShippingIcon"><?php echo TEXT_PRODUCT_FREE_SHIPPING_ICON; ?></div> <?php } ?> <!--eof free ship icon --> And it should work. Can someone help me? Thanks enzo from Italy ciao ciao
14 Jun 2016, 5:40 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Can I automatically Free Shipping Icon if product qualifies by price?

You can mark specific product as being free shipping in the catalog on the product's info page. This would spare you from modifying core code. Does that work for you?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

15 Jun 2016, 7:57 AM
#3
enzo_ita avatar

enzo_ita

Zen Follower

Join Date:
Jul 2009
Posts:
402
Plugin Contributions:
0

Re: Can I automatically Free Shipping Icon if product qualifies by price?

mc12345678:

You can mark specific product as being free shipping in the catalog on the product's info page. This would spare you from modifying core code. Does that work for you?
Thanks, but I already do that for products that I want to promote and would not be not be free shipping normally.
I wanted to have it automated for all the other products also because prices may change and it would be much easier if the icon would appear and disappear when the price changes.
ciao ciao

15 Jun 2016, 8:36 AM
#4
enzo_ita avatar

enzo_ita

Zen Follower

Join Date:
Jul 2009
Posts:
402
Plugin Contributions:
0

Re: Can I automatically Free Shipping Icon if product qualifies by price?

I think I got something that may work and it is as simple as changing

<?php if(zen_get_product_is_always_free_shipping($products_id_current) && $flag_show_product_info_free_shipping) { ?>

to

<?php if((zen_get_product_is_always_free_shipping($products_id_current) && $flag_show_product_info_free_shipping || ($products_price >=MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN))
{ ?>

the problem I have is that $products_price output's is € 90,10 and I think that the output is not recognized as a number in the || logical operator, therefore the free shipping icon is always shown.
Is there any way to clean up the output for the logical operator so it can compare numbers with numbers? Also probably the value to compare is xx.xx while the
$products_price number is xx,xx and this creates another problem I think.

Thanks for help

ciao from Italy
enzo

15 Jun 2016, 10:21 AM
#5
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Can I automatically Free Shipping Icon if product qualifies by price?

If you're going to modify the core code (instead of perhaps adding a listener to modify the free_shipping flag of the product say in or off of the header_php.php or elsewhere) then there is already the $products_id_current variable that can be used to lookup the price (need to consider what aspect of the price you are really considering because you may want to take into account a product priced by attributes and the effect of one attribute causing the price to be below the threshold and another putting it over), but yes you would have an issue especially if you offer multiple currencies and the value of comparison in one currency is significantly different than that of another. (ie. Yen is likely to be always free shipping just because of conversion factors, if currency conversion is included in the price lookup function used.)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

15 Jun 2016, 10:27 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Can I automatically Free Shipping Icon if product qualifies by price?

Personally, I'd probably do something as say an admin init_ type file, check to see if a product was being updated and if so, then to run the comparison and make the database change for the product. That is at least if prices are updated through the admin. If not, and say using a bulk update program, then I would either incorporate such a switch into the updater (though a "shortcut" route and likely to cause a headache later when trying to troubleshoot why this keeps happening) or just incorporate into the price update process to set or clear that flag as approriate.

Whatever the case, hopefully you will heavily document this change both in the code and in whatever notes you take/keep.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

15 Jun 2016, 5:27 PM
#7
enzo_ita avatar

enzo_ita

Zen Follower

Join Date:
Jul 2009
Posts:
402
Plugin Contributions:
0

Re: Can I automatically Free Shipping Icon if product qualifies by price?

mc12345678:

If you're going to modify the core code (instead of perhaps adding a listener to modify the free_shipping flag of the product say in or off of the header_php.php or elsewhere) then there is already the $products_id_current variable that can be used to lookup the price (need to consider what aspect of the price you are really considering because you may want to take into account a product priced by attributes and the effect of one attribute causing the price to be below the threshold and another putting it over), but yes you would have an issue especially if you offer multiple currencies and the value of comparison in one currency is significantly different than that of another. (ie. Yen is likely to be always free shipping just because of conversion factors, if currency conversion is included in the price lookup function used.)
Thanks a lot for your comments.
I see what you mean and I agree.
By now I just hacked the code and found the way to make it work in both product_listing.php and tpl_product_info_display.php
I made notes about the mods on head of the files.
Thanks again.
enzo

15 Jun 2016, 5:37 PM
#8
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Can I automatically Free Shipping Icon if product qualifies by price?

Glad it works.

If you have the time, could you post your solution so that other interested individuals can reproduce your success?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

15 Jun 2016, 10:02 PM
#9
enzo_ita avatar

enzo_ita

Zen Follower

Join Date:
Jul 2009
Posts:
402
Plugin Contributions:
0

Re: Can I automatically Free Shipping Icon if product qualifies by price?

mc12345678:

Glad it works.

If you have the time, could you post your solution so that other interested individuals can reproduce your success?
Here we go,
provided you have enabled the freeoptions with a value that allows free shipping over a order value, if you mod (after backing up the original files) the two files, you will have the free shipping icon appear when the product price is over that limit.
If it does not work, let me know.
includes/templates/yourtemplate/templates/tpl_product_info_display.php
find
line 112
```php

<?php if((zen_get_product_is_always_free_shipping($products_id_current) && $flag_show_product_info_free_shipping){ ?>
<div id="freeShippingIcon"><?php echo TEXT_PRODUCT_FREE_SHIPPING_ICON; ?></div>
<?php } ?>
change
	```php
<?php if((zen_get_product_is_always_free_shipping($products_id_current) && $flag_show_product_info_free_shipping)|| ($cleaned = str_replace("€ " , "",$products_price) >=MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN)){ ?>
	<div id="freeShippingIcon"><?php echo TEXT_PRODUCT_FREE_SHIPPING_ICON; ?></div>
	<?php } ?>

includes/module/yourtemplate/product_listing.php
find

$lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '' : '') : '');

change

$lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) || ((int)preg_replace('#[^0-9]+#', '', $lc_price)/100 >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '' : '') : '');

If you try it and it works, let me know if it does not work, let me know,but I do not take responsibility about, however...
ciao from Italy

15 Jun 2016, 10:04 PM
#10
enzo_ita avatar

enzo_ita

Zen Follower

Join Date:
Jul 2009
Posts:
402
Plugin Contributions:
0

Re: Can I automatically Free Shipping Icon if product qualifies by price?

mc12345678:

Glad it works.

If you have the time, could you post your solution so that other interested individuals can reproduce your success?
Here we go,
provided you have enabled the freeoptions with a value that allows free shipping over a order value, if you mod (after backing up the original files) the two files, you will have the free shipping icon appear when the product price is over that limit.
If it does not work, let me know.
includes/templates/yourtemplate/templates/tpl_product_info_display.php
find
line 112
```php

<?php if((zen_get_product_is_always_free_shipping($products_id_current) && $flag_show_product_info_free_shipping){ ?>
<div id="freeShippingIcon"><?php echo TEXT_PRODUCT_FREE_SHIPPING_ICON; ?></div>
<?php } ?>
change
	```php
<?php if((zen_get_product_is_always_free_shipping($products_id_current) && $flag_show_product_info_free_shipping)|| ($cleaned = str_replace("€ " , "",$products_price) >=MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN)){ ?>
	<div id="freeShippingIcon"><?php echo TEXT_PRODUCT_FREE_SHIPPING_ICON; ?></div>
	<?php } ?>

includes/module/yourtemplate/product_listing.php
find
line 149

    $lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '' : '') : '');

change

$lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) || ((int)preg_replace('#[^0-9]+#', '', $lc_price)/100 >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '' : '') : '');

If you try it and it works, let me know if it does not work, let me know,but I do not take responsibility about, however...
ciao from Italy

20 Jun 2016, 10:59 PM
#11
enzo_ita avatar

enzo_ita

Zen Follower

Join Date:
Jul 2009
Posts:
402
Plugin Contributions:
0

Re: Can I automatically Free Shipping Icon if product qualifies by price?

Hi all,
I noticed that there was a mistake in my previous code.

in includes/modules/yourtemplate/product_listing_php find

$lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '' : '') : '');  

and substitute with

$clean_normal_price = zen_get_products_base_price($listing->fields['products_id']);
$clean_special_price = zen_get_products_special_price($listing->fields['products_id']);
if  ($clean_normal_price >= $clean_special_price) {
	$rcs_price = $clean_special_price;
	}
if ($clean_special_price == ''){
	$rcs_price = $clean_normal_price;
	}
	  $lc_text .= '' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id'])|| (($rcs_price * 1.22) >= (MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN)) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '' : '') : '');

in includes/templates/yourtemplate/tpl_product_info_display.php find

	<!--bof free ship icon  -->
<?php if(zen_get_product_is_always_free_shipping($products_id_current) && $flag_show_product_info_free_shipping) { ?>
<div id="freeShippingIcon"><?php echo TEXT_PRODUCT_FREE_SHIPPING_ICON; ?></div>
<?php } ?>
<!--eof free ship icon  -->

and substitute with

<!--bof free ship icon  -->
<?php	
$clean_normal_price = zen_get_products_base_price((int)$_GET['products_id']);
$clean_special_price = zen_get_products_special_price((int)$_GET['products_id']);

if  ($clean_normal_price >= $clean_special_price) {
	$rcs_price = $clean_special_price;
	}
if ($clean_special_price == ''){
	$rcs_price = $clean_normal_price;
	}
?>

<?php if((zen_get_product_is_always_free_shipping($products_id_current) && $flag_show_product_info_free_shipping)|| $rcs_price * 1.22 >=MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN){ ?>
<div id="freeShippingIcon"><?php echo TEXT_PRODUCT_FREE_SHIPPING_ICON; ?></div>
<?php } ?>
<!--eof free ship icon  -->

There is an hard coding that I did and it is the VAT adding (1.22 in red)
It is needed to change this to your vat value or better if some knows how to get the value from the db (i spent hours but I did not make it out) please let me know so the code will be more automated for everyone.

Ciao from Italy
enzo