How to display "Only X more to get free shipping"?

  • Posts: 344
  • Thank you received: 3
8 years 4 months ago #244573

Joomla 3.5.1
Hikashop 2.6.3

So right now I am using this code in the checkout / cart.php file

if($this->full_total->prices[0]->price_value_without_shipping < 900){
	$diffQty = 900 - $this->full_total->prices[0]->price_value_without_shipping;
	$app = JFactory::getApplication();
	$app->enqueueMessage(JText::sprintf('MISSING_QTY_FOR_FREE_SHIPPING',$diffQty));
}

But now I have just started adding tax to my products, and now the above code is displaying the message with prices based on the price without tax.

I need the message to be displayed based on the price with tax( price_value_with_tax;). So somewhere in the code above I need to place this: "price_value_with_tax;"

Any advice on how I can get it right ?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 4 months ago #244581

Hi,

Instead of price_value_without_shipping, you want to use price_value_without_shipping_with_tax

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

  • Posts: 344
  • Thank you received: 3
8 years 3 months ago #247571

I now have this function on the top of my checkout, and it works very well.
More customers are buying more to get free shipping after I implementet it.

Is it possible to have this function do display in my shopping cart module ?

See attached image to see what I mean:



Tnx

Attachments:

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 3 months ago #247575

Hi,

You can use almost the same code.
Instead of $this->full_total you need to use $this->total
The rest should be the same.

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

  • Posts: 344
  • Thank you received: 3
8 years 3 months ago #247768

Tnx

In which php. file to I need to place the code ?

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
8 years 3 months ago #247770

Hi,

No in a PHP file, in a view.
Do not edit HikaShop PHP files !

They are two views for the carts "checkout / cart" and "product / cart".


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 344
  • Thank you received: 3
8 years 3 months ago #247944

No, I want to display this message inside the hikashop cart module.

Any advice?

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
8 years 3 months ago #247945

They are two views for the carts "checkout / cart" and "product / cart"


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 344
  • Thank you received: 3
8 years 3 months ago #248121

Joomla 3.6.2
Hikashop 2.6.3

This is the code I am using in the checkout / cart.php file:

if($this->full_total->prices[0]->price_value_without_shipping_with_tax < 900){
	$diffQty = 900 - $this->full_total->prices[0]->price_value_without_shipping;
	$app = JFactory::getApplication();
	$app->enqueueMessage(JText::sprintf('MISSING_QTY_FOR_FREE_SHIPPING',$diffQty));
}

I've discovered something strange with the code.

I have free freight when a customers buys for more than NOK 900,-

When the price of the products in the checkout is below NOK 1 125 the message in the checkout says.

"Message
If you shop for NOK -224 more you get free shipping!"

I have noticed that there is a minus in front of the value.

NOTE: The NOK minus price varies. I.e if the total price is NOK 967, the message says: If you shop for NOK -67,- more you get free shipping!"

If the price of the products is NOK 1125 av above the message don't display and working just fine.

I know that this has some to do with the tax. Because the tax rate in Norway is 25%, ....and NOK 900 x 1,25 = 1125

Any advice on how to fix this ?

Last edit: 8 years 3 months ago by river.

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

  • Posts: 200
  • Thank you received: 75
8 years 3 months ago #248123

Hi,

I was just browsing through this post, you may have the prices with and without tax mixed up.

In the first line you check the price_value_without_shipping_with_tax against 900, but then in the second line you still use the price_value_without_shipping (so not with tax) to subtract from 900.

Make sure you use the same price value everywhere, it should work correctly.

Regards,

The following user(s) said Thank You: Jerome

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

  • Posts: 344
  • Thank you received: 3
8 years 3 months ago #248142

Hi !
Tnx man ..... I didn't notice. so now I used the code:

<?php
if($this->full_total->prices[0]->price_value_without_shipping_with_tax < 900){
	$diffQty = 900 - $this->full_total->prices[0]->price_value_without_shipping_with_tax;
	$app = JFactory::getApplication();
	$app->enqueueMessage(JText::sprintf('MISSING_QTY_FOR_FREE_SHIPPING',$diffQty));
}

And now it works ! =)

Last edit: 8 years 3 months ago by river.

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

  • Posts: 344
  • Thank you received: 3
8 years 1 month ago #251173

Joomla 3.6.2
Hikashop 2.6.4

Until now I only have displayed this message in the checkout.

So now I want it also to display above each product.
So I placed this code in the view/product / show_default file:

<?php
if($this->full_total->prices[0]->price_value_without_shipping_with_tax < 900){
	$diffQty = 900 - $this->full_total->prices[0]->price_value_without_shipping_with_tax;
	$app = JFactory::getApplication();
	$app->enqueueMessage(JText::sprintf('MISSING_QTY_FOR_FREE_SHIPPING',$diffQty));
}

It display fine, but that's all.

Now the message is just static and says (even if a customer ads products to the basket):

"Message
If you buy for NOK 900, - you get free shipping!"


I need the message to display (before the customers ads products to the basket)

"If you buy for NOK 900, - or more you get free shipping!"

And after the customer ads product to the basket (i.e value of products is NOK 399,-) I need it to say:

"If you buy for NOK 501,- more you get free shipping!"

And after the customers ads products to the value of NOK 900 or above the message disappears.

Any advice on how to adjust the code to work like this ?

Last edit: 8 years 1 month ago by river.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 1 month ago #251179

Hi,

$this->full_total is not defined on that view file.
You need to add that code before:

$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
$this->full_total =& $cart->full_total;
and then your code will work.

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

  • Posts: 344
  • Thank you received: 3
