Discount being applied to individual products

  • Posts: 122
  • Thank you received: 0
11 years 2 weeks ago #156246

-- url of the page with the problem -- : starsupplyalliance.com
-- HikaShop version -- : 2.3.1
-- Joomla version -- : 3.2
-- PHP version -- : 5.4
-- Browser(s) name and version -- : XXXXX x.x.x
-- Error-message(debug-mod must be tuned on) -- : Error_message

I need the discount to be applied to the total purchase amount not the individual products purchased. I have used the Orders / Discounts /Coupons set up as advised and I attach a screen shot of one of the coupons.

How do I get the coupon to reflect the total amount in the cart?

Many thanks,

Mike

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

  • Posts: 2143
  • Thank you received: 747
11 years 2 weeks ago #156286

Reads like you haven't configured the coupon properly.

Go into the discount/coupon and check the settings. There's one where the on-board help says, "Coupon percentage applies to product only : When a percentage is entered for the coupon and that a product or a category is selected for the coupon, if you activate that option, the coupon value will be based on the price of that product in the cart or on the sum of prices of all the products of the cart which are in that category."

If it's all set okay, the coupon will apply not to a single product, but to the (sub)total of the cart, means all items in the cart, before shipping.

Still unsure? Then click on "Help" in the toolbar while there...


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )

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

  • Posts: 83932
  • Thank you received: 13588
  • MODERATOR
11 years 2 weeks ago #156261

Hi,

We didn't get any screenshot in your message. Could you try again to attach it please ?
Without knowing how the coupon is setup it's hard to say what could be wrong.

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

  • Posts: 122
  • Thank you received: 0
11 years 2 weeks ago #156407

Hi guys,

I attach the screenshot of the coupon set up and the complete coupon list.

I have the Category set to 2 product category

Whether I set Coupon percentage applies to product only to Yes or No the discount applies 10% which is the $1000 bracket coupon rather than the 15%

How do I get the 15% discount on the total?

Thanks,

Mike

Attachments:

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

  • Posts: 83932
  • Thank you received: 13588
  • MODERATOR
11 years 2 weeks ago #156449

Hi,

I would recommend to remove the category selection and turn off the option " Coupon percentage applies to product only" so that it applies to the total purchased order. Make sure that you do that for all the coupons.

It should work fine then.

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

  • Posts: 122
  • Thank you received: 0
11 years 2 weeks ago #156567

Hi Nicolas,

I followed your instructions and now the cart seems to me calculating the discount across the whole cart correctly but it seems to be only using the lowest rate of 5% to make the discount even when the order is above $1000 which should give a rate of 10% - see screenshots.

What could be causing this issue?

Thanks,

Mike

Attachments:

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

  • Posts: 12953
  • Thank you received: 1778
11 years 2 weeks ago #156573

Hello Mike,
I think that you should also set a "Maximum order value" for your coupons like 599.99 for your 5% coupon.

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

  • Posts: 122
  • Thank you received: 0
11 years 2 weeks ago #156739

Hello Mohamed,

Your suggestion makes sense to me but I cannot see this option - see attached screenshot.

Please advise.

Thanks,

Mike

Attachments:

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

  • Posts: 13201
  • Thank you received: 2322
11 years 2 weeks ago #156877

Hi,

There is indeed not this option for the coupons.

I have reproduced the issue on my local. I add in the todo list to debug that as soon as possible.
We will keep you informed. Thanks for the report.

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

  • Posts: 13201
  • Thank you received: 2322
11 years 4 days ago #158353

Hi,

We have solved this problem, it will be available in the next release.
To correct it now, thanks to edit the file "administrator/components/com_hikashop/classes/cart" and replace the function "loadFullCart()" by the following code:

