Please specify the product’s option(s). in magento 1.9.2

I’ve this issue early, I’ve tired with searching on this issue and nothing helpfull.

so what I’m trying to ask here, I’ve this magento 1.9 server and the products is set on, the adding into cart for simple product is working smoothly and fine, but when I try to add configurable product this message return.

Please specify the product’s option(s).

Now I was tracing the code and working on it, till i reach here.

app/code/core/Mage/Checkout/controllers/CartController

in this file this code for adding the product exists:

/**
 * Add product to shopping cart action
 *
 * @return Mage_Core_Controller_Varien_Action
 * @throws Exception
 */
public function addAction()
{
    if (!$this->_validateFormKey()) {
        $this->_goBack();
        return;
    }
    $cart   = $this->_getCart();
    $params = $this->getRequest()->getParams();

    try {
        if (isset($params['qty'])) {
            $filter = new Zend_Filter_LocalizedToNormalized(
                array('locale' => Mage::app()->getLocale()->getLocaleCode())
            );
            $params['qty'] = $filter->filter($params['qty']);


        }

        $product = $this->_initProduct();
        $related = $this->getRequest()->getParam('related_product');


        /**
         * Check product availability
         */
        if (!$product) {
            $this->_goBack();
            return;
        }
        echo 'here';
        ?>
            <pre>
                <?php print_r($params); ?>
            </pre>
        <?php
            exit;
        ?>
        <?php

        $cart->addProduct($product, $params);
        if (!empty($related)) {
            $cart->addProductsByIds(explode(',', $related));
        }

        $cart->save();

        $this->_getSession()->setCartWasUpdated(true);

        /**
         * @todo remove wishlist observer processAddToCart
         */
        Mage::dispatchEvent('checkout_cart_add_product_complete',
            array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
        );

        if (!$this->_getSession()->getNoCartRedirect(true)) {
            if (!$cart->getQuote()->getHasError()) {
                $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
                $this->_getSession()->addSuccess($message);
            }
            $this->_goBack();
        }
    } catch (Mage_Core_Exception $e) {
        if ($this->_getSession()->getUseNotice(true)) {
            $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage()));
        } else {
            $messages = array_unique(explode("n", $e->getMessage()));
            foreach ($messages as $message) {
                $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message));
            }
        }

        $url = $this->_getSession()->getRedirectUrl(true);
        if ($url) {
            $this->getResponse()->setRedirect($url);
        } else {
            $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl());
        }
    } catch (Exception $e) {
        $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.'));
        Mage::logException($e);
        $this->_goBack();
    }
}

in this code I used this simple code to achive where i’m and what data i have.

echo 'here';
?>
    <pre>
        <?php print_r($params); ?>
    </pre>
<?php
    exit;
?>
<?php

This simple code return the arguments i have for my Configurable Product.

Array
(
    [uenc] => aHR0cDovL3N0YWdpbmcudmF0dHJlbmEuY29tL2luZGV4LnBocC9nZW5lcmFsLWplYW5zMTMuaHRtbA,,
    [product] => 65
    [form_key] => qIGyp6YDp7kQjibA
    [related_product] => 
    [super_attribute] => Array
        (
            [168] => M
        )

    [qty] => 1
)

That mean all attributes is chosen, but after this simple code when i reach the

$cart->addProduct($product, $param);

it suppose to go to this file

app/code/core/Mage/Checkout/Model/Cart.php

On this function

/**
 * Add product to shopping cart (quote)
 *
 * @param   int|Mage_Catalog_Model_Product $productInfo
 * @param   mixed $requestInfo
 * @return  Mage_Checkout_Model_Cart
 */
public function addProduct($productInfo, $requestInfo=null)
{
    $product = $this->_getProduct($productInfo);
    $request = $this->_getProductRequest($requestInfo);

    $productId = $product->getId();

    if ($product->getStockItem()) {
        $minimumQty = $product->getStockItem()->getMinSaleQty();
        //If product was not found in cart and there is set minimal qty for it
        if ($minimumQty && $minimumQty > 0 && $request->getQty() < $minimumQty
            && !$this->getQuote()->hasProductId($productId)
        ){
            $request->setQty($minimumQty);
        }
    }

    if ($productId) {
        try {
            $result = $this->getQuote()->addProduct($product, $request);
        } catch (Mage_Core_Exception $e) {
            $this->getCheckoutSession()->setUseNotice(false);
            $result = $e->getMessage();
        }
        /**
         * String we can get if prepare process has error
         */
        if (is_string($result)) {
            $redirectUrl = ($product->hasOptionsValidationFail())
                ? $product->getUrlModel()->getUrl(
                    $product,
                    array('_query' => array('startcustomization' => 1))
                )
                : $product->getProductUrl();
            $this->getCheckoutSession()->setRedirectUrl($redirectUrl);
            if ($this->getCheckoutSession()->getUseNotice() === null) {
                $this->getCheckoutSession()->setUseNotice(true);
            }
            Mage::throwException($result);
        }
    } else {
        Mage::throwException(Mage::helper('checkout')->__('The product does not exist.'));
    }

    Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product));
    $this->getCheckoutSession()->setLastAddedProductId($productId);
    return $this;
}

But when i try to echo anything in this function, it won’t appear and redirected to the configurable product page with This message

Please specify the product’s option(s).

I’m Thanking anyone can help me with this issue, and i’m thanking everyone for trying to help


Source: stackoverflow-php

routing by frontName like {frontName}/[params1]/[paramsX]… in magento2

Magento2 processing requests with the structure like:

{frontName}/{controller}/{action}

but i need to process some requests with the structure like

{frontName}/[params1]/[paramsX]...

what’s the best way to solve it?
Event linstener for controller_front_send_response_before?
Interceptor for MagentoUrlRewriteControllerRoute?
or any other … thanks very much


Source: stackoverflow-php