Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
171 Vistas

I'm using Odoo v18 for my e-commerce website and I want to show the in stock status of products. The "Out-of-stock" message is only shown when a product is out of stock, it's too low on the page. Showing the quantity available is not what I need either.

For regular products that have no variants I'm able to use product.qty_available​ in the website_sale.product​ view. However when I have a product with multiple variants this can't be used as when at least one of the variants is in stock the product.qty_available​ will be higher than 0.

What I need is a way to access the qty_available​ for the specific variant that is selected.

I've tried product.product.qty_available​ but that gives me a internal server error. Accessing the combination info only works partially for the variant initially selected on page load but that doesn't update when a visitor selects a different variant.

Is there a way to access the selected variant's stock information on the product detail page in a way that it updates when a visitor selects a different variant?

Avatar
Descartar

Hello,
You need to check the qty by product variant on shop page, right?

Autor

Correct, on /shop/[PRODUCT]​. Where the customer can see the product details and click the add to cart button. I want to add the In stock notification just above the add to cart button.

Review this :<t t-set="combination_info" t-value="variant_id._get_combination_info_variant()"/>. May be helpful for you..

Autor

That results in a internal server error. There is no `variant_id`.

```
Error while render the template
KeyError: 'variant_id'
Template: website_sale.product
```

Let you know if I got any solution..

Autor

Correct and that needs to update when a customer selects different variant of the product

Autor

So far I have been kind of get it to work with the code below. The problem is that this doesn't update when I a customer selects a different variant. `product_variant` doesn't get updated.

```
<t t-set="product_variant" t-value="product.env['product.product'].browse(combination_info['product_id'])"/>
<div t-if="(product_variant.sudo().qty_available or 0.0) &gt; 0">In stock</>
```

You have to take vast changes in python, JS and XML for this.

Autor

Bummer, where is the price update being done? That does change when a new product variant is changed.

I'm using Theme Prime. Maybe I can update that to include this.

It is using this to display price
<span class="oe_price"
style="white-space: nowrap;"
t-out="combination_info['price']"
t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
When variant is changed the extra price of the product is included in this price using JS:
'change .js_main_product [data-attribute_exclusions]': 'onChangeVariant',
XML: <div class="js_product js_main_product mb-3">
Please debug into these things, you will get solution for this. Thanks

Publicaciones relacionadas Respuestas Vistas Actividad
2
oct 25
408
2
dic 23
2754
1
oct 23
2912
4
oct 23
5602
2
oct 24
3613