参加を使用してグリッドで製品名とSKUを入手してください
-
13-12-2019 - |
質問
これは私のコード
です$vendorTableName = Mage::getSingleton('core/resource')->getTableName('marketplace/vendor');
$vendorproductsTableName = Mage::getSingleton('core/resource')->getTableName('marketplace/vendorpro');
$productsTableName = Mage::getSingleton('core/resource')->getTableName('catalog/product');
$collection = Mage::getModel("marketplace/vendorpro")->getCollection();
$collection->getSelect()
->joinLeft(array('ce1' => $vendorTableName), 'ce1.vendor_id=main_table.vendor_id', array('vendor_name','vendor_contact_email'));
$collection->getSelect()
->joinLeft(
array('prod' => 'catalog_product_entity'),
'prod.entity_id = main_table.mageproduct_id',
array('sku')
)
->joinLeft(
array('cpev' => 'catalog_product_entity_varchar'),
'cpev.entity_id=main_table.mageproduct_id',
array('name' => 'value')
);
.
私は正しいデータを取得していません私はデータベースに2つのエントリしか持っていませんが、2以上のエントリが返されますか?
解決
$vendorTableName = Mage::getSingleton('core/resource')->getTableName('marketplace/vendor');
$vendorproductsTableName = Mage::getSingleton('core/resource')->getTableName('marketplace/vendorpro');
$productsTableName = Mage::getSingleton('core/resource')->getTableName('catalog/product');
$collection = Mage::getModel("marketplace/vendorpro")->getCollection();
$collection->getSelect()
->joinLeft(array('ce1' => $vendorTableName), 'ce1.vendor_id=main_table.vendor_id', array('vendor_name','vendor_contact_email'));
$entityTypeId = Mage::getModel('eav/entity')
->setType('catalog_product')
->getTypeId();
$prodNameAttrId = Mage::getModel('eav/entity_attribute')
->loadByCode($entityTypeId, 'name')
->getAttributeId();
$collection->getSelect()
->joinLeft(
array('prod' => 'catalog_product_entity'),
'prod.entity_id = main_table.mageproduct_id',
array('sku')
)
->joinLeft(
array('cpev' => 'catalog_product_entity_varchar'),
'cpev.entity_id=prod.entity_id AND cpev.attribute_id='.$prodNameAttrId.'',
array('name' => 'value')
);
.
これを使用すると、適切なSKUと製品名を取得できます。
私のために働いています。
所属していません magento.stackexchange