function &loadFullCart($additionalInfos=false,$keepEmptyCart=false,$skipChecks=false){

		$app = JFactory::getApplication();
		$database	= JFactory::getDBO();
		$config =& hikashop_config();
		$currencyClass = hikashop_get('class.currency');
		$productClass = hikashop_get('class.product');
		$main_currency = (int)$config->get('main_currency',1);
		$currency_id = hikashop_getCurrency();

		if(!in_array($currency_id,$currencyClass->publishedCurrencies())){
			//if the selected currency can't be used for checkout use the main currency
			$currency_id = $main_currency;
		}

		$zone_id = hikashop_getZone('shipping');
		if($config->get('tax_zone_type','shipping')=='billing'){
			$tax_zone_id=hikashop_getZone('billing');
		}else{
			$tax_zone_id=$zone_id;
		}
		$discount_before_tax = (int)$config->get('discount_before_tax',0);
		$cart = new stdClass();
		$cart->products = $this->get(@$this->cart->cart_id, $keepEmptyCart);
		$cart->cart_id = (int)@$this->cart->cart_id;
		$cart->cart_type = @$this->cart->cart_type;
		$cart->cart_params = @$this->cart->cart_params;
		$cart->coupon = null;
		$cart->shipping = null;
		$cart->total = null;
		$cart->additional = array();

		if(!empty($cart->products)){
			$ids = array();
			foreach($cart->products as $product){
				$ids[]=$product->product_id;
			}
			JArrayHelper::toInteger($ids);
			$query = 'SELECT * FROM '.hikashop_table('file').' WHERE file_ref_id IN ('.implode(',',$ids).') AND file_type IN( \'product\',\'file\') ORDER BY file_ref_id ASC, file_ordering ASC';
			$database->setQuery($query);
			$images = $database->loadObjectList();
			if(!empty($images)){
				foreach($cart->products as $k => $row){
					$productClass->addFiles($cart->products[$k],$images);
				}
			}

			//add variants inside main products as reference for tax calculus
			foreach($cart->products as $k => $row){
				if($row->product_type=='variant'){
					foreach($cart->products as $k2 => $row2){
						if($row->product_parent_id==$row2->product_id){
							$cart->products[$k2]->variants[]=&$cart->products[$k];
							break;
						}
					}
				}
			}

			//add the characteristics infos
			$query = 'SELECT a.*,b.* FROM '.hikashop_table('variant').' AS a LEFT JOIN '.hikashop_table('characteristic').' AS b ON a.variant_characteristic_id=b.characteristic_id WHERE a.variant_product_id IN ('.implode(',',$ids).') ORDER BY a.ordering,b.characteristic_value';
			$database->setQuery($query);
			$characteristics = $database->loadObjectList();
			if(!empty($characteristics)){
				foreach($cart->products as $key => $product){
					if($product->product_type!='variant'){
						$element =& $cart->products[$key];
						$product_id=$product->product_id;
						$mainCharacteristics = array();
						foreach($characteristics as $characteristic){
							if($product_id==$characteristic->variant_product_id){
								$mainCharacteristics[$product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id]=$characteristic;
							}
							if(!empty($element->options)){
								foreach($element->options as $k => $optionElement){
									if($optionElement->product_id==$characteristic->variant_product_id){
										$mainCharacteristics[$optionElement->product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id]=$characteristic;
									}
								}
							}
						}
						if(!empty($element->variants)){
							$this->addCharacteristics($element,$mainCharacteristics,$characteristics);
						}

						if(!empty($element->options)){
							foreach($element->options as $k => $optionElement){
								if(!empty($optionElement->variants)){
									$this->addCharacteristics($element->options[$k],$mainCharacteristics,$characteristics);
								}
							}
						}
					}
				}
			}

			//calculate prices
			$product_quantities = array();
			foreach($cart->products as $row){
				if(empty($product_quantities[$row->product_id])){
					$product_quantities[$row->product_id] = (int)@$row->cart_product_quantity;
				}else{
					$product_quantities[$row->product_id]+=(int)@$row->cart_product_quantity;
				}
				if(empty($product_quantities[$row->product_parent_id])){
					$product_quantities[$row->product_parent_id] = (int)@$row->cart_product_quantity;
				}else{
					$product_quantities[$row->product_parent_id] += (int)@$row->cart_product_quantity;
				}
			}
			foreach($cart->products as $k => $row){
				$cart->products[$k]->cart_product_total_quantity = $product_quantities[$row->product_id];
				if($row->product_parent_id){
					$cart->products[$k]->cart_product_total_variants_quantity = $product_quantities[$row->product_parent_id];
				}else{
					$cart->products[$k]->cart_product_total_variants_quantity = $cart->products[$k]->cart_product_total_quantity;
				}
			}

			$currencyClass->getPrices($cart->products,$ids,$currency_id,$main_currency,$tax_zone_id,$discount_before_tax);

			if($additionalInfos){
				$queryImage = 'SELECT * FROM '.hikashop_table('file').' WHERE file_ref_id IN ('.implode(',',$ids).') AND file_type=\'product\' ORDER BY file_ref_id ASC, file_ordering ASC, file_id ASC';
				$database->setQuery($queryImage);
				$images = $database->loadObjectList();

				foreach($cart->products as $k=>$row){
					if(!empty($images)){
						foreach($images as $image){
							if($row->product_id==$image->file_ref_id){
								if(!isset($row->file_ref_id)){
									foreach(get_object_vars($image) as $key => $name){
										$cart->products[$k]->$key = $name;
									}
								}
								break;
							}
						}
					}
					if(!isset($cart->products[$k]->file_name)){
						$cart->products[$k]->file_name = $row->product_name;
					}
				}
			}

			foreach($cart->products as $k => $row){
				if(!empty($row->variants)){
					foreach($row->variants as $k2 => $variant){
						$productClass->checkVariant($cart->products[$k]->variants[$k2],$row);
					}
				}
			}

			//check that products are still published etc
			$notUsable = array();
			$cartData = $this->loadCart($cart->cart_id);

			if(!$skipChecks){
				$cart->products = array_reverse($cart->products);
				foreach($cart->products as $k => $product){
					if(empty($product->product_id)){
						continue;
					}
					if(!empty($product->cart_product_quantity)){
						$oldQty = $product->cart_product_quantity;
						if(@$cartData->cart_type != 'wishlist')
							$this->_checkQuantity($product,$product->cart_product_quantity,$cart->products,$product->cart_product_id);
						if($oldQty!=$product->cart_product_quantity){
							$notUsable[$product->cart_product_id]=0;
							break;
						}
						if(!$config->get('display_add_to_cart_for_free_products',0) && empty($product->prices)){
							$notUsable[$product->cart_product_id]=0;
							$app->enqueueMessage(JText::sprintf('PRODUCT_NOT_AVAILABLE',$product->product_name),'notice');
							continue;
						}
						if(empty($product->product_published)){
							$notUsable[$product->cart_product_id]=0;
							$app->enqueueMessage(JText::sprintf('PRODUCT_NOT_AVAILABLE',$product->product_name),'notice');
							continue;
						}
						if($product->product_quantity!=-1 && $product->product_quantity < $product->cart_product_quantity){
							$notUsable[$product->cart_product_id]=0;
							$app->enqueueMessage(JText::sprintf('NOT_ENOUGH_STOCK_FOR_PRODUCT',$product->product_name),'notice');
							continue;
						}

						if($product->product_sale_start>time()){
							$notUsable[$product->cart_product_id]=0;
							$app->enqueueMessage(JText::sprintf('PRODUCT_NOT_YET_ON_SALE',$product->product_name),'notice');
							continue;
						}
						if(!empty($product->product_sale_end) && $product->product_sale_end<time()){
							$notUsable[$product->cart_product_id]=0;
							$app->enqueueMessage(JText::sprintf('PRODUCT_NOT_SOLD_ANYMORE',$product->product_name),'notice');
							continue;
						}
					}
				}
				$cart->products = array_reverse($cart->products);
			}

			if(!empty($notUsable)){
				//if we need to remove products from the cart do so and then reload the cart
				$this->update($notUsable,1,0,'item');
				return $this->loadFullCart($additionalInfos);
			}

			foreach($cart->products as $k => $row){
				//we unset the cart coupon and modified date in order to avoid the auto load hash on the products to be different if only the coupon of the cart changed
				unset($cart->products[$k]->cart_modified);
				unset($cart->products[$k]->cart_coupon);

				$currencyClass->calculateProductPriceForQuantity($cart->products[$k]);
			}

			$currencyClass->calculateTotal($cart->products,$cart->total,$currency_id);
			$cart->full_total=&$cart->total;

			JPluginHelper::importPlugin('hikashop');
			JPluginHelper::importPlugin('hikashoppayment');
			JPluginHelper::importPlugin('hikashopshipping');
			$dispatcher = JDispatcher::getInstance();
			$dispatcher->trigger('onAfterCartProductsLoad', array( &$cart ) );

			if(!empty($cart->additional)) {
				$currencyClass->addAdditionals($cart->additional, $cart->additional_total, $cart->full_total, $currency_id);
				$cart->full_total =& $cart->additional_total;
			}

			if(!empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist'){
				$discount=hikashop_get('class.discount');
				$discountData = $discount->load($this->cart->cart_coupon);
				if(@$discountData->discount_auto_load){
					$current_auto_coupon_key = sha1($zone_id.'_'.serialize($cart->products).'_'.hikashop_loadUser());
					$previous_auto_coupon_key = $app->getUserState( HIKASHOP_COMPONENT.'.auto_coupon_key');

					if($current_auto_coupon_key!=$previous_auto_coupon_key){
						$this->cart->cart_coupon='';
					}
				}
			}

			if(hikashop_level(1) && empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist'){
				$filters = array('discount_type=\'coupon\'','discount_published=1','discount_auto_load=1');
				hikashop_addACLFilters($filters,'discount_access');
				$query = 'SELECT * FROM '.hikashop_table('discount').' WHERE '.implode(' AND ',$filters).' ORDER BY discount_minimum_order DESC, discount_minimum_products DESC';
				$this->database->setQuery($query);
				$coupons = $this->database->loadObjectList();
				if(!empty($coupons)){
					$discount = hikashop_get('class.discount');
					$zoneClass = hikashop_get('class.zone');
					$zones = $zoneClass->getZoneParents($zone_id);
					foreach($coupons as $coupon){
						$result = $discount->check($coupon,$cart->total,$zones,$cart->products,false);
						if($result){
							//if we found a coupon to auto load add the coupon to the cart and reload the cart
							$auto_coupon_key = sha1($zone_id.'_'.serialize($cart->products).'_'.hikashop_loadUser());
							$app->setUserState( HIKASHOP_COMPONENT.'.auto_coupon_key',$auto_coupon_key);
							$app->setUserState( HIKASHOP_COMPONENT.'.coupon_code','');
							$this->update($coupon->discount_code,1,0,'coupon',true);
							if(empty($this->cart))
								$this->cart= new stdClass();
							$this->cart->cart_coupon = $coupon->discount_code;
							static $done = false;
							if($done == false){
								$done = true;
								return $this->loadFullCart($additionalInfos);
							}
						}
					}
				}
			}

			if(!empty($this->cart->cart_coupon) && $cart->cart_type != 'wishlist') {
				$zoneClass = hikashop_get('class.zone');
				$zones = $zoneClass->getZoneParents($zone_id);
				$cart->coupon = $discount->loadAndCheck($this->cart->cart_coupon, $cart->full_total, $zones, $cart->products, true);
				if(empty($cart->coupon)) {
					if(!empty($this->cart))
						$this->cart->cart_coupon = '';
				} else {
					$cart->full_total = &$cart->coupon->total;
				}
			}

			if(bccomp($cart->full_total->prices[0]->price_value_with_tax, 0, 5) <= 0) {
				$cart->full_total->prices[0]->price_value_with_tax = 0;
				$cart->full_total->prices[0]->price_value = 0;
				if(isset($cart->full_total->prices[0]->taxes))
					unset($cart->full_total->prices[0]->taxes);
			}

			$shipping_id = $app->getUserState(HIKASHOP_COMPONENT.'.shipping_id');
			if(!empty($shipping_id)) {
				$cart->shipping = $app->getUserState(HIKASHOP_COMPONENT.'.shipping_data');
				if(!empty($cart->shipping)) {
					if(!is_array($cart->shipping)){
						$cart->shipping = array($cart->shipping);
					}else{
						//make sure that there are no shipping methods entered twice in the selected shipping data.
						$shippings = array();
						foreach($cart->shipping as $method){
							$group_key = $method->shipping_id;
							if(!empty($method->shipping_warehouse_id)){
								$group_key .= '_';
								if(is_array($method->shipping_warehouse_id)){
									foreach($method->shipping_warehouse_id as $key => $val){
										$group_key .= $key.$val;
									}
								}else{
									$group_key .= $method->shipping_warehouse_id;
								}
							}
							$shippings[$group_key]=$method;
						}
						$cart->shipping = array_values($shippings);
					}
					$currencyClass = hikashop_get('class.currency');
					$shipping =& $cart->shipping;
					$currencyClass->processShippings($shipping,$cart);
					//calculate total price with shipping
					$cart->full_total =& $currencyClass->addShipping($cart->shipping, $cart->full_total);
				}
			}

			$before_additional = !empty($cart->additional);

			$dispatcher->trigger('onAfterCartShippingLoad', array( &$cart ) );

			if(!$before_additional && !empty($cart->additional)) {
				$currencyClass->addAdditionals($cart->additional, $cart->additional_total, $cart->full_total, $currency_id);
				$cart->full_total =& $cart->additional_total;
			}

			if(bccomp($cart->full_total->prices[0]->price_value_with_tax,0,5)<=0){
				$cart->full_total->prices[0]->price_value_with_tax = 0;
				$cart->full_total->prices[0]->price_value = 0;
				if(isset($cart->full_total->prices[0]->taxes)) unset($cart->full_total->prices[0]->taxes);
			}

			$payment_id = $app->getUserState( HIKASHOP_COMPONENT.'.payment_id');
			if(!empty($payment_id)){
				$cart->payment = $app->getUserState( HIKASHOP_COMPONENT.'.payment_data');
				if(!empty($cart->payment)){
					$currencyClass = hikashop_get('class.currency');
					$payment =& $cart->payment;
					$payments = array(&$payment);
					$currencyClass->processPayments($payments);
					//calculate total price with payment
					$currencyClass->addPayment($cart->payment,$cart->full_total);
					$cart->full_total=&$cart->payment->total;
				}
			}
		}

		if($additionalInfos){
			$app = JFactory::getApplication();
			$shipping_address=$app->getUserState( HIKASHOP_COMPONENT.'.shipping_address',0);
			if(!empty($shipping_address)){
				$this->loadAddress($cart,$shipping_address);
			}
			$billing_address=$app->getUserState( HIKASHOP_COMPONENT.'.billing_address',0);
			if($billing_address==$shipping_address){
				$cart->billing_address =& $cart->shipping_address;
			}else{
				if(!empty($billing_address)){
					$this->loadAddress($cart,$billing_address,'parent','billing');
				}
			}
			$this->calculateWeightAndVolume($cart);
		}

		return $cart;
	}

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

  • Posts: 122
  • Thank you received: 0
