Jump to content

$product.allow_oosp always returns 0 on Product List


Recommended Posts

Hi:

I'm trying to setup a custom message both in my product page and product list page for product backorders, but I'm having a bit of an issue. In the product page it works as intended. Shows In Stock when theres stock for the combination selected, returns Backorder message when $product.quantity =< 0 and $product.allow_oosp is set, and shows an Out of Stock message when There are no units left and $product.allow_oosp is not set. Search results and various modules (like featured products) work like they're supposed to, returning the original $category.allow_oosp value.

However in my product list (Category page) It returns In stock when $product.quantity_all_versions > 0 (as intended) and it ALWAYS defaults to out of stock when quantity for all combinations is 0 or lower, and what's more interesting, {$category.allow_oosp} value is ALWAYS 0.

Is it possible the loop isn't returning that variable at all on product list?

{if $product.quantity_all_versions > 0}
	<span class="stocklabel">{l s='In stock' d='Shop.Theme.Product'}</span>
{else}
	{if $product.allow_oosp}
		<span class="stocklabel backorder">{$product.available_later}</span>
	{else}
		<span class="stocklabel oos">{l s='Not available' d='Shop.Theme.Product'}</span>
	{/if}
{/if}

All help is appreciated. I'm quite a newb, as you may notice 😕 

Edited by Luis C
more info. (see edit history)
Link to comment
Share on other sites

  • 2 years later...

Nah, ended up solving it with a different approach. I wrote a multi-purpose module and determined both stock and order out of stock feature there, calling the module with the widget interface in the catalog/_partials/miniatures/product.tpl

Link to comment
Share on other sites

19 hours ago, gabrielrey37 said:

I have exact the same problem, do you resolve it?

In case you're looking for a solution, here's a snippet of my code so you can write your own.

 

	function hookDisplayProductListExtra($params){
        $id_producto = $params['productid']; // we determine the product ID using the hook implementation in the template file. {hook h='displayProductListExtra' productid=$product.id_product}

        $product = new Product($id_producto); // Create a new Product instance
        $variantes = $product->getAttributeCombinations(); // Get all combinations
        $stock = array();
        $shopbehavior = Configuration::get('PS_ORDER_OUT_OF_STOCK'); // Get current out of stock behaviour from shop. Careful with multishop implementations
        $allow_oosp = $product->out_of_stock;
        foreach($variantes as $variante) // Iterate each combination, look for the qty variable and add them to an array
        {
            array_push($stock, $variante['quantity']);
        }
        if (max($stock) > 0){ // If the sum of all array values is greater than 0, we assign a true boolean to an smarty variable, otherwise we assign false
            $this->context->smarty->assign('stockall', true);
            $stockall = true;
        }else{
            $this->context->smarty->assign('stockall', false);
            $stockall = false;

        }
        $sale = 0;
        if($allow_oosp == 0){
            $sale = 0;
        }elseif($allow_oosp == 1) {
            $sale = 1;
        }elseif($allow_oosp == 2){
            if($shopbehaviour == 0) {
                $sale = 0;
            }else{
                $sale = 1;
            }
        }
        $this->context->smarty->assign('sale', $sale); // determine the current behavior both for product OOSP and shop OOSP. 0 = deny sale, 1 = accept sale, 2 = default shop behaviour
        return $this->display(__FILE__, 'stock.tpl');


    }

Use the template file to show the correct tag in your preferred hook (or calling the module with Widget interface) depending on allow_oosp behavior ({$sale}) and qty ($stockall)

Link to comment
Share on other sites

  • 2 years later...

Did you find a solution? I have the same issue...

Actually, $product.allow_oosp changes from 0 to 1 for the products that are added to cart :)))

 

This only happens on product list (categories). It does not happen to homepage or propduct page.

I've traced the issue to this file, but couldn't advance further: \src\Adapter\Presenter\Product\ProductLazyArray.php

 

Also, there might be a confusion between the out_of_stock field in ps_stock_available (which is related to the option to be able to add to cart products with no stock) and out_of_stock field in ps_product (which I couldn't find what it does).

Edited by razvy (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...