1

バンドルされた商品の子オプション/商品がトランザクションメールで正しく並べ替えられないという問題があります。

この場合、製品モデルはオプションの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%確信しています。しかし、数時間の調査の後、私はそれを見つけることができませんでした。

これは機能します。以上です。

4

1 に答える 1

2

それについて行く1つの方法:

  • すべてをループし$items、ID(キーとして)と名前(値として)を使用して配列を作成します。これが$sortedPrdと呼ばれると仮定します。
  • 新しい配列の($ sortedPrd)値を(アルファベット順に)並べ替えます
  • ループして$sortedPrd、そのキーを使用して、特定の製品を$items

アップデート

バンドルオプション(サブ製品)の位置を取得するためのコードは次のとおりです。

$optionCollection = $_product->getTypeInstance(true)->getOptionsCollection($_product);
foreach ($optionCollection as $prdOptions){

  $position = $prdOptions->getPosition();
}

詳細については、この質問を参照してください:Magento:管理で使用されるすべてのデータに沿って製品をロードする方法

于 2013-01-02T20:56:02.973 に答える