Jump to content

Edit History

AfterGlow93

AfterGlow93

On 6/24/2022 at 6:51 PM, Mateuniu said:

Hello I'm trying to override my CartController -> "Check product quantity availability" The problem is how to get quantity of single product, not all combinations. My code is:

if ('update' !== $mode && $this->shouldAvailabilityErrorBeRaised($product, $qty_to_check)) {
	$this->{$ErrorKey}[] = $this->trans(
		'The item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted %productQuantity% - %productCheck%.',
		array('%product%' => $product->name, '%productQuantity%' => $product->quantity, '%productCheck%' => $qty_to_check),
		'Shop.Notifications.Error'
	);
}

I'm trying to display product quantity (of single combination) with $product->quantity but it shows quantity of all combinations.

 

Thanks :)

Hi, 

You have to use $combinations instead of $product.

To loop through each combination on one product, use a foreach loop : 

{foreach from=$combinations item=combination}
    {$combination->quantity} 
{/foreach}

To show only the selected combination, grab combination from your product in cart using {$product.id_product_attribute}

So, the whole thing would be done with something like like this : 

{if $combinations}
{foreach from=$combinations item=combination}
{if $combination.id == $product.id_product_attribute}
    {$combination->quantity} <-- show quantity of current combination in product loop -->
{/if}
{/foreach}
{else}
.......  <--  insert your current code for products without combination -->
{/if}

 

AfterGlow93

AfterGlow93

On 6/24/2022 at 6:51 PM, Mateuniu said:

Hello I'm trying to override my CartController -> "Check product quantity availability" The problem is how to get quantity of single product, not all combinations. My code is:

if ('update' !== $mode && $this->shouldAvailabilityErrorBeRaised($product, $qty_to_check)) {
	$this->{$ErrorKey}[] = $this->trans(
		'The item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted %productQuantity% - %productCheck%.',
		array('%product%' => $product->name, '%productQuantity%' => $product->quantity, '%productCheck%' => $qty_to_check),
		'Shop.Notifications.Error'
	);
}

I'm trying to display product quantity (of single combination) with $product->quantity but it shows quantity of all combinations.

 

Thanks :)

Hi, 

You have to use $combinations instead of $product.

To loop through each combination on one product, use a foreach loop : 

{foreach from=$combinations item=combination} {$combination->quantity} {/foreach}

{foreach from=$combinations item=combination}
    {$combination->quantity} 
{/foreach}

To show only the selected combination, grab combination from your product in cart using {$product.id_product_attribute}

So, the whole thing would be done with something like like this : 

{if $combinations}
{foreach from=$combinations item=combination}
{if $combination.id == $product.id_product_attribute}
    {$combination->quantity} <-- show quantity of current combination in product loop -->
{/if}
{/foreach}
{else}
.......  <--  insert your current code for products without combination -->
{/if}

 

×
×
  • Create New...