2

I'm getting the following error:

[15-Apr-2018 04:10:22 UTC] PHP Fatal error:  Uncaught TypeError: Argument 3 passed to Mage_Catalog_Model_Resource_Abstract::_canUpdateAttribute() must be of the type array, null given, called in /home/xxxx/public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 836 and defined in /home/xxxx/public_html/app/code/core/Mage/Catalog/Model/Resource/Abstract.php:368
Stack trace:
#0 /home/xxxx/public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php(836): Mage_Catalog_Model_Resource_Abstract->_canUpdateAttribute(Object(Mage_Catalog_Model_Resource_Eav_Attribute), '1', NULL)
#1 /home/xxxx/public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php(763): Mage_Eav_Model_Entity_Abstract->_collectSaveData(Object(Mage_Catalog_Model_Product))
#2 /home/xxxx/public_html/app/code/core/Mage/Core/Model/Abstract.php(180): Mage_Eav_Model_Entity_Abstract->save(Object(Mage_Catalog_Model_Product))
#3 /home/xxxx/public_html/app/code/community/Webinse/DailyDeals/Model/Observer.php(261): Mage in /home/xxxx/public_html/app/code/core/Mage/Catalog/Model/Resource/Abstract.php on line 368

Here is core/Mage/Eav/Model/Entity/Abstract.php(836)

    foreach ($newData as $k => $v) {

        if (is_numeric($k) || is_array($v)) {
            continue;
        }

        if (!in_array($k, $staticFields) && !in_array($k, $attributeCodes)) {
            continue;
        }

        $attribute = $this->getAttribute($k);
        if (empty($attribute)) {
            continue;
        }

        $attrId = $attribute->getAttributeId();


        if ($this->isAttributeStatic($k)) {
            $entityRow[$k] = $this->_prepareStaticValue($k, $v);
            continue;
        }


  HERE IS LINE 836 -->   if ($this->_canUpdateAttribute($attribute, $v, $origData)) {
            if ($this->_isAttributeValueEmpty($attribute, $v)) {
                $delete[$attribute->getBackend()->getTable()][] = array(
                    'attribute_id'  => $attrId,
                    'value_id'      => $attribute->getBackend()->getEntityValueId($newObject)
                );
            } elseif ($v !== $origData[$k]) {
                $update[$attrId] = array(
                    'value_id' => $attribute->getBackend()->getEntityValueId($newObject),
                    'value'    => $v,
                );
            }
        } else if (!$this->_isAttributeValueEmpty($attribute, $v)) {
            $insert[$attrId] = $v;
        }
    }

    $result = compact('newObject', 'entityRow', 'insert', 'update', 'delete');
    return $result;
}

Here is core/Mage/Catalog/Model/Resource/Abstract.php:368

 HERE IS LINE 368 --> protected function _canUpdateAttribute(
        Mage_Eav_Model_Entity_Attribute_Abstract $attribute,
        $value,
        array &$origData)
    {
        $result = parent::_canUpdateAttribute($attribute, $value, $origData);
        if ($result &&
            ($attribute->isScopeStore() || $attribute->isScopeWebsite()) &&
            !$this->_isAttributeValueEmpty($attribute, $value) &&
            $value == $origData[$attribute->getAttributeCode()] &&
            isset($origData['store_id']) && $origData['store_id'] != $this->getDefaultStoreId()
        ) {
            return false;
        }

        return $result;
    }

Here is code/community/Webinse/DailyDeals/Model/Observer.php(261)

    public function updateDealsStatuses()
    {
        $helper = Mage::helper('dailydeals');
        $collection = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('deal_status', true);
        foreach ($collection as $item) {
            if ($item->getDealStatus()) {
                $stat = Mage::helper('dailydeals')->checkUpdateDealStatus($item);
                if ($stat != $item->getDealStatuses()) {
                    $helper->changeSpecialData($item, $stat);
   HERE IS LINE 261 -->    $item->setDealStatuses($stat)->save();
                }
            }
        }
    }

The only thing I could find about this error seems to say I need to add Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); somewhere:

Magento failing when trying to save product inside event observer on frontend?

Add products to another category programatically

How can I fix this error? It cause my site to have a 500 server error when the daily deal is over. Thank you.

  • seems need only - Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); – Alex Jan 31 at 20:34
2

getDealStatuses(...) is an overriding function? If so, write that out... If not, then perhaps the issue is that there is no deal_statuses attribute that can be updated, whereas there appears to definitely be a deal_status attribute.

setDealStatuses(...)->save() is invalidly attempting to update a non-existent attribute. If the function is defined in an override, then that needs to be explained.

Update from researching above potential problems

There is an attribute entity defined for deal_statuses, however, it appears that it is incorrectly defined since I have seen that there exists a model, resource model, and collection for deal_statuses... This leads me to asking why it isn't set to use the source from the model. Furthermore, why wouldn't it be configured as an int so that a selection drop down could be used? Why is it not visible, user_defined, contain product types that it needs to apply_to, etc?

These questions are simply rhetorical, as the solution is now evident and will be at the bottom of this post.

$installer->addAttribute($entityTypeId, 'deal_statuses', array(
    'type' => 'varchar',
    'backend' => '',
    'frontend' => '',
    'label' => 'Deal Statuses',
    'note' => ' ',
    'input' => 'text',
    'class' => '',
    'source' => '',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => false,
    'required' => false,
    'user_defined' => false,
    'default' => '',
    'searchable' => false,
    'filterable' => false,
    'comparable' => false,
    'visible_on_front' => false,
    'unique' => false,
    'is_configurable' => false
));

Verified this, so ignore:

And another check that needs to be done:

$helper->changeSpecialData($item, $stat); should be changeSpecialDate(...)?

SpecialDate makes more sense than SpecialData



Notes that may help with Developing for efficient performance:

There is a bit of an issue here with how the attributes are being set and saved within an iteration of a collection loop.

There are two things that would provide more efficient saving of data, should they be applicable to this code.

I think that an entire collection can have data modified, then the collection be saved... look for collection abstract methods save() that implement this.. I could be wrong here.

There is a much more efficient function available saveAttribute(...) in the resource layer, which may work better for updating this single attribute.


Further feedback:

Why would this even be defined: $helper = Mage::helper('dailydeals');

if it's just going to be ignored when time to use it: $stat = Mage::helper('dailydeals')->checkUpdateDealStatus($item);


Potential Solution

Due to the way the deal_statuses attribute has been defined, it appears that it may be missing from any flat catalog product tables. Perhaps the admin store setting updates it to pull from the EAV table unions, as opposed to the flat tables.

If you can access the attribute from the admin, then update the apply_to so that it applies to "All product types". Also update the field so that it can be used on the frontend. Clear cache, reindex, and test.

Sorry to say this, but the code quality of the extensions is poor from what I have seen, and hopefully there were improvements down the line.

The BEST solution would be to check for a newer version, as well as the changelogs to see if the issue has been addressed and resolved.

From what I can tell, there lacked experience with Magento Architecture and framework at the time this code was developed.

I would hope that you find this extension to be improved with a newer released version, and that you are able to use it effectively in a way that you can find a return on investment.

  • I appreciate your help very much but I have decided to delete the extension as it is giving me to many errors and I'm tired of working on it. Thank you. – Freejoy Apr 15 '18 at 7:22
  • If this answer helped lead to removal of the extension, +1 ? – df2k2 Apr 15 '18 at 8:23

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.