2

私はグーグルで見つけたいくつかのアイデアを試しましたが、数日間誰も私のために働きませんでした。最後に、カスタム拡張機能で、magentoのバンドル製品の「可能な最小価格」と「可能な最大価格」を表示する方法を見つけました。

    $_product_id            = YOUR_BUNDLE_PRODUCT_ID;

    // highest possible price for this bundle product
    $return_type            = 'max'; // because I used this in a helper method

    // lowest possible price for this bundle product
    // $return_type         = 'min';

    $model_catalog_product  = Mage::getModel('catalog/product'); // getting product model
    $_product               = $model_catalog_product->load( $_product_id );

    $TypeInstance           = $_product->getTypeInstance(true);
    $Selections             = $TypeInstance->getSelectionsCollection($OptionIds, $_product );
    $Options                = $TypeInstance->getOptionsByIds($OptionIds, $_product);
    $bundleOptions          = $Options->appendSelections($Selections, true);

    $minmax_pricevalue      = 0; // to sum them up from 0

    foreach ($bundleOptions as $bundleOption) {
        if ($bundleOption->getSelections()) {

            $bundleSelections       = $bundleOption->getSelections();

            $pricevalues_array  = array();
            foreach ($bundleSelections as $bundleSelection) {

                $pricevalues_array[] = $bundleSelection->getPrice();

            }
                if ( $return_type == 'max' ) {
                rsort($pricevalues_array); // high to low
                } else {
                sort($pricevalues_array);   // low to high
                }

            // sum up the highest possible or lowest possible price
            $minmax_pricevalue += $pricevalues_array[0];


        }
    }

    // echo $minmax_pricevalue;
    echo ''.Mage::helper('core')->currency($minmax_pricevalue, true, false).'';

より良い方法とより短い方法がある場合は、ここに投稿してください。関係者全員に感謝します!

その背景には、カスタム拡張機能を作成し、そのような構成の「可能な最小価格」と「可能な最大価格」も表示したかったのです。Magento-セットアップは次のとおりです。ネイティブの「バンドル製品」いくつかの「バンドルアイテムオプション」が私の「バンドル製品」に接続しました。各「バンドルオプション」には、価格の異なる複数のシンプルな製品が含まれています。それがここでのポイントだったと思います。

すべてが誰かを助けることを願っています-そのようなものを共有するのが大好きです:-)

4

3 に答える 3

9

Magentoには、その目的のための組み込み関数があります。

Mage::getModel('bundle/product_price')->getTotalPrices($_product,'min',1);
于 2015-02-05T15:22:32.000 に答える
5

ここでも、最終的な作業コードは次のとおりです。

$_product_id            = YOUR_BUNDLE_PRODUCT_ID;

// highest possible price for this bundle product
$return_type            = 'max'; // because I used this in a helper method

// lowest possible price for this bundle product
// $return_type         = 'min';

$model_catalog_product  = Mage::getModel('catalog/product'); // getting product model
$_product               = $model_catalog_product->load( $_product_id );

$TypeInstance           = $_product->getTypeInstance(true);
$Selections             = $TypeInstance->getSelectionsCollection($OptionIds, $_product );
$Options                = $TypeInstance->getOptionsByIds($OptionIds, $_product);
$bundleOptions          = $Options->appendSelections($Selections, true);

$minmax_pricevalue  = 0; // to sum them up from 0

foreach ($bundleOptions as $bundleOption) {
    if ($bundleOption->getSelections()) {


        $bundleSelections       = $bundleOption->getSelections();

        $pricevalues_array  = array();
        foreach ($bundleSelections as $bundleSelection) {

            $pricevalues_array[] = $bundleSelection->getPrice();

        }
            if ( $return_type == 'max' ) {
            rsort($pricevalues_array); // high to low
            } else {
            sort($pricevalues_array);   // low to high
            }

        // sum up the highest possible or lowest possible price
        $minmax_pricevalue += $pricevalues_array[0];


    }
}

// echo $minmax_pricevalue;
echo ''.Mage::helper('core')->currency($minmax_pricevalue, true, false).'';
于 2013-03-05T13:43:09.837 に答える
0

私はしばらく前に同様の問題を抱えていて、これを思いついた(バンドルされた製品コレクションを入手するためのInchooのブログの助けを借りて)。メインに関連付けられているすべてのバンドル製品をproduct_idアレイにロードします。配列を並べ替えることで、下部に最小値を取得し、最後に最大値を取得し$bundled_prices[0]ますarray_slice($bundled_prices, -1, 1, false)

    $product_id = YOUR_PRODUCT_ID;

    $bundled_product = new Mage_Catalog_Model_Product();
    $bundled_product->load($product_id);
    $selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
            $bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product
    );
    $bundled_items = array();
    foreach($selectionCollection as $option) { 
        if ($option->getPrice()!="0.0000"){                 
            $bundled_prices[]=$option->getPrice();
        }
    }

    sort($bundled_prices);

    $min_price=$bundled_prices[0];
    $max_price_tmp=array_slice($bundled_prices, -1, 1, false);
    $max_price=$max_price_tmp[0];

    echo "Min: " . $min_price . '<br>'; 
    echo "Max: " . $max_price;
于 2013-03-01T19:08:00.027 に答える