2016-07-28 62 views
0

Ich habe dieses Skript geschrieben, um alle meine Produktdaten zu exportieren. Es funktioniert bis zum <admin> Knoten. Es scheint, dass es ein Problem gibt, die Bezeichnung der Attribute zu erhalten.Alle Attribute des Produkts exportieren

<?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> 

Antwort

0

In der Tat ist die Ursache des Problems Anruf, um ein Etikett zu erhalten. Einige Attribute sind am Frontend nicht sichtbar, deshalb können Sie keine Shop-Labels für sie erhalten. Getter

$attribute->getIsVisibleOnFront() 

ist hilfreich, um festzustellen, ob is_visible_on_front Eigenschaft festgelegt ist.

Ich bin nicht sicher, was der Zweck Ihres Imports ist und ob Sie unsichtbare Attribute einschließen müssen oder nicht. Methode

$attribute->getFrontendLabel() 

kann verwendet werden, um einen Attributwert zu erhalten, wie Sie es in Admin Panel -> Attribute verwalten Seite sehen. Bei einigen Attributen (ich gehe von der Tabelle catalog_product_entity aus) ist es jedoch immer noch leer.