Out of stock badge not displayed on Variants

  • Posts: 306
  • Thank you received: 42
  • Hikamarket Multivendor Hikashop Business
9 years 1 month ago #246992

-- HikaShop version -- : 2.6.3
-- Joomla version -- : 3.6.1
-- PHP version -- : 5.6.0

Hi

We have an Out of Stock badge set up and it works OK on products without variants but if a product variant has zero stock the badge is not displayed when the variant is selected.

The variant selection is by drop-down if it helps.

Best regards
Trevor

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

  • Posts: 84313
  • Thank you received: 13702
  • MODERATOR
9 years 1 month ago #247008

Hi,

The badge cannot refresh when you change the variant as the badges are loaded only for the whole product, not per variant for now.

That will require some modifications to support that.
Let's try that.

Change the code:

$qty = 0;
		if(isset($row->main)){
			if(@$row->main->discount) $discount =& $row->main->discount;
			elseif(@$row->discount) $discount =& $row->discount;
			$product_id = $row->main->product_id;
			$qty = $row->main->product_quantity;
		}else{
			if(@$row->discount) $discount =& $row->discount;
			$product_id = $row->product_id;
			$qty = $row->product_quantity;
		}
		$badge_filters=array(
			'a.badge_start <= '.time(),
			'( a.badge_end >= '.time().' OR a.badge_end =0 )',
			'a.badge_published=1',
			'(a.badge_quantity=\'\' OR a.badge_quantity='.(int)$qty.')',
		);
		if($discount && isset($discount->discount_id)){
			$badge_filters[]='(badge_discount_id='.(int)@$discount->discount_id.' OR badge_discount_id LIKE \'%,'.(int)@$discount->discount_id.',%\' OR badge_discount_id=\'0\' OR badge_discount_id=\'\' )';
		}else{
			$badge_filters[]='(badge_discount_id=\'0\' OR badge_discount_id=\'\')';
		}

		$categories = array(
			'originals' => array(),
			'parents' => array()
		);
		$categoryClass = hikashop_get('class.category');
		$productClass = hikashop_get('class.product');
to:
$qty = $row->product_quantity;
		if(isset($row->main)){
			if(@$row->main->discount) $discount =& $row->main->discount;
			elseif(@$row->discount) $discount =& $row->discount;
			$product_id = $row->main->product_id;
			if($row->product_quantity==-1){
				$qty = $row->main->product_quantity;
			}
		}else{
			if(@$row->discount) $discount =& $row->discount;
			$product_id = $row->product_id;
		}
		
		$badge_filters=array(
			'a.badge_start <= '.time(),
			'( a.badge_end >= '.time().' OR a.badge_end =0 )',
			'a.badge_published=1',
			'(a.badge_quantity=\'\' OR a.badge_quantity='.(int)$qty.')',
		);
		if($discount && isset($discount->discount_id)){
			$badge_filters[]='(badge_discount_id='.(int)@$discount->discount_id.' OR badge_discount_id LIKE \'%,'.(int)@$discount->discount_id.',%\' OR badge_discount_id=\'0\' OR badge_discount_id=\'\' )';
		}else{
			$badge_filters[]='(badge_discount_id=\'0\' OR badge_discount_id=\'\')';
		}

		$categories = array(
			'originals' => array(),
			'parents' => array()
		);
		$categoryClass = hikashop_get('class.category');
		$productClass = hikashop_get('class.product');

		if(!isset($row->categories) && isset($row->main->categories)){
			$row->categories =& $row->main->categories;
		}
in administrator/components/com_hikashop/classes/badge.php
Add the code:
if(!empty($element->variants)){
			foreach($element->variants as $k => $variant){
				$classbadge->loadBadges($element->variants[$k]);
			}
		}
after the code:
$classbadge=hikashop_get('class.badge');
		$this->assignRef('classbadge',$classbadge);
		$classbadge->loadBadges($element);
in the file components/com_hikashop/views/product/view.html.php
And add the line:
$this->element->badges =& $variant->badges;
after the line:
$this->element->images =& $variant->images;
in the file "show" of the view "product" via the menu display>views.
That should allow the system to support that.
Let us know how it goes so that we can add it on our end for the next version.

The following user(s) said Thank You: trevsmiff

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

  • Posts: 306
  • Thank you received: 42
  • Hikamarket Multivendor Hikashop Business
9 years 1 month ago #247061

Hi Nicolas

Thanks for looking into that.

nicolas wrote: And add the line:

$this->element->badges =& $variant->badges;
after the line:
$this->element->images =& $variant->images;
in the file "show" of the view "product" via the menu display>views.
That should allow the system to support that.


I can't find that line in the 'show' file of the 'product' view. I looked in 'product' 'show_block_img' as well but it wasn't there either!

regards
Trevor

Last edit: 9 years 1 month ago by trevsmiff.

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

  • Posts: 26275
  • Thank you received: 4045
  • MODERATOR
9 years 1 month ago #247066

Hi,

Please check one more time in the view "show" ; Nicolas did not make a typo.
If you already have an override for the view, it could explain why you can't find the line, but in that case you would have some issues with variant images...

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: 306
  • Thank you received: 42
  • Hikamarket Multivendor Hikashop Business
9 years 1 month ago #247102

Found it ! (I was using the search facility in FireFox which couldn't find it) :blush:

The patch is working well and the 'Out of stock' badge is now displaying on the variants with zero quantity.

Thank you very much.

Best regards
Trevor

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

  • Posts: 267
  • Thank you received: 5
9 years 1 month ago #247287

Hello,

if the stock is zero the sitema indicates that the item is out of stock, but I need to indicate that some items are in " soon be found for sale " as is " item out of stock " is indicated . But without losing the latter.

Thanks Nicolás

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

  • Posts: 84313
  • Thank you received: 13702
  • MODERATOR
9 years 1 month ago #247289

Hi,

Then, you can change that text with a translation override:
www.hikashop.com/download/languages.html#modify

The following user(s) said Thank You: dvddvd

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

  • Posts: 267
  • Thank you received: 5
9 years 1 month ago #247313

Hi Nicolas,

I understand your response, but I need to also use the stock is zero:
1.- When the stock reaches zero the system should indicate , as does.
2.- I need also indicate the status of the article as "soon be found for sale " somehow.

Thanks

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

  • Posts: 4820
  • Thank you received: 654
  • MODERATOR
9 years 1 month ago #247321

Hello,

Can you precise your idea and needs because I' m not sure to follow you...
Awaiting news from you.

Regards

The following user(s) said Thank You: dvddvd

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

  • Posts: 267
  • Thank you received: 5
9 years 1 month ago #247496

Hi,

I mean add " soon for sale " keeping also " Out of stock ".

Thanks

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

  • Posts: 4820
  • Thank you received: 654
  • MODERATOR
9 years 1 month ago #247501

Hello,

Then, if you want in some case have "Out of stock" alone in some case.
And in other case, have "Out of stock" And in some time add "Soon for sale".

I see two solutions for you :
- Maybe create a badge with a picture and the text, and select product (Out of stock) that will be soon be back.
See this tutorial , to better understand badges system possibilities.

- Or for some reason you want have two different texts for each conditions, and I afraid that will required a custom code in HikaShop.
You can contact one of our partners, here .

Hope this will help you.

Regards

Last edit: 9 years 1 month ago by Philip.
The following user(s) said Thank You: dvddvd

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

Time to create page: 0.085 seconds
Powered by Kunena Forum