Adding option to a product create error

I'm extending the \Magento\Catalog\Block\Product\View file in AddToCart.php.

In my AddTocart, I've added this line :

$stock = $this->isInStockCustom($sku);

Now, I'm adding options to my products. It was working find until now.

But if I add an option to this product, in my log, I have this

Invalid method Magento\Catalog\Block\Product\View\Interceptor::isInStockCustom [] []

But if I remove the options, I don't have this error anymore.

Any help would be very appreciated.

Solutions

Go it :

also need to change this in catalog_product_view.xml:

<block class="Vendor\Module\Block\AddToCart" 
name="product.info.addtocart.additional" as="product.info.addtocart" 
template="Magento_Catalog::product/view/addtocart.phtml"/>

Because additional option and simple product are not the same.

Similar questions

Magneto: Adding configurable product to cart fails : Please specify the product's option(s)
Using Magento 1.7.0.2 I'm able to add simple products to the cart with out any problem. But when I'm trying to add configurable product to the cart it throws following XmlRpcException. API documentation for this xml-rpc call http://devdocs.magento.com/guides/m1x/api/soap/checkout/cartProduct/cart_product.add.html Magento API doc wasn't much helpful...
Get option Value from Option label for product/store
Having a option value for an attribute I would like to get the code/id associated to this option value. How can I get this ? Sql/Magento model approach are both wellcome EDIT: I can retrieve option label for an attribute of a configurable product in this way: } What is missed here for me is the possibility to get the label for a particular store vi...
Where is Option Id of Newly Added Option For Bundle Product?
So I have a module, which I am using to set a custom field in bundle options. I have implimented my module successfully. However I came to a situation to which I can't move on without get an answer for this problem. In my module, in order to save data to my custom fields, I am observing to <catalog_product_save_after />. In my custom table,al...
Get multiple select product attribute's option labels instead of option IDs
I have a product attribute, Available Sizes in Magento. The input type is Multiple Select. The options for the attribute are Small, Medium and Large. Normally when I call a product attribute on the frontend, I use echo $_product->getAttributeCode(); With this attribute, when I use echo $product->getAvailableSizes(); it is giving me the values...
Implement the option of choosing product weight on drop down option
I Would like the same exact option shown in the image to implement on my site. how can it be done
how to Implement the option of choosing product weight on drop down option
i want to display as like above image in my website in product list page.

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.