我正在使用Magento C.E 1.7。我需要向客户发送订单确认电子邮件,包括相关产品的图片和追加销售产品 >购买的产品。
如何在 magento 中执行此操作?
答案 0 :(得分:2)
在email / order / items.phtml中添加相关产品的代码
<?php
$productId = $_item->getProduct()->getId(); //for order emails
$_product = Mage::getModel('catalog/product')->load($productId);
$related_product_collection = $_product->getRelatedProductCollection();
$related_product_collection->AddStoreFilter();
foreach($related_product_collection as $pdt)
{
$pdt_id=$pdt->getId();
$model_rel = Mage::getModel('catalog/product'); //getting product model
$_product_rel = $model_rel->load($pdt_id); //getting product object for particular product id
$rel_name= $_product_rel->getName();
$rel_price= number_format($_product_rel->getPrice(),2);
?>
<a href='<?php echo $_product_rel->getProductUrl();?>'><img src="<?php echo Mage::getModel('catalog/product_media_config')
->getMediaUrl($_product_rel->getSmallImage()); ?>"
width="120" height="120" alt="<?php echo $_product_rel->getName() ?>" /> </a>
<?php
}
?>
使用此
获取加售产品系列$upsell_product_collection = $_product->getUpSellProductCollection();
答案 1 :(得分:0)
在这里,我可以为您提供一些可在订单商品中使用的框架代码
当您发送电子邮件订单确认邮件时,您可以从订单ID或订单对象获取订单产品。
像这样。 $collection = Mage::getResourceModel('sales/order_item_collection')->addFieldToFilter('order_id',array
('eq'=>$order->getId()));
foreach($collection as $item){
if(!$item->getParent_item_id()){
$order_product = $item->getId();
}
}?>
从上面的代码中您可以获取客户订购的产品ID,您可以获得其他详细信息,如相关产品和追加销售产品,如下所示
$related = $order_product->getRelatedProductCollection()
->addAttributeToSelect('required_options')
->addAttributeToSort('position', Varien_Db_Select::SQL_ASC)
->addStoreFilter();
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {//if you want to exclude the products in the cart
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($related,
Mage::getSingleton('checkout/session')->getQuoteId()
);
$this->_addProductAttributesAndPrices($related);
}
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($related);
$related->load();
升级
$upsells = $product->getUpSellProductCollection()
->addAttributeToSort('position', Varien_Db_Select::SQL_ASC)
->addStoreFilter()
;
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {//if you want to exclude the products in the cart
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($upsells,
Mage::getSingleton('checkout/session')->getQuoteId()
);
$this->_addProductAttributesAndPrices($upsells);
}
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($upsells);
//$upsells->setPageSize(10);//uncomment if you want to get only the first 10 items.
$upsells->load();
但请先检查加载时间,否则可能需要一段时间才能清除此过程。
希望这对您有所帮助。