Add custom field per_unit to category view

  • Posts: 3
  • Thank you received: 0
12 years 9 months ago #70167

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.

  • Posts: 84102
  • Thank you received: 13637
  • MODERATOR
12 years 9 months ago #70177

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.

  • Posts: 3
  • Thank you received: 0
12 years 9 months ago #70184

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.

Attachments:

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

  • Posts: 84102
  • Thank you received: 13637
  • MODERATOR
12 years 9 months ago #70257

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.

  • Posts: 306
  • Thank you received: 42
  • Hikamarket Multivendor Hikashop Business
12 years 9 months ago #70284

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:



product/listing_price.php:
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:
PER_UNIT=" each"
PER_DOZ=" doz"

Last edit: 12 years 9 months ago by trevsmiff.

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

  • Posts: 306
  • Thank you received: 42
  • Hikamarket Multivendor Hikashop Business
12 years 9 months ago #70313

After a bit of hacking I can get it to work if I edit listing_price.php as follows:

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.

  • Posts: 306
  • Thank you received: 42
  • Hikamarket Multivendor Hikashop Business
12 years 9 months ago #70361

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.

  • Posts: 84102
  • Thank you received: 13637
  • MODERATOR
12 years 9 months ago #70363

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.

  • Posts: 306
  • Thank you received: 42
  • Hikamarket Multivendor Hikashop Business
12 years 9 months ago #70365

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.

  • Posts: 3
  • Thank you received: 0
12 years 9 months ago #70406

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 ?

Attachments:
Last edit: 12 years 9 months ago by dillweed.

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

  • Posts: 306
  • Thank you received: 42
  • Hikamarket Multivendor Hikashop Business
12 years 9 months ago #70408

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.112 seconds
Powered by Kunena Forum