Pergunta

I've written some code in magento which will add a product to the cart if the total is above a certain amount. At the moment, it's only working for Simple Products. I want to add a configurable product, and just tell it which simple product (which size) to select.

The following code is my params, as I've seen people use around the net:

$params = array(
     'product' => 369,
     'super_attribute' => array(
            22 => 12 ,
      ),
     'qty' => 1,
);

Where '22' is the id of an attribute, and '12' would be the specific attribute value. I have no idea how to find my version of '22', I don't know whether a Simple Product counts as an attribute of a configurable product or not.

The code I call at the end is:

$product = new Mage_Catalog_Model_Product();
$product->load(369); 
$cart->addProduct($product, $params);                               
$cart->save();
Foi útil?

Solução

Obvious once you know where to look. If you visit the configurable product's page, and check the source on the drop down menu, you will find both the attribute ID and the value ID.

Happy programming :)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top