0

Friends, I need your help.

I want to make the "Out of Stock" status display on the "Add to Cart" button when the quantity in the warehouse becomes "0". Should work in the Category and Product.

I only know this solution:

controller/product/category.php

After: $data['products'][] = array(

Add:

'quantity'      => $result['quantity'],   
'my_text'       => $result['stock_status'],

category.twig

Replace: {{ button_cart }}

To:

{% if product.quantity > 0 %}
{{ button_cart }}
{% else %} 
{{ product.my_text }}
{% endif %}

But this method shows all the statuses, but I need only "out of stock"(id=5) and apply disabled="disabled" to it. Other status names should be displayed and without "disabled".

I know what to start with this:

model/catalog/product.php

After: $query->row['special'],

Add: 'stock_status_id' => $query->row['stock_status_id'],

But what's next?

Sorry for my English. I'm using Google Translate.

VeroN
  • 37
  • 11
  • Hi veron, I have provided you the solution .May I know where you are facing difficulties? – Radhika Apr 26 '18 at 04:43
  • @Radhika, i'm very glad to see you again. I thought you did not appear here anymore, since you no longer contacted me in our chat room. With the previous decision, unfortunately, I can not achieve the result. A slightly different solution is obtained :( – VeroN Apr 26 '18 at 05:38
  • I want to disable the "add to cart" button with the "disabled" function, but only for the "out of stock" status. If the status name changes for example to "2-3 days" or "preorder"...etc., then the button should work and show the status regardless of how many in the warehouse. The button is disabled when the "out of stock" status is selected in the admin panel, it is shown by the text on the button and the button is not available for the disabled and also when and accordingly the quantity in the warehouse becomes zero. – VeroN Apr 26 '18 at 05:38
  • Sorry it is totally out of mind to reply you in chat. Please check answer – Radhika Apr 26 '18 at 06:10

1 Answers1

2

In catalog/controller/product/category.php:

add -

if($result['quantity'] > 0){
              $cart = 'ena';
                $cart_text = $this->language->get('button_cart');
}
elseif($result['stock_status_id'] = 5 || $result['quantity'] <= 0){
                $cart = 'dis';
                $cart_text = 'Out Of Stock';
            }

before -

$data['products'][] = array(

add -

'cart_text'   => $cart_text,
                'cart'        => $cart,

after -

$data['products'][] = array(
                'product_id'  => $result['product_id'],
                'thumb'       => $image,
                'name'        => $result['name'],

In catalog/view/product/category.tpl

edit for button cart as below:

 <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');" <?php if($product['cart'] == 'dis') { echo 'disabled'; } ?>><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $product['cart_text']; ?></span></button>
Radhika
  • 533
  • 5
  • 22
  • Radhika, i made a screenshot, please see how it works with this code, also i wrote notes on how this should work. [Screenshot link](https://s6.postimg.cc/de7u8pnsh/Screenshot-2018-4-26_Phones_PDAs.jpg) – VeroN Apr 26 '18 at 08:15
  • @VeroN, as per your description, you told that if quantity = 0 then button should be disabled – Radhika Apr 26 '18 at 08:22
  • Radhika, i apologize if you misunderstand me. This is the error of Google Translate. In the comments in the first post I hope that I correctly expressed my thoughts. I meant to show all the statuses on the button but to disable only id = 5 and when the number is 0. When the number is zero and if the status in the admin panel is like "2-3 days", the button is not disabled. In the standard value "out of stock" and when the amount is greater than zero, the text on the button should show "add to cart" as usual. In the screenshot, I think I showed my thoughts better. – VeroN Apr 26 '18 at 08:54
  • @VeroN, Check my answer. Edited as per your requirement. – Radhika Apr 26 '18 at 11:59
  • Now it's getting better. Radhika, is it possible to make that when the product has zero quantity, then the text on the button will always be "out of stock" (id = 5) regardless of which status(for example 2-3 days, Pre-Order etc.) it is selected ? It turns out there will be only two options: Or "add to cart" (when quantity is greater than zero) or "out of stock"(when less than one). Also now i receive an error: `Undefined index: button_cart`. – VeroN Apr 26 '18 at 12:02
  • Radhika, when the product has a zero quantity, then the button shows another status(which is selected in the admin panel, for example "2-3 days"), but can possible make it so that with zero balance the status on the button is strictly fixed only to "out of stock"(id=5) regardless of what status is set in the admin panel? – VeroN Apr 26 '18 at 12:42
  • Radhika, is it possible to use the value and text from the admin panel by `ID=5` and `status.name`? I mean the replacement of the text in this line: `$cart_text = 'Out Of Stock';` – VeroN Apr 26 '18 at 13:10
  • No veron it is not possible – Radhika Apr 26 '18 at 13:22
  • Radhika, maybe can add an additional index? For example, if use `$cart_text = $result['name'];`, then the text works. Or here other case and only a binding to manual text? – VeroN Apr 26 '18 at 13:46
  • $result['name'] will give you a product name so manual text will be a good way – Radhika Apr 27 '18 at 04:41
  • Yes, Radhika, `results[name]` is just an example to see if it's possible to do the same but for example so `results[stock_status_id]=5 : results [stock_status.name]`. But if you say that there are no more options, then i completely trust you, so i do not have any more questions on this topic. Thank you very much for your help, Radhika. I will say again and again that you are the most beautiful human with whom i have had to communicate. Have a nice day. – VeroN Apr 27 '18 at 05:38