yılında: o phtml dosya türüne Mage_Catalog_Block_Product_View_Type_Grouped
ait olduğu
<?php
$_associatedProducts = $this->getAssociatedProducts();
, gidebiliriz:
/magento/app/design/frontend/base/default/template/catalog/product/view/type/grouped.phtml
Onların bu kullandığını göreceksiniz
/magento/app/code/core/Mage/Catalog/Block/Product/View/Type/Grouped.php
ve bakın Ben,
<?php
if ($product->getTypeId() == 'grouped'){
// how do I now get associated products of $product?
$associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
}
tamamen kodunuzu optimize etmek olsaydı:
<?php
$this->getProduct()->getTypeInstance(true)->getAssociatedProducts($this->getProduct());
yüzden güvenle ürün nesnesi döndüren $this->getProduct()
varsayabiliriz ve böylece gibi $product
değişken ile değiştirin: Mage_Catalog_Block_Product_View_Type_Grouped::getAssociatedProducts()
yapar d bu gibi yazmak':
<?php
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter('type_id', array('eq' => 'grouped'));
foreach ($products as $product) {
$associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
// Do something with $associatedProducts
}
sayesinde bu işe gidebilir ... Tüm ürünler üzerinde yinelemek istiyorum ve ilişkili ürünler üzerinde yinelenen gruplandırılırsa - sadece gruplanmış ürünle ilişkili ürünler değil, yalnızca tüm ürünleri istiyorum. 'Optimize' kodunuz normal tek ürünler içermez, doğru muyum? – Owen
Doğru, yalnızca gruplandırılmış ürünlerden oluşan bir koleksiyon elde ederdi. Kullanmak istediğiniz şey $ product-> isGrouped(). Tüm ürünlerden oluşan koleksiyonunuz ile birlikte kullanın: foreach ($ ürün olarak $ ürün) {if ($ product-> isGrouped()) {/ * İlgili ürün koleksiyonunu alın * /}} –