0

i am adding products to cart but it shows me:

please specify the product's option(s)

how i can display which product option is missing in notifications.

basically i want to display options missing to user so he know what he has to select before add to cart.

Thanks

0

this can be a bit tricky but here are some options

You can do a rewrite/overload of a few classes

Mage_Catalog_Model_Product_Option_Type_Date
public function validateUserValue($values){ ... }

Mage_Catalog_Model_Product_Option_Type_Default
public function validateUserValue($values){ ... }

Mage_Catalog_Model_Product_Option_Type_File
protected function _validateUploadedFile(){ ... }
protected function _validateFile($optionValue) { ... }

Mage_Catalog_Model_Product_Option_Type_Select
public function validateUserValue($values){ ... }

Mage_Catalog_Model_Product_Option_Type_Text
public function validateUserValue($values)

Mage_Catalog_Model_Product_Type_Configurable
public function getSpecifyOptionMessage()

Mage_Catalog_Model_Product_Type_Grouped
protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)

Now, Mage_Catalog_Model_Product_Type_Abstract has a function called public function getSpecifyOptionMessage()

Abstract classes should be left alone if possible, so in your model, you can set that same function to be used instead of the abstract one.

Ok, now that you know where they are all set, its going to be interesting if you have to do them all. If it was me, I would just focus on the Configurable and Grouped. Since that is more than likely where its coming from

Mage_Catalog_Model_Product_Type_Configurable
public function getSpecifyOptionMessage()

Mage_Catalog_Model_Product_Type_Grouped
protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)

Finding where they come from, the easy part. Now to answer your question, how to add some additional messaging.

For Configurable there is a function public function checkProductBuyState($product = null) that calls that message.

public function checkProductBuyState($product = null)
{
    parent::checkProductBuyState($product);
    $product = $this->getProduct($product);
    $option = $product->getCustomOption('info_buyRequest');
    if ($option instanceof Mage_Sales_Model_Quote_Item_Option) {
        $buyRequest = new Varien_Object(unserialize($option->getValue()));
        $attributes = $buyRequest->getSuperAttribute();
        if (is_array($attributes)) {
            foreach ($attributes as $key => $val) {
                if (empty($val)) {
                    unset($attributes[$key]);
                }
            }
        }
        if (empty($attributes)) {
            Mage::throwException($this->getSpecifyOptionMessage());
        }
    }
    return $this;
}

You could do something like

public function checkProductBuyState($product = null)
{
    $additional_info = '';
    parent::checkProductBuyState($product);
    $product = $this->getProduct($product);
    $option = $product->getCustomOption('info_buyRequest');
    if ($option instanceof Mage_Sales_Model_Quote_Item_Option) {
        $buyRequest = new Varien_Object(unserialize($option->getValue()));
        $attributes = $buyRequest->getSuperAttribute();
        if (is_array($attributes)) {
            foreach ($attributes as $key => $val) {
                if (empty($val)) {
                    $additional_info . ' ' . $val;
                    unset($attributes[$key]);
                }
            }
        }
        if (empty($attributes)) {
            Mage::throwException($this->getSpecifyOptionMessage().' You forgot ' . $additional_info);
        }
    }
    return $this;
}

For Grouped protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)

The process would be similar to Configurable, but there is a different function but in the end, we just need to determine what is missing and append it to the message.

Please keep in mind I did not try this, but it should give you a good starting point.

2
  • thanks for help. problem is this we have custom options under product when user click on add to cart button then system gives error: Please specify the product's option(s). and we are not sure which option is missing. thanks for help if u have any idea please let me know. – Sandeep Singh Jan 6 '16 at 20:51
  • By doing a rewrite of Models you will have the ability to set/fix the error message, but you will have to rewrites. There is no real easy way to handle this, otherwise Magento would of added this to default functionality. – RussellAlbin Jan 6 '16 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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