1
votes

I'm attempting to add a configurable product to the cart using the url parameters but I'm still getting a "Please specify the product's option(s)." when I try to add a product to the cart using the url:

/myConfigurableProduct.html?options=cart&product=6&related_product=&super_attribute[146]=60&super_attribute[147]=67&super_attribute[145]=57&super_attribute[144]=49&super_attribute[148]=69&super_attribute[149]=75&super_attribute[150]=80&qty=1

I've looked through the Magento docs for a solution to this and found that this can be done from the cart page using the /cart/add?, but I'm trying to do it from the product view page.

The url super_attributes selected don't show a error when submitted using the form, but fails when using the url. Am I missing something here?

1
Please edit to post your final solution. I like this... we need to sometimes give customers a URL and it would be nice to click and it's in the cart.Chris K

1 Answers

1
votes

Just for sake of explaining some things, lets say you want a link on your product page that adds the product to the cart in a specifically configured way. For example, lets use the old standby of a "T-Shirt". There can probably be color and size for attributes. Lets also say you sell "Pants" that have a size and color, but you want the user to be able to use the dropdowns for pants and have buttons for T-Shirts.

The buttons would be pre-configured, and the pants would allow any choice

You would do the following in the app/designt/frontend/YOURTHEME/default/template/catalog/product/view.phtml

Look for

<?php if ($_product->isSaleable() && $this->hasOptions()):?>
    <?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>

and replace it with something like this

 <?php 
    if ($_product->isSaleable() && $this->hasOptions())
    {
        $attSetName = "TSHIRT";
        $product = Mage::registry('current_product');
        $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
        $attributeSetModel->load($product->getAttributeSetId());
        $attributeSetName  = $attributeSetModel->getAttributeSetName();

        // Its only going to work on Tshirts that are configurable products
        // All others (PANTS) will fall to the default magento functionality
        if (strtoupper($attributeSetName)== $attSetName && $product->getTypeId() == "configurable")
        {
            // Here is where you will add the cart links to set up products directly to the cart
            // It *MAY* make more sense to set these up as custom variables, but for simplicity's sake, lets just hard code them in here for now

            $productA = "/?super_attribute[146]=60&super_attribute[147]=67&super_attribute[145]=57&super_attribute[144]=49&super_attribute[148]=69&super_attribute[149]=75&super_attribute[150]=80&qty=1";
            $productB = "/?super_attribute[146]=60&super_attribute[147]=67&super_attribute[145]=57&super_attribute[144]=49&super_attribute[148]=69&super_attribute[149]=75&super_attribute[150]=80&qty=1";

            echo '<div id="YOURATTRIBUTESETNAMEcustomProducst">';
            echo '<a href="/checkout/cart/add/product/' . $_product->getId() . $productA . '" />Buy Custom Option A</a>';
            echo '<a href="/checkout/cart/add/product/' . $_product->getId() . $productB . '" />Buy Custom Option B</a>';
            echo '</div>';
        }
    }
    else
    {
        // Do the default magento action
        // *not sure if container1 or container2. Each section does its own thing so
        // just experiment. Mine was container2
        echo $this->getChildChildHtml('container2', '', true, true);
    }

?>

This code is untested. I coded it up on the fly, and I believe strongly that it is a sound base to find a good solution! GOOD LUCK.