Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Сопутствующие товары в корзине
 
Alexmac
Sr. Member
 
Total Posts:  223
Joined:  2011-05-08
 

Как можно блок с сопутствующими товарами вывести в корзину?
Читал много ответов на этот вопрос так и не нашел.

Нужно по идее в файле checkout.xml прописать

<reference name="right">
<block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
</reference>

а в cart.phtml вызвать <?php echo $this->getChildHtml('related_form') ?>

но не срабатывает

 
Magento Community Magento Community
Magento Community
Magento Community
 
mcdky
Sr. Member
 
Avatar
Total Posts:  140
Joined:  2011-09-29
 

попробуйте <?php echo $this->getChildHtml('catalog.product.related') ?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Alexmac
Sr. Member
 
Total Posts:  223
Joined:  2011-05-08
 
mcdky - 06 November 2012 12:58 AM

попробуйте <?php echo $this->getChildHtml('catalog.product.related') ?>

спасибо но не сравботало(

 
Magento Community Magento Community
Magento Community
Magento Community
 
Alexmac
Sr. Member
 
Total Posts:  223
Joined:  2011-05-08
 

Ответ:

в cart.phtml в нужном вам месте можете вставить:

<!-- Related products block START -->
<div class="related-products-holder">
<?php
$array_added_product = array();
$total_product= "";
$last_product= "";
?>

<?php foreach($this->getItems() as $_item):
$array_added_product[]=$_item->getProductId();?>
<?php endforeach ?>

<?php
//print_r($array_added_product);
$total_product=sizeof($array_added_product);
//echo "<br>".$total_product;
if($total_product > 0){
$last_product=$array_added_product[($total_product-1)];
}
?>

<?php
$nProducts = $total_product;
$_product = Mage::getModel('catalog/product')->load($total_product-1);
$ids = array();
while ((count($ids) < 5) && ($nProducts > 0)){
$nProducts --;
$last_product=$array_added_product[($nProducts)];
$_product1 = Mage::getModel('catalog/product')->load($last_product);

if (!$_product1->hasRelatedProductIds()) {
foreach ($_product1->getRelatedProducts() as $product) {
if (count($ids) < 5) $ids[] = $product->getId();
else break;
}
$_product->setRelatedProductIds($ids);
}
}
?>

<?php $product_per_row=5; //how many product show in a row ?>

<table width="100%" align="center" cellpadding="0" cellspacing="0" style="margin-bottom:10px; border:1px solid #dbdbdb;">
<tr>
<td width="100%" align="left" valign="middle" class="tdcolor" colspan="<?php echo $product_per_row; ?>">Related Items</td>
</tr>

<?php
$product_counter=0;
foreach ($_product->getData('related_product_ids') as $r_productid) {
$_product = Mage::getModel('catalog/product')->load($r_productid);
?>

<?php if(($product_counter%$product_per_row)==0){ ?>
<tr class="bg-related-products">
<?php } ?>

<td valign="top" style="padding:15px;" width="21%">
<div class="related-product-cart">
<a href="<?php echo $_product->getProductUrl() ?>” style="text-decoration:none;margin-left:30px;text-align:center;">
<img src="<? echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(50, 50); ?>” alt="<?php echo $this->htmlEscape($_product['name']); ?>” border="0" width="50" />
</a>
<a href="<?php echo $_product->getProductUrl() ?>” style="text-decoration:none; font-size:11px; color:#0076a3; font-weight:bold; text-align:left; “>
<br />
<?php
if (strlen($this->helper('catalog/output')->productAttribute($_product, $_product->getName(), 'name')) > 32) {echo substr($this->helper('catalog/output')->productAttribute($_product, $_product->getName(), 'name'),0,32)."...";}
else echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName(), 'name');
?>
</a>
<div style="font-size:11px; color:#6b6a6a; font-weight:bold; text-align:left;margin-top:7px;">
List:<?php $price_mine= (float) $_product->getPrice();
$price_mine= number_format($price_mine,2);
?>
<?php echo "$". $price_mine; ?>
</div>
<div style="font-size:11px; color:#ff5907; font-weight:bold; text-align:left;">
Our Price:<?php $final_price= (float) $_product->getFinalPrice();
$final_price= number_format($final_price,2);
?>
<?php echo "$". $final_price; ?>
</div>
<div style="margin-top:7px; text-align:left; font-size:11px !important;text-decoration:underline;color:#959595;">
<a href="<?php echo $_product->getProductUrl() ?>” title="more info">more info</a>
</div>
</div>
</td>
<?php
$product_counter++;
if(($product_counter%$product_per_row)==0){
?>
</tr>
<?php } ?>
<?php } ?>
</table>
</div>
<!-- Related products block END -->

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top