バンドルされた商品の子オプション/商品がトランザクションメールで正しく並べ替えられないという問題があります。
この場合、製品モデルはオプションの1つであり、最初に表示する必要があるため、並べ替え順序は重要です。
template / bundle / email / order / items / order / default.phtmlには、製品の詳細を吐き出すためのビューロジックがあります。
<?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...
子商品の並べ替え順序は、通常どおり管理者で定義され、通常は商品ビュー、カート、チェックアウトなどに表示されますが、メールでの表示中に順序が変更されます。
奇妙なことに、順序もアルファベット順ではありません。実際、それは少し恣意的なようです-奇妙な...
とにかく$items
、意図したソート順に一致するように配列をソートするにはどうすればよいですか?
注=これは、admin-> catalog-> product-> bundleitems->positionで設定された値です。
アップデート
これが私の完成したヘルパーメソッドです:
/**
* @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;
}
}
そして、私はそれをtemplate / bundle / email / order / items / order / default.phtml(またはソートされたバンドルが必要な場所)で呼び出します:
<?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 );
?>
...これを行うための組み込みのメソッドがいくつかあり、おそらくもっとクリーンなものがあると1000%確信しています。しかし、数時間の調査の後、私はそれを見つけることができませんでした。
これは機能します。以上です。