11 years 4 days ago #158461

Hi Xavier,

Thanks very much for this.

However, I cannot find the string loadFullCart() to replace it in cart.php.

Please advise.

Regards,

Mike

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

  • Posts: 83932
  • Thank you received: 13588
  • MODERATOR
11 years 1 day ago #158898

Please do that modification and it should fix the problem:
www.hikashop.com/forum/product-category-...orrectly.html#158811

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

  • Posts: 122
  • Thank you received: 0
11 years 1 day ago #158977

Hello Nicolas,

I installed the fix but the discounts re still not working properly at starsupplyalliance.com/ (see attached screenshot for coupon levels.

For example,

- there is no discount applied for sales between $300 and $600
- an incorrect discount of 10% is applied between sales of $600- $1000

Mohamed Thelji has staed in this thread that
'I think that you should also set a "Maximum order value" for your coupons like 599.99 for your 5% coupon. ' which is still not possible after the patch.

Please advise on how to make these calculations work.

Regards,

Mike

Attachments:

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

  • Posts: 122
  • Thank you received: 0
10 years 11 months ago #159704

Hi guys,

Is there any movement on this issue?

Thanks,

Mike

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

  • Posts: 83932
  • Thank you received: 13588
  • MODERATOR
10 years 11 months ago #159759

Hi,

Sorry for the delay.
We've add to apply multiple patches to fix that.
Replace the files discount.php and cart.php in the folder administrator/components/com_hikashop/classes with the ones in this archive and that should solve definitely the issue:

File Attachment:

File Name: h464f6a1.zip
File Size:19 KB

Attachments:

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

  • Posts: 122
  • Thank you received: 0
10 years 11 months ago #159833

Hi Nicolas,

Thanks for this - it is looking much better.

The only problem we have now is that the doscount is being applied to the post tax price rather than the pre-tax which is what we need - how do we use the pre-tax value?

Regards,

Mike

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

  • Posts: 83932
  • Thank you received: 13588
  • MODERATOR
10 years 11 months ago #159881

You have the option "Apply discounts" of the configuration if you want to change that.

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

  • Posts: 122
  • Thank you received: 0
10 years 11 months ago #159992

Hi Nicolas,

Your responses are normally very clear but I don't understand this one.

I want to change the calculation so that the discount is applied to the pre-tax amount.

Where in the configuration do I set this up?

Thanks,

Mike

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

  • Posts: 83932
  • Thank you received: 13588
  • MODERATOR
10 years 11 months ago #159997

Hi,

I don't see where my answer was not clear ?
Toggle the "Apply discounts" option of the configuration and that will do it:
take.ms/bwuZU

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

  • Posts: 122
  • Thank you received: 0
10 years 11 months ago #160126

Hi Nicolas,

I was looking everywhere bar the obvious place!

As you can see from the first attachment, the tax/discount is set up as you recommended but as you can see from screenshot 2 the discount is being applied on the post tax amount.

Regards,

Mike

Attachments:

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

Time to create page: 0.132 seconds
Powered by Kunena Forum