Magento捆绑产品:子选项排序顺序问题
我遇到一个问题,捆绑产品的子选项/产品在事务性电子邮件中排序不正确 在这种情况下,排序顺序很重要,因为产品型号是选项之一,需要首先显示 在template/bundle/email/order/items/order/default.phtml中,我们拥有显示产品详细信息的视图逻辑:Magento捆绑产品:子选项排序顺序问题,magento,bundle,product,transactional,Magento,Bundle,Product,Transactional,我遇到一个问题,捆绑产品的子选项/产品在事务性电子邮件中排序不正确 在这种情况下,排序顺序很重要,因为产品型号是选项之一,需要首先显示 在template/bundle/email/order/items/order/default.phtml中,我们拥有显示产品详细信息的视图逻辑: <?php $_item = $this->getItem() ?> <?php $_order=$this->getOrder() ?> <?php $parentIt
<?php $_item = $this->getItem() ?>
<?php $_order=$this->getOrder() ?>
<?php $parentItem = $this->getItem() ?>
<?php $items = array_merge(array($parentItem), $parentItem->getChildrenItems()); ?>
<?php foreach ($items as $_item): ?>
// etc...
我在template/bundle/email/order/items/order/default.phtml中调用它(或者在需要排序包的地方):
。。。我有1000%的把握,有一些内置的方法可以做到这一点,也许还有一些更干净的方法。但是经过几个小时的搜寻,我找不到它
这很有效。仅此而已。一种方法是:
- 循环遍历所有
,并创建一个包含id(作为键)和名称(作为值)的数组,假设它被称为$sortedpred$items
- 对新数组的($sortedPrd)值进行排序(按字母顺序)
- 循环浏览
,并使用it's键从$sortedpred
$items
查看此问题了解更多信息:Yeah=我认为这可能是一条不错的路线。。。你知道我怎样才能获得儿童产品的“排序”价值吗?它是EAV吗?确实可以使用它来获取所有捆绑包选项:$\u product->getTypeInstance(true)->getOptionsCollection($\u product);您可以通过调用$options->getPosition()循环遍历每一个选项并获取位置;(或者可以使用var_dump($option->getData())查看所有选项)或者使用usort;进行排序)@Bosworth99感谢您在上面分享您的实现,这将帮助未来有问题的人
/**
* @codepool Local
* @package Namespace
* @module Module
*/
class Namespace_Module_Helper_Product_Sort extends Mage_Core_Helper_Abstract
{
/*
* @param $item : bundle product
* @return array
*/
public function sortBundleChildrenByPosition( $item )
{
$sorted = array();
$sorted[] = $item;
//Mage::log('Namespace_Module_Helper_Product_Bundle::sortChildrenByPosition /n'.print_r($item->debug(), true));
// grab the product (bundle parent)
$_product = $item->getProduct();
// grab child order items
$_children = $item->getChildrenItems();
// grab sort order for options
$optionCollection = $_product->getTypeInstance(true)->getOptionsCollection($_product);
// iterate over options, comparing title / label, if they match, toss into return array
foreach ($optionCollection as $option){
//Mage::log('$option:'.print_r($option->debug(), true));
$title = $option['default_title'];
foreach ($_children as $child){
$prodOption = $child->getProductOptions();
$bundleSelectionAttributes = unserialize($prodOption['bundle_selection_attributes']);
//Mage::log('$_children=>$child:product_options[bundle_selection_attributes]'.print_r($bundleSelectionAttributes, true));
if ($bundleSelectionAttributes['option_label'] == $title){
//Mage::log('$bundleSelectionAttributes[option_label] == '.$title.'. $sorted[] ='. print_r($child->debug(), true) );
$sorted[] = $child;
continue;
}
}
}
return $sorted;
}
}
<?php
$_item = $this->getItem();
$_order=$this->getOrder();
$parentItem = $this->getItem();
//$items = array_merge( array($parentItem), $parentItem->getChildrenItems());
$items = $this->helper('Namespace_Module/Product_Sort')->sortBundleChildrenByPosition( $_item );
?>
$optionCollection = $_product->getTypeInstance(true)->getOptionsCollection($_product);
foreach ($optionCollection as $prdOptions){
$position = $prdOptions->getPosition();
}