2016-07-28 7 views
0

私はこのスクリプトを書いて、私のすべての製品データをエクスポートしています。それは<admin>の結び目まで働いています。属性のラベルを取得するのに問題があるようです。製品のすべての属性をエクスポート

<?php $productCollection = Mage::getModel('catalog/product')->getCollection(); ?> 
<?php echo '<?xml version="1.0" encoding="utf-8"?>'.PHP_EOL; ?> 
<import> 
    <?php if (!empty($productCollection)): ?> 
     <?php /** @var Mage_Catalog_Model_Product $product */ ?> 
     <?php foreach ($productCollection as $product): ?> 
      <product> 
       <?php $websiteIds = $product->getWebsiteIds(); ?> 
       <?php if (!empty($websiteIds)): ?> 
        <websites> 
         <?php foreach ($websiteIds as $websiteId): ?> 
          <website> 
           <?php $website = Mage::getModel('core/website')->load($websiteId); ?> 
           <code><?php echo $website->getName(); ?></code> 
           <?php $storeIds = $website->getStoreIds(); ?> 
           <?php if(!empty($storeIds)): ?> 
            <store_views> 
             <?php foreach ($storeIds as $storeId): ?> 
              <?php $store = Mage::getModel('core/store')->load($storeId); ?> 
              <code><?php echo $store->getName(); ?></code> 
             <?php endforeach; ?> 
            </store_views> 
           <?php endif; ?> 
          </website> 
         <?php endforeach; ?> 
        </websites> 
       <?php endif; ?> 
       <?php $categoryIds = $product->getCategoryIds(); ?> 
       <?php if (!empty($categoryIds)): ?> 
        <categories> 
         <?php foreach ($categoryIds as $categoryId): ?> 
          <id><?php echo $categoryId; ?></id> 
         <?php endforeach; ?> 
        </categories> 
       <?php endif; ?> 
       <admin> 
        <?php $attributes = $product->getAttributes(); ?> 
        <?php if (!empty($attributes)): ?> 
         <?php foreach ($attributes as $attribute): ?> 
          <attribute> 
           <name><?php echo $attribute->getStoreLabel($product); ?></name> 
           <value><?php echo $attribute->getFrontend()->getValue($product); ?></value> 
          </attribute> 
         <?php endforeach; ?> 
        <?php endif; ?> 
       </admin> 
       <?php if (!empty($storeIds)): ?> 
        <?php foreach ($storeIds as $storeId): ?> 
         <store_view> 
          <?php $store = Mage::getModel('core/store')->load($storeId); ?> 
          <code><?php echo $store->getName(); ?></code> 
          <?php Mage::app()->setCurrentStore($storeId); ?> 
          <?php $attributes = $product->getAttributes(); ?> 
          <?php if (!empty($attributes)): ?> 
           <attributes> 
            <?php foreach ($attributes as $attribute): ?> 
             <attribute> 
              <name><?php echo $attribute->getStoreLabel($product); ?></name> 
              <value><?php echo $attribute->getFrontend()->getValue($product); ?></value> 
             </attribute> 
            <?php endforeach; ?> 
           </attributes> 
          <?php endif; ?> 
         </store_view> 
        <?php endforeach; ?> 
       <?php endif; ?> 
      </product> 
     <?php endforeach; ?> 
    <?php endif; ?> 
</import> 

答えて

0

実際、問題の原因はラベルを取得することです。一部の属性はフロントエンドでは表示されないため、ストアラベルを取得できません。 Getter

$attribute->getIsVisibleOnFront() 

is_visible_on_frontプロパティが設定されているかどうかを判断するのに役立ちます。

インポートの目的は何か、また目に見えない属性を含める必要があるかどうかはわかりません。方法

$attribute->getFrontendLabel() 

を使用すると、管理パネル - >属性の管理ページで属性値をどのように表示するかを知ることができます。しかし、いくつかの属性(私はテーブルcatalog_product_entityから仮定します)ではまだ空です。

関連する問題