Show Qty box based on Product and/or Category

  • Posts: 73
  • Thank you received: 2
11 years 10 months ago #117739

-- Example of product display :
(Don't want--currently not-show qty box)
(Need to show qty box)
-- HikaShop version -- : 2.2.0
-- Joomla version -- : 2.5.14
-- PHP version -- : 5.4
-- Browser(s) name and version -- : ff 22.0

Are there any plans to be able to have the qty box appear based on product category versus a global setting now? Unless I'm not seeing this option settings correctly, this would really be nice to do as well as see options on the product lisitng page. I use custom fields for now. Right now sadly, I've had to use another shop cart ( ) to show qty where I need it.

Any suggestions will be appreciated.

Thanks

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

  • Posts: 13201
  • Thank you received: 2322
11 years 10 months ago #117783

Hi,

To change the comportment of the quantity input in the listings, you can edit the view "product / add_to_cart_listing", it's possible to add a check on the category to display it the way you want.

If you want to change the display of the input on the product page the view to edit is "product / quantity".

But there is no options for that in the listing menu/modules.

Last edit: 11 years 10 months ago by Xavier.

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

  • Posts: 73
  • Thank you received: 2
11 years 10 months ago #117831

Sorry for some reason the example url did not show up:
-- Example of product display :
http://www.fchsptsa.org/how-you-can-help/jag-fund-honor-roll.html
http://www.fchsptsa.org/how-you-can-help/fall-plant-sale.html (Need to show qty box)

So these pages are category moduules product listing. The first link I need to show qty box but no qty box on the 2nd link (as it appears now).

I'm not sure if I understand your suggestion of editing the view "product / add_to_cart_listing" since I'm not too keen on PHP coding. There was no suggestion provided on how to edit this view. Your assistance would be appreciated.

Thanks

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

  • Posts: 12953
  • Thank you received: 1778
11 years 10 months ago #117863

Hi,

If you want to add a quantity box through your product listing I think that you'll probably find your answer there :

You can edit the file listing_img_title of the view product via the menu Display->Views and add the code:
$this->params->set('show_quantity_field', 1);
at the beginning after the first <?php tag.


Hope this will help you.

Last edit: 11 years 10 months ago by Mohamed Thelji.

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

  • Posts: 73
  • Thank you received: 2
11 years 10 months ago #117921

Ok I got the qty box to appear on my product list page; however, how I can have it appear under just a particular category. See the links again. I don't want the qty box to appear on this product list page
http://www.fchsptsa.org/online-shopping-categories/category/18-family-sponsors.html
And it plugs in the set amount rather than 1 on this page. Can you make the qty box show zero initially?

then, if you look at this page
http://www.fchsptsa.org/online-shopping-categories.html
the new line of code appears. :(



Thanks

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

  • Posts: 73
  • Thank you received: 2
11 years 10 months ago #117922

Sorry, here's the screen shot, This is a working site and need to revert back to the way I had it showing no qty on product listing page.

This page I don't want QTY box to appear; however on first attachment but need QTY box on the 2nd attachment image (flowers)

thanks

Attachments:
Last edit: 11 years 10 months ago by aheng5. Reason: add'l explanation

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

  • Posts: 13201
  • Thank you received: 2322
11 years 10 months ago #117990

Hi,

You can try to use this kind of code in the view "product / quantity":

						if(in_array($this->row->product_category,array('x','y','z'))){
							$this->params->set('show_quantity_field','1');
						}else{
							$this->params->set('show_quantity_field','0');
						}
This code allow you to display the quantity field depending on the product category.
You have to replace 'x', 'y', 'z' by category ids.

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

  • Posts: 73
  • Thank you received: 2
11 years 10 months ago #118068

Sorry no luck; no effect

Here's my placement of code (partial view of Product/Quantity:

}else{
$end_date = $this->element->main->product_sale_end;
}
if(in_array($this->row->product_category,array('28'))){
$this->params->set('show_quantity_field','1');
}else{
$this->params->set('show_quantity_field','0');
}

if($end_date && $end_date<time()){
?>
<span class="hikashop_product_sale_end">
<?php echo JText::_('ITEM_NOT_SOLD_ANYMORE'); ?>
</span>

I also tried with and without this prior code suggestion in the "listing_img_title"
$this->params->set('show_quantity_field', 1);

No luck :(

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

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
11 years 10 months ago #118124

The code provided by Xavier should be placed right after the first <?php tag of the quantity file. Also, please make sure that you edit the file for the correct frontend template and not another template or you won't see any change.

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

  • Posts: 73
  • Thank you received: 2
11 years 10 months ago #118135

Have tried your latest suggestion; yes I have the right template and have under Main-Product-quantity option set to Ajax input. I use view "listing_img_desc". Not sure if this makes any difference. The only change I made on this view place the description on the left.

product/quantity view

<?php
/**
 * @package  HikaShop for Joomla!
 * @version  2.2.0
 * @author  hikashop.com
 * @copyright  (C) 2010-2013 HIKARI SOFTWARE. All rights reserved.
 * @license  GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
//-------------------------
if(in_array($this->row->product_category,array('28'))){
 $this->params->set('show_quantity_field','1');
 }else{
 $this->params->set('show_quantity_field','0');
 }
//-------------------------
      if(!isset($this->cart)) $this->cart = hikashop_get('helper.cart');
      if(!empty($this->row->has_options)){
        echo $this->cart->displayButton(JText::_('CHOOSE_OPTIONS'),'choose_options',$this->params,hikashop_completeLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$this->itemid.$this->category_pathway),'window.location = \''.str_replace("'","\'",hikashop_completeLink('product&task=show&product_id='.$this->row->product_id.'&name='.$this->row->alias.$this->itemid.$this->category_pathway)).'\';return false;','');
No luck :(

Last edit: 11 years 10 months ago by Jerome.

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

  • Posts: 26253
  • Thank you received: 4040
  • MODERATOR
11 years 10 months ago #118309

Hi,

Your code looks globally good. You can use only number and not string, it will unsure you that the check are valid.

if(in_array( (int)$this->row->product_category, array(28)) ) {
After that, if it don't work, you can add some "debug traces" in order to check where the code go.
Putting some
echo '#1';
(#2, #3...) in order to see if you're editing the right view, if the code enter in the if or in the else, etc.
You can also make some "var_dump" in order to see the content of a variable, it is always useful for checks.

Regards,


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: 73
  • Thank you received: 2
11 years 10 months ago #118358

No luck; I'm unsure about the echo and debug notation and how to implement it. So I'll just need to wait until hopefully this coding will become part of the standard programming. thanks

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

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
11 years 10 months ago #118400

Jerome is proposing to do like that:

if(in_array($this->element->category_id,array('28'))){
echo '#1';
 $this->params->set('show_quantity_field','1');
 }else{
echo '#2';
 $this->params->set('show_quantity_field','0');
 }
That way, if you see a #1 or a #2 on the page, you will know that you're editing the correct file for the correct template. And you will see if it set the show_quantity_field at the correct value for the correct category.

Note that I changed :
$this->row->product_category
to:
$this->element->category_id
in my code example as $this->row->product_category is not always available on products listings (it depends on how you configure the module/menu.

The following user(s) said Thank You: aheng5

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

  • Posts: 73
  • Thank you received: 2
11 years 10 months ago #118414

:woohoo: SUCCESS! Exactly what I was looking for. Thank you!

Attached are my screen shots of my final code as I removed the echo codes.

Attachments:

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

  • Posts: 73
  • Thank you received: 2
11 years 10 months ago #118438

Ok, one more challenge.

I've added via Product insert tag product from 3 different categories. I want to only show qty box on the "Donate ANGP Ticket" but not on the other two products. Refer to screen shots to see the product page and the code used in the article.

http://ptsa.westfieldhs.org/parents/angp-homepage/order-angp-tickets.html

I tried including the last code into the the product/quantity view but no effect.

Is this possible?

Attachments:
Last edit: 11 years 10 months ago by aheng5. Reason: add'l comments

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

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
11 years 10 months ago #118461

There is the parameter quantityfield that you can add to the tag to display or not the quantity field.

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

  • Posts: 73
  • Thank you received: 2
11 years 10 months ago #118471

My last screenshot does show the quanityfield tag as part of the product tag insert. I also have under the main config page for product to show the quantity box. Any other suggestion? thanks

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

  • Posts: 73
  • Thank you received: 2
11 years 10 months ago #118472

I've decided to revert to module insert rather than product tag insert and all is good for now. :)

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

Time to create page: 0.106 seconds
Powered by Kunena Forum