Skip to main content

Add custom field per_unit to category view

14 years 3 weeks ago #70167 by dillweed
Hello,

I am trying to get a custom field of "per_unit" or "per_case" into the category view next to the price. I have the correct "per_unit" in the product view, but for the life of me I can't figure out how to get into the category view. So I was wondering if this is possible.

Thank you for the help!

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

14 years 3 weeks ago #70177 by nicolas
Hi,

If you do it as explained in the section "I sell packed products, how can I change "each" text in the product page ?" of the FAQ it will work on both :
www.hikashop.com/en/support/documentation/106-faq.html

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

14 years 3 weeks ago #70184 by dillweed
nicolas,

thanks for the reply. I have already seen the FAQ's and changed the necessary information on the site, but for some reason the "per_unit" does not show up in the category view. I've attached two images to explain what I mean.

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

14 years 2 weeks ago #70257 by nicolas
Can you also do a screenshot of the code modification you made and of your custom product field ?

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

14 years 2 weeks ago - 14 years 2 weeks ago #70284 by trevsmiff
I am also trying to display the units in the Category view. The units are displayed properly in the Product view.

The settings for the custom product field looks like this:
image missing http://www.imperialarrows.co.uk/salesunit.jpg

product/listing_price.php:
Code:
if(isset($price->price_min_quantity) && empty($this->cart_product_price) && $this->params->get('per_unit',1)){ if($price->price_min_quantity>1){ echo JText::sprintf('PER_UNIT_AT_LEAST_X_BOUGHT',$price->price_min_quantity); }else{ //echo JText::_('PER_UNIT'); echo JText::_($this->element->salesunit); } }

en_GB.com_hikashop.ini:
Code:
PER_UNIT=" each" PER_DOZ=" doz"
Last edit: 14 years 2 weeks ago by trevsmiff.

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

14 years 2 weeks ago #70313 by trevsmiff
After a bit of hacking I can get it to work if I edit listing_price.php as follows:
Code:
if($price->price_min_quantity>1){ echo JText::sprintf('PER_UNIT_AT_LEAST_X_BOUGHT',$price->price_min_quantity); }else{ //echo JText::_('PER_UNIT'); echo JText::_($this->row->salesunit); }

Is this safe?

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

14 years 2 weeks ago #70361 by trevsmiff
Well the hack works until you select a different characteristic then the unit disappears :(

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

14 years 2 weeks ago #70363 by nicolas
The problem is that you have products with characteristics.
In that case, the code will have to be a bit more complex:

if(isset($this->element->main)) echo JText::_($this->element->main->salesunit);
else echo JText::_($this->element->salesunit);

That way it will work on both pages.
The following user(s) said Thank You: trevsmiff, dillweed

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

14 years 2 weeks ago #70365 by trevsmiff
Thanks Nicolas

It didn't quite work as the units were not displayed on the ctegories page by I changed the code as follows and it did work:

if(isset($this->element->main)) echo JText::_($this->element->main->salesunit);
else echo JText::_($this->row->salesunit);

Trevor

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

14 years 2 weeks ago - 14 years 2 weeks ago #70406 by dillweed
Here are the screen shots that you requested.

Thank you for the help!

nicolas wrote: Can you also do a screenshot of the code modification you made and of your custom product field ?

Last edit: 14 years 2 weeks ago by dillweed.

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

14 years 2 weeks ago #70408 by trevsmiff
dillweed

I had the same problem but have now managed to get it working. Nicolas has now updated the FAQ . . .

In the menu Display -> Views, edit the product / listing_price.php file.
In this file, replace:

echo JText::_('PER_UNIT');

By:

if(isset($this->element->main)) echo JText::_($this->element->main->salemethod);

elseif(isset($this->row)) echo JText::_($this->row->salemethod);

else echo JText::_($this->element->salemethod);
The following user(s) said Thank You: nicolas, dillweed

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

Time to create page: 0.148 seconds
Powered by Kunena Forum