Basit bir ürün yapılandırılabilir ürünün bir parçasıdır ve daha sonra ana ürün alırsam nasıl, öğrenebilirim? Ben ürün listeleme için bu gerekir.
Sadece öğrendim:
$_product->loadParentProductIds();
$parentIds = $_product->getParentProductIds();
Diyelim ki sizin basit ürünün Ürün Kimliği var diyelim.
Bu basit ürünün tüm ana yapılandırılabilir ürün kimliğine almak için, aşağıdaki kodu kullanabilirsiniz: -
<?php
$_product = Mage::getModel('catalog/product')->load(YOUR_SIMPLE_PRODUCT_ID);
$parentIdArray = $_product->loadParentProductIds()
->getData('parent_product_ids');
if(!empty($parentIdArray)) {
// currently in the master configurable product
print_r($parentIdArray); // this prints all the parent product IDs using your simple product.
}
?>
Ben bu gitmen gerektiğini varsayalım.
After version 1.4.2.0 the loadParentProductIds() and getParentProductIds() methods are depricated. Dont ask me why. Personally I kind of liked those methods. So I've reintroduced them karşı my local Mage classes. This is how:
Copy
app/code/core/Mage/Catalog/Model/Product.php
karşı
app/code/local/Mage/Catalog/Model/Product.php
and change the loadParentProductIds() method, found around line 1349 karşı:
public function loadParentProductIds()
{
return $this->_getResource()->getParentProductIds($this);
}
This piece of code will query its resource for its parent product ids. For this karşı work we'll need karşı rewrite the getParentProductIds() method in the resource class.
Yani kopyalayın:
app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product.php
karşı
app/code/local/Mage/Catalog/Model/Resource/Eav/Mysql4/Product.php
Depricated getParentProductIds() yöntem bulmak. Hat 535 civarında bir yerde olmalı öncesi 1.4.2.0 koduyla üzerine yaz.:
public function getParentProductIds($object){
$childId = $object->getId();
$groupedProductsTable = $this->getTable('catalog/product_link');
$groupedLinkTypeId = Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED;
$configurableProductsTable = $this->getTable('catalog/product_super_link');
$groupedSelect = $this->_getReadAdapter()->select()
->from(array('g'=>$groupedProductsTable), 'g.product_id')
->where("g.linked_product_id = ?", $childId)
->where("link_type_id = ?", $groupedLinkTypeId);
$groupedIds = $this->_getReadAdapter()->fetchCol($groupedSelect);
$configurableSelect = $this->_getReadAdapter()->select()
->from(array('c'=>$configurableProductsTable), 'c.parent_id')
->where("c.product_id = ?", $childId);
$configurableIds = $this->_getReadAdapter()->fetchCol($configurableSelect);
return array_merge($groupedIds, $configurableIds);
}
Şimdi bir kez daha yapabilirsiniz:
$_product->loadParentProductIds()->getData('parent_product_ids');
Bu size yardımcı olur umarım!