4

While trying to load the simple product "child" of a configurable product in the order email item detail, I ran this code:

if ($_item->getProductType() == 'configurable') {
    $options = $_item->getProductOptionByCode('info_buyRequest');

    /** @var Mage_Catalog_Model_Product $_simpleProduct */
    $_simpleProduct = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($options['super_attribute'], $_product);
} else {
    /** @var Mage_Catalog_Model_Product $_simpleProduct */
    $_simpleProduct &= $_product;
}

...and got this error:

PHP Fatal error:  Call to a member function getBackend() on a non-object in [...]\app\code\core\Mage\Eav\Model\Entity\Abstract.php on line 816

It looks like that line tries to load an attribute, and can't find it, and then errors. The attribute code that it's trying to load is uenc which I can't find anywhere in eav_attribute. It turns out that uenc is a key in the array returned by $options = $_item->getProductOptionByCode('info_buyRequest'); and I don't know why.

After some searching of the codebase, all I can find are various third party modules that all unset this array key as if it's consistently problematic, and a note about the value of this key being a base64 encoded product URL for the purchased product. (It looks like the constant PARAM_NAME_URL_ENCODED is actually used when this data is being added.)

Does anyone know what this is here for, and why it breaks getProductByAttributes()? It seems like I'm not the first developer to run into this issue.

2
  • I'm curious about this field I suspect (as of doing zero research on this so far) that it is security related (add to cart form origin) or helps with redirecting users.
    – jamil
    Jun 28, 2018 at 0:23
  • Not sure the purpose but it is indeed the base64 encoded product URL.
    – aredridel
    Sep 16, 2019 at 19:20

0

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.

Browse other questions tagged or ask your own question.