8 years 1 month ago #251214

Tnx for reply

So i added this code

<?php
$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
$this->full_total =& $cart->full_total;
if($this->full_total->prices[0]->price_value_without_shipping_with_tax < 900){
	$diffQty = 900 - $this->full_total->prices[0]->price_value_without_shipping_with_tax;
	$app = JFactory::getApplication();
	$app->enqueueMessage(JText::sprintf('MISSING_QTY_FOR_FREE_SHIPPING',$diffQty));
}
It works fine.

But there's a small problem.

It only works after I add a product to the basket and proceed to checkout, and after that go back to a product.

Then it displays correct.

Any advice on how to make it display correctly after I just adding a product to the basket ? (without going to the checkout, and back to a product page)

Hope my explenation makes sense =)

Last edit: 8 years 1 month ago by river.

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

  • Posts: 200
  • Thank you received: 75
8 years 1 month ago #251221

Hi,

if I understand correctly you mean the cart is automatically updated through Ajax when someone adds a product, while the message is not updated since it is static content only generated on pageload.

One possible solution would be to simply disable Ajax in your Hikashop configuration. That way the page will always refresh when the "Add to cart" button is clicked and the message will also be updated.

It would probably be possible to do what you want without page refresh by creating a plugin using something like the trigger "onAfterCartUpdate", though it would also be possible by just adding some Javascript that gets executed when the "Add to cart" button is pressed, which is what we use. It's perhaps not the most elegant solution, but this way would also allow you update the message to always display correctly.

Let me know if you're interested in the Javascript solution.

Kind regards,

The following user(s) said Thank You: nicolas

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

  • Posts: 344
  • Thank you received: 3
8 years 1 month ago #251278

The Javascript solutions sound like a good idea. What kind of code should I use ?

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

  • Posts: 200
  • Thank you received: 75
8 years 1 month ago #251304

Hi,

below is the Javascript code we used, I'll give some explanation further down. You can add the code for example all the way at the end of your show_default view:

<script>
jQuery(function(){
  jQuery('.hikashop_cart_input_button').click(function(){
    setTimeout(function(){
      var qtyForFreeShipping = jQuery('td.hikashop_cart_module_product_total_value span.hikashop_product_price').text().replace(/,/g,".");
      var diffQty = 900 - parseFloat(qtyForFreeShipping.substr(qtyForFreeShipping.indexOf(" ")));
      if(diffQty < 0){
        jQuery('#system-message > div').hide();
      }
      else{
        jQuery('#qtyForFreeShipping').text(diffQty);
      }
    },800);
  });                                                            
});
</script>

It looks more complicated than it is.
First we register the click event when someone clicks on the "Add to cart button":
jQuery('.hikashop_cart_input_button').click(function(){
Because the Ajax call always takes a little while to complete, we had to add a timeout to wait for about 800ms to be sure we always get the correct updated total price:
setTimeout(function(){ ... },800);
Then we need to grab the total price from the page. Since we have a Hikashop Cart Module on all our pages we can easily get the current total price from there and calculate the diffQty:
var qtyForFreeShipping = jQuery('td.hikashop_cart_module_product_total_value span.hikashop_product_price').text().replace(/,/g,".");
var diffQty = 900 - parseFloat(qtyForFreeShipping.substr(qtyForFreeShipping.indexOf(" ")));
If your prices have decimal values, the comma needs to be replaced by a dot and we need to get rid of the currency symbol in front with a substr before we can use parseFloat to change the string to a number.

Then we have a simple if-else to hide the system message if the total cart value is above 900, or otherwise modify the value in the message. To grab the price in your message with jQuery, the easiest way is to put a span with a unique class or id around the price value in your MISSING_QTY_FOR_FREE_SHIPPING constant, so change it to something like:
MISSING_QTY_FOR_FREE_SHIPPING = If you buy for NOK <span id="qtyForFreeShipping">%s</span> or more you get free shipping!
Then we can simply update the value with jQuery by grabbing the id "qtyForFreeShipping":
jQuery('#qtyForFreeShipping').text(diffQty);

And that's it, for us this works fine.

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

  • Posts: 344
  • Thank you received: 3
8 years 1 month ago #251503

Tnx man

I will try it out.

I'll give you a feedback when I've tested it.

Regards =)

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

  • Posts: 344
  • Thank you received: 3
8 years 1 month ago #251613

river wrote: Tnx for reply

So i added this code

<?php
$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
$this->full_total =& $cart->full_total;
if($this->full_total->prices[0]->price_value_without_shipping_with_tax < 900){
	$diffQty = 900 - $this->full_total->prices[0]->price_value_without_shipping_with_tax;
	$app = JFactory::getApplication();
	$app->enqueueMessage(JText::sprintf('MISSING_QTY_FOR_FREE_SHIPPING',$diffQty));
}
It works fine.

But there's a small problem.

It only works after I add a product to the basket and proceed to checkout, and after that go back to a product.

Then it displays correct.

Any advice on how to make it display correctly after I just adding a product to the basket ? (without going to the checkout, and back to a product page)

Hope my explenation makes sense =)


Unfortunately the Javascript soulution dosent work :(
.
Any advice from you Hikashop guys on how to solve this without Javascript ?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 1 month ago #251642

Hi,

The javascript solution looks good to me.
If it doesn't work, it might be because of the way HikaShop is configured in your way which isn't compatible with that.
Or maybe you didn't add it properly to the page.
But I still see a javascript solution as the way to go, even though it might require some adaptation for your case.

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

Time to create page: 0.119 seconds
Powered by Kunena Forum