1

How to add simple product to basket if this product is child of configurable product ?

How I can get super_attributes of simple product ( I got ID ) to make it ?

An example: I have T-shirts (id 1) configurable product.

And I got XL (id 5), L (id 6) versions of this product.

I want add to shopping cart id 5, but I cannot make it without requestInfo (super_attributes) when I'm using addProduct($productInfo, $requestInfo=null)

1

1 Answer 1

1

Ok , I got it.

Steps.

1. load child product object.

2. load parent id from child id.

3. load parent product object.

4. get parent array of attributes

($parent->getTypeInstance(true)->getConfigurableAttributesAsArray($parent);)

5. Make loop for array of attributes

6. $attributeId = $attribute['attribute_id']

7. And use in loop getAttributeRawValue method for value of attribute.

8. $cart->addProduct($parent, array('qty => 4, 'super_attribute' => array($attributeId => $value)));

9. $cart->save();

10. Open your beer
2
  • hello amit can you explain it with code for magento2 Jun 29, 2017 at 15:58
  • Does the getAddUrl take the same params? We are trying to add products to the cart by a direct URL (via ajax)
    – snh_nl
    Nov 8, 2018 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.