How Do I override product price with custom field?

  • Posts: 2
  • Thank you received: 0
8 years 3 months ago #264349

I want to display user's country based price. I know Hikashop does price based on country ip but it uses the exchange rate to calculate the price in a different currency. What we are wanting is storing a completely different price for some countries which is not directly related to the main Australian price. Products sold in New Zealand have to be priced to account for the cost of logistics in that country, import duties, office overheads etc. A product sold for AUD$100 in Australia may need to be sold for AUD$115 equivalent in New Zealand because of additional costs.

So What I did is, I created a custom field for New Zealand price. I've created plugin which extends JPlugin and I am using onHikashopBeforeDisplayView action to replace the "\components\com_hikashop\views\product\tmpl\listing_price.php" view. But Result prints output from both my plugin view file and hikashop's default view file. so How do I configure it to display output from only my plugin file on product listing, product detail, cart and order page?

Attachments:
Last edit: 8 years 3 months ago by karmicdice.

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

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
8 years 3 months ago #264353

Hi,

In each product, you can set several prices and for each price, select the currency of the price.
If the system finds the price for the current currency, then it will use it, otherwise, it will convert it.
So you don't need a custom field, or a view override, or a plugin.
Just set the prices in the products accordingly and that should do it.
If you want to override a view through a plugin, you can use the ouput buffering of PHP ( ob_start in onHikashopBeforeDisplayView and ob_get_clean in onHikashopAfterDisplayView ), but it shouldn't be necessary for what you want to do.

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

  • Posts: 2
  • Thank you received: 0
8 years 3 months ago #264423

Hello Nicolas,

Thank you for response. But it seems you couldn't quite understand what I want to achieve here. I don't want to show price in different currencies. Price will always be in AUD. "What we are wanting is storing a completely different price for some countries which is not directly related to the main Australian price. Products sold in New Zealand have to be priced to account for the cost of logistics in that country, import duties, office overheads etc. A product sold for AUD$100 in Australia may need to be sold for AUD$115 equivalent in New Zealand because of additional costs". Basically A watch being sold at AUD$100. But when someone from New Zeland purchase it, All the cost of logistics, mport duties, office overheads etc will be included and price might increase to AUD$115. So When someone from New Zeland takes a look at that product, I want to show the price including All the cost of logistics, mport duties, office overheads, but in AUD and not NZD.


Also I tried ob_start in onHikashopBeforeDisplayView and ob_get_clean in onHikashopAfterDisplayView , but my code seems to append with original template and not replace/override it. How do I replace/override the original template and load my template instead specially in category/product listing page?

Last edit: 8 years 3 months ago by karmicdice.

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

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
8 years 3 months ago #264433

Hi,

1. In that case, there is indeed no option. You can't have prices based on the address of the customer.
And in that case, customization will be necessary.

2. Something like that :

function onHikashopBeforeDisplayView(&$view){
 ob_start();
}
function onHikashopAfterDisplayView(&$view){
 ob_get_clean();
echo 'my alternative HTML';
}

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

Time to create page: 0.088 seconds
Powered by Kunena Forum