Magento getData () does not return a value

I have an attribute cdn_image_namethat is great for about 90,000 products. Recently, content editors reported that there are about three products that do not contain images. I highlighted the problem for the Magento getData () method.

This is the same code for the source.

$cdnImageName = $product->getData('cdn_image_name');

I also tried:

$cdnImageName = $product->getCdnImageName();
$cdnImageName = $product->getAttributeText('cdn_image_name');

In the Magento admin interface, I see a field filled with the correct value. I checked the DB, it also matters in place. It just returns "null" with any of the ways I tried.

Note: there are no typo problems, I checked the "n" times, it works for almost all products, but several.

+3
source share
4 answers

SQL, Magento:

// Create read and write connections to the database
    $resource  = Mage::getSingleton('core/resource');
    $connRead  = $resource->getConnection('core_read');

    // find out attribute id of cdn_image_name from the Magento database
    $attributeId = 123;

    $sqlCdnImageName = "SELECT `cpet`.`value`
            FROM `catalog_product_entity` `cpe`
            INNER JOIN `catalog_product_entity_text` `cpet`
            ON `cpe`.`entity_id` = `cpet`.`entity_id`
            WHERE `cpet`.`attribute_id` = $attributeId
            AND `cpe`.`entity_id` = " . $product->getId() . ";";

     $cdnImageName = $connRead->fetchOne($sqlCdnImageName);
+1

, 'used in product listing' 'no'. " ".

+3

if you use a custom attribute you can use it as

$cdnImageName = Mage::getResourceModel('catalog/product')->getAttributeRawValue($product_new->getData("entity_id"), "cdn_image_name", $storeID);


$product_new->getData("entity_id") = your product id

EDIT

Also check

$_item = $this->getProduct()->getId();
$_resource = $this->getProduct()->getResource();
$optionValue = $_resource->getAttributeRawValue($_item, 'cdn_image_name', Mage::app()->getStore());
echo $optionvalue;

hope this works for you.

+2
source

You can try this

$cdnImageName = Mage::getResourceModel('catalog/product')->getAttributeRawValue($product->getId(), 'cdn_image_name');

thank

0
source

All Articles