6

We have a custom attribute which is added to the default attribute group. Used in product listing is yes and it is added in the config.xml to the product collection.

The values of the attribute are set using \Mage_Catalog_Model_Product_Action::updateAttributes in a data upgrade script.

Anyways, the values are not displayed in the product listing. When the product is saved in the backend, it becomes visible.

Rebuilding all indices using indexer.php or n98-magerun.phar did not help.

EDIT

data upgrade script 1

$installer = $this;
$installer->startSetup();

$attrCodeDeliveryTimeFrom = 'delivery_time_from';
$attrCodeDeliveryTimeTo = 'delivery_time_to';
$attrGroupName = 'General';
$attrLabelDeliveryTimeFrom = 'Delivery time from (days)';
$attrLabelDeliveryTimeTo = 'Delivery time to (days)';
$attrNoteDeliveryTimeFrom = 'Days from';
$attrNoteDeliveryTimeTo = 'Days to';

$objCatalogEavSetup = Mage::getResourceModel('catalog/eav_mysql4_setup', 'core_setup');
$attrIdTest = $objCatalogEavSetup->getAttributeId(Mage_Catalog_Model_Product::ENTITY, $attrCodeDeliveryTimeFrom);

if ($attrIdTest === false) {
    $objCatalogEavSetup->addAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCodeDeliveryTimeFrom, array(
    'group' => $attrGroupName,
    'sort_order' => 50,
    'type' => 'int',
    'backend' => '',
    'frontend' => '',
    'label' => $attrLabelDeliveryTimeFrom,
    'note' => $attrNoteDeliveryTimeFrom,
    'class' => '',
    'source' => '',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => true,
    'required' => false,
    'user_defined' => true,
    'visible_on_front' => true,
    'unique' => false,
    'is_configurable' => false,
    'used_for_promo_rules' => true
    ));
}

$attrIdTest = $objCatalogEavSetup->getAttributeId(Mage_Catalog_Model_Product::ENTITY, $attrCodeDeliveryTimeTo);

if ($attrIdTest === false) {
    $objCatalogEavSetup->addAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCodeDeliveryTimeTo, array(
    'group' => $attrGroupName,
    'sort_order' => 51,
    'type' => 'int',
    'backend' => '',
    'frontend' => '',
    'label' => $attrLabelDeliveryTimeTo,
    'note' => $attrNoteDeliveryTimeTo,
    'class' => '',
    'source' => '',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => true,
    'required' => false,
    'user_defined' => true,
    'visible_on_front' => true,
    'unique' => false,
    'is_configurable' => false,
    'used_for_promo_rules' => true
    ));
}

$setup = Mage::getResourceModel('catalog/setup','catalog_setup');
$setup->removeAttribute('catalog_product','delivery_time');

date upgrade script 2

$installer = $this;
$installer->startSetup();

$_productCollection = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addStoreFilter(2);
$storeId = 0;

foreach ($_productCollection as $_product) {
    $product = Mage::getModel('catalog/product')->load($_product->getEntityId());
    $data = array(
    'delivery_time_to' => 3,
    'delivery_time_from' => 1
    );
    Mage::getSingleton('catalog/product_action')->updateAttributes(array($product->getId()), $data, $storeId);
}


$installer->endSetup();

We did the attribute creation in a data upgrade script. Maybe this is the problem.

7
  • Is just the value not display or the whole product missing?
    – Tobias
    Commented Jun 11, 2014 at 12:31
  • @Tobias: The value is missing.
    – Alex
    Commented Jun 11, 2014 at 12:36
  • ok i had similar issues with complete product missing. i know that's not your problem. anyway i would suggest check if there exists an attribute value for store_id 0, at least in earlier magento version this lead to that error. if you have specific store values, you needed at least a NULL entry as value for store_id=0. this just as comment as it's just an idea and not guaranteed to work, sorry ;)
    – Tobias
    Commented Jun 11, 2014 at 13:59
  • Do you happen to use flat tables for products? If so, make sure your catalog_product_flat_1, 2, 3... have populated values for your attribute. Commented Jun 11, 2014 at 14:16
  • Flat tables are off.
    – Alex
    Commented Jun 12, 2014 at 12:28

3 Answers 3

3

Alex,

This is missing in your attribute data: 'used_in_product_listing' => true

Please try by adding that in your code. I tried and it works.


if ($attrIdTest === false) {
    $objCatalogEavSetup->addAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCodeDeliveryTimeFrom, array(
    'group' => $attrGroupName,
    'sort_order' => 50,
    'type' => 'int',
    'backend' => '',
    'frontend' => '',
    'label' => $attrLabelDeliveryTimeFrom,
    'note' => $attrNoteDeliveryTimeFrom,
    'class' => '',
    'source' => '',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => true,
    'required' => false,
    'user_defined' => true,
    'visible_on_front' => true,
    'used_in_product_listing' => true,
    'unique' => false,
    'is_configurable' => false,
    'used_for_promo_rules' => true
    ));
}

1

In date upgrade script 2 you have used below filter in product collection. i would suggest removing that.

->addStoreFilter(2);

And Second thing

Mage::getSingleton('catalog/product_action')->updateAttributes(array($product->getId()), $data, $storeId);

will only save a single attribute in one go.

instead of that use $product->save();

0

One thing that could be causing the issue is that you filter by the store id 2 and then save the attribute on the store id 0.

I am not sure how this could cause an issue but maybe it messes around because the product object is loaded and attached to store 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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