6

I'm using the internal Magento APIs to get the product data on a store view level. I only want to get the values that are on that store view level, not the global values that in inherits. But it returns all the values for all the fields, so I don't know which ones are the Global values and which are the Store View values. Is there a way to do this? If not with the APIs, then with SQL?

UPDATE: As requested, I've pasted the code we're using, below: --Mitch

const PRODUCT_TYPE_CODE = 'catalog_product';
​
private function getProductPage($storeId, $pageId, $productsOnPage)
{
    $productData = array();
​
    $entityTypeId = LegacyHelperFunctions::getEntityIdByTypeCode(self::PRODUCT_TYPE_CODE);
​
    Mage::app()->setCurrentStore($storeId);
​
    $storeLastPageId = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToFilter('entity_type_id', $entityTypeId)
        ->addAttributeToSelect('*')
        ->setPageSize($productsOnPage)
        ->getLastPageNumber();
​
    if ($storeLastPageId < $pageId) {
        return array();
    }
​
    $collection = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToFilter('entity_type_id', $entityTypeId)
        ->addAttributeToSelect('*')
        ->setPageSize($productsOnPage)
        ->setCurPage($pageId);
​
    foreach ($collection as $product) {
        $stockItem = Mage::getModel('cataloginventory/stock_item')
            ->loadByProduct($product->getEntityId());
​
        $usedAttributes = null;
        $configurableAttributesData = null;
        $usedSimpleProducts = null;
​
        if ($product->getTypeId() === 'configurable') {
            $usedAttributes = $product->getTypeInstance()
                ->getUsedProductAttributeIds();
​
            $configurableAttributesData = $product->getTypeInstance()
                ->getConfigurableAttributesAsArray();
​
​
            $usedSimpleProducts = Mage::getModel('catalog/product_type_configurable')
                ->getChildrenIds($product->getId());
        }
​
        $productAttributeData = CustomArrayHelpers::except(
            $product->getData(), array(
                'website_ids',
                'store_ids',
                'category_ids',
                'attribute_set_id',
                'type_id',
                'entity_type_id',
                'entity_id',
                'image',
                'small_image',
                'thumbnail'
            )
        );
​
        if (!isset($productData[$product->getId()])) {
            $productData[$product->getId()] = array(
                'store_ids' => $product->getStoreIds(),
                'website_ids' => $product->getStoreIds(),
                'category_ids' => $product->getCategoryIds(),
                'attribute_set_id' => $product->getAttributeSetId(),
                'product_id' => $product->getEntityId(),
                'type_id' => $product->getTypeId(),
                'data' => array(),
                'stock' => $stockItem->getData(),
                'relations' => array(
                    'cross_sell' => $product->getCrossSellLinkCollection()->toArray(),
                    'up_sell' => $product->getUpSellLinkCollection()->toArray(),
                    'related' => $product->getRelatedLinkCollection()->toArray(),
                    'associated' => array(
                        'simple_products' => $usedSimpleProducts,
                        'attributes' => $usedAttributes,
                        'attribute_data' => $configurableAttributesData
                    )
                ),
                'images' => array(
                    'base_image' => $product->getImageUrl(),
                    'small_image' => $product->getSmallImageUrl(),
                    'thumbnail_image' => $product->getThumbnailUrl(),
                    'media_gallery' => $product->getMediaGalleryImages()
                )
            );
        }
​
        $productData[$product->getId()]['data'][$storeId] = array_merge($productAttributeData, array(
                'image' => $product->getImageUrl(),
                'small_image' => $product->getSmallImageUrl(),
                'thumbnail' => $product->getThumbnailUrl())
        );
    }
​
    return $productData;
}
  • Could you post the code you're using to get the product data ? – Raphael at Digital Pianism Jun 17 '16 at 12:01
  • You will have to do it in SQL, the Magento API always uses the inheritance mechanism. Look up the values in catalog_product_entity_{varchar,int,decimal,price,datetime,gallery,text} with WHERE store_id=X – Fabian Schmengler Jun 17 '16 at 12:43
0

To me I think using Mage::app()->setCurrentStore($storeId); is not enough to retrieve store specific data.

I reckon you should update your collections code and add the following:

->addStoreFilter($storeId)
  • 1
    This won't help either to get only the overridden values and not the inherited values. – Fabian Schmengler Jun 17 '16 at 12:45

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.