Skip to main content

Apply a discount and free shipping with a coupon

More
14 years 2 months ago - 14 years 2 months ago #58719 by gageorion
Hey, great component.

Question: Is there a simple hack to apply a discount when a coupon code is used? I need a coupon to discount each item from $46 to $40 (every item has the same price thus far.) not just a flat rate or percentage of the total sale.

Also, I found a post about free shipping with a coupon but have not been able to make the following hack work, it breaks the whole page. (not a PHP whiz) I don't suppose you could help in giving a sample of how the code would integrate into the existing view to work? I am messing up the syntax somewhere.

In the For Each loop for $rate, I wrote an IF statement:
if (!$this->coupon->discount_code == "Wanderlust2012" && $rate->shipping_name == "Free Shipping Promo"){
//do nothing, this skips the free shipping radio button if coupon code is not valid
}
else
{
// show the remaining shipping methods


Thank you!
Last edit: 14 years 2 months ago by gageorion. Reason: mispelling

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago - 14 years 2 months ago #58739 by Mohamed Thelji
Hello,

Can you show me exactly what is in your "For Each loop for $rate" ?
Last edit: 14 years 2 months ago by Mohamed Thelji.

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago #58822 by gageorion
Below is the entire view code for checkout/shipping... I have not been able to add the IF statement correctly, it was from a different poster. I see where it should be added, I see the For Each loop for $rate but cannot figure out how to successfully add the new code.
Code:
<?php /** * @package HikaShop for Joomla! * @version 1.5.4 * @author hikashop.com * @copyright (C) 2010-2011 HIKARI SOFTWARE. All rights reserved. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ defined('_JEXEC') or die('Restricted access'); ?> <?php if(!empty($this->rates)){ ?> <div class="hikashop_shipping_methods" id="hikashop_shipping_methods"> <fieldset> <legend class="legend"><?php echo JText::_('HIKASHOP_SHIPPING_METHOD');?></legend> <table> <?php $this->setLayout('listing_price'); $this->params->set('show_quantity_field', 0); $auto_select_default = $this->config->get('auto_select_default',2); if($auto_select_default==1 && count($this->rates)>1) $auto_select_default=0; $done=false; $k = 0; foreach($this->rates as $rate){ $checked = ''; if(($this->shipping_method==$rate->shipping_type && $this->shipping_id==$rate->shipping_id)|| ($auto_select_default && empty($this->shipping_id)&&!$done)){ $done = true; $checked = 'checked="checked"'; } if($this->config->get('auto_submit_methods',1) && empty($checked)){ $checked.=' onclick="this.form.submit(); return false;"'; } ?> <tr class="<?php echo "row$k"; ?>"> <td> <input class="hikashop_checkout_shipping_radio" type="radio" name="hikashop_shipping" id="radio_<?php echo $rate->shipping_type.'_'.$rate->shipping_id;?>" value="<?php echo $rate->shipping_type.'_'.$rate->shipping_id;?>" <?php echo $checked; ?> /> </td> <td><label for="radio_<?php echo $rate->shipping_type.'_'.$rate->shipping_id;?>" style="cursor:pointer;"> <span class="hikashop_checkout_shipping_image"> <?php if(!empty($rate->shipping_images)){ $images = explode(',',$rate->shipping_images); if(!empty($images)){ foreach($images as $image){ if(!empty($this->images_shipping[$image])){ ?> <img src="<?php echo HIKASHOP_IMAGES .'shipping/'. $this->images_shipping[$image];?>" alt=""/> <?php } } } } ?> </span> </label> </td> <td><label for="radio_<?php echo $rate->shipping_type.'_'.$rate->shipping_id;?>" style="cursor:pointer;"> <span class="hikashop_checkout_shipping_name"><?php echo $rate->shipping_name;?></span> <span class="hikashop_checkout_shipping_price_full"> <?php if(empty($rate->shipping_price_with_tax)){ $rate->shipping_price_with_tax = $rate->shipping_price; } if(empty($rate->shipping_price)){ $rate->shipping_price = $rate->shipping_price_with_tax; } $taxes = round($rate->shipping_price_with_tax-$rate->shipping_price,$this->currencyHelper->getRounding($rate->shipping_currency_id)); $prices_taxes = 1; if(bccomp($taxes,0,5)==0){ $prices_taxes = 0; } if(bccomp($rate->shipping_price,0,5)===0){ echo JText::_('FREE_SHIPPING'); }else{ echo JText::_('PRICE_BEGINNING'); echo '<span class="hikashop_checkout_shipping_price">'; if($prices_taxes){ echo $this->currencyHelper->format($rate->shipping_price_with_tax,$rate->shipping_currency_id); echo JText::_('PRICE_BEFORE_TAX'); echo $this->currencyHelper->format($rate->shipping_price,$rate->shipping_currency_id); echo JText::_('PRICE_AFTER_TAX'); }else{ echo $this->currencyHelper->format($rate->shipping_price,$rate->shipping_currency_id); } if($this->params->get('show_original_price') && isset($rate->shipping_price_orig) && bccomp($rate->shipping_price_orig,0,5)){ echo JText::_('PRICE_BEFORE_ORIG'); if($prices_taxes){ echo $this->currencyHelper->format($rate->shipping_price_orig_with_tax,$rate->shipping_currency_id_orig); }else{ echo $this->currencyHelper->format($rate->shipping_price_orig,$rate->shipping_currency_id_orig); } echo JText::_('PRICE_AFTER_ORIG'); } echo '</span> '; echo JText::_('PRICE_END'); } ?> </span> </label> <br/> <div class="hikashop_checkout_shipping_description"><?php echo $rate->shipping_description;?></div> </td> </tr> <?php $k = 1-$k; } ?> </table> </fieldset> </div> <?php } ?>

Thank you! Quick response!

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago #58871 by nicolas
It's really easy.

After the line:
foreach($this->rates as $rate){

just add that line:
if ($this->coupon->discount_code != "Wanderlust2012" && $rate->shipping_name == "Free Shipping Promo") continue;

Note that it requires that the coupon and the shipping views are on the same step of the checkout workflow.

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago #58940 by gageorion
Nicolas, THANK YOU! Works lika charm!

Can the something similar be done to apply a discount with a coupon code - making the discount apply ONLY if a coupon code is entered? If so, I can start a new thread.

Your support is great... REDSHOP takes DAYS to get back to you. I am sold on Hikashop!

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago #58991 by nicolas
Discounts are not handled in views but in the price algorithms in classes. You can't change them without hacking the core files of HikaShop. Plus it's a more difficult than that.
It's not impossible but it would require proper development.

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago #59001 by gageorion
Nothing is impossible, however, I know enough to understand what you mean; I thought that might be the case. Oh Well, customer needs to check with me before they advertise discounts the system will not do! It might be a cool feature to allow discounts with a coupon code; maybe add it to the wishlist if it is reasonably feasible.

Thank you, great component great support. I will recommend HS!

Thanks, Nicolas!

Please Log in or Create an account to join the conversation.

More
14 years 2 months ago #59052 by nicolas
I don't really see why that would be useful since you can give the discount amount via the coupon directly.
I don't see a case where you would have to use a coupon+discount system like you want instead of just a coupon.

Please Log in or Create an account to join the conversation.

More
14 years 1 month ago #61680 by woonydanny
is there an option in the new version to give free shipping when members enter a code?

Please Log in or Create an account to join the conversation.

More
14 years 1 month ago #61686 by Mohamed Thelji
Hello,

I think that you should use awocoupon which can handle it.

Hope this will help you.

Please Log in or Create an account to join the conversation.

Time to create page: 0.198 seconds
Powered by Kunena Forum