最も売れていない特別価格は、設定可能な製品ビュー ページに表示されます。

magento.stackexchange https://magento.stackexchange.com/questions/101507

質問

この構成可能な製品にアクセスしてください リンク

見ることができます: MRP : Rs. 9.00, below that Rs. 0.00 デフォルトでは

バックエンド値:価格 :0、特別価格:0

同じリンクで、上に「「ドロップダウン属性、選択してください

1)Blue, = >  MRP: Rs. 10.00, below that Rs 5.00

2)Light Pink => MRP: Rs. 9.00 below that Rs 4.00

3)choose an option => MRP: Rs. 9.00 ,below that 4.00

現在、オプション 3 は正常に機能しています。ただし、ページを更新すると バックエンドに入力された元の値が表示されます 特別価格で

価格の仕組み:

ページを更新すると、シンプルな商品の最低価格が表示されます。これで大丈夫です。

特別価格の仕組み

ページを更新すると、バックエンドに入力された値が表示されます。これは正しくありません。

私に必要なのは:

ページを更新すると、シンプルな商品の最低特別価格が表示されます

シンプルな製品の最低販売価格を表示するには、@alan によるこのリンクの回答に従いました。 Magento で構成可能な製品価格を単純な製品価格より優先する

<?php

#The methods in there have become a bit convoluted, so it could benefit from a tidy,
#...though the logic is not that simple any more.

class OrganicInternet_SimpleConfigurableProducts_Catalog_Model_Product_Type_Configurable_Price
    extends Mage_Catalog_Model_Product_Type_Configurable_Price
{
    #We don't want to show a separate 'minimal' price for configurable products.
    public function getMinimalPrice($product)
    {
        return $this->getPrice($product);
    }

    public function getMaxPossibleFinalPrice($product) {
        #Indexer calculates max_price, so if this value's been loaded, use it
        $price = $product->getMaxPrice();
        if ($price !== null) {
            return $price;
        }

        $childProduct = $this->getChildProductWithHighestPrice($product, "finalPrice");
        #If there aren't any salable child products we return the highest price
        #of all child products, including any ones not currently salable.

        if (!$childProduct) {
            $childProduct = $this->getChildProductWithHighestPrice($product, "finalPrice", false);
        }

        if ($childProduct) {
            return $childProduct->getFinalPrice();
        }
        return false;
    }

    #If there aren't any salable child products we return the lowest price
    #of all child products, including any ones not currently salable.
    public function getFinalPrice($qty=null, $product)
{
    //Start edit
    $selectedAttributes = array();
    if ($product->getCustomOption('attributes')) {
        $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
    }
    //End edit
    if (sizeof($selectedAttributes)) return $this->getSimpleProductPrice($qty, $product);

    if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
        return $product->getCalculatedFinalPrice();
    }

    $basePrice = $this->getBasePrice($product, $qty);
    $finalPrice = $basePrice;
    $product->setFinalPrice($finalPrice);
    Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product, 'qty' => $qty));
    $finalPrice = $product->getData('final_price');

    $finalPrice += $this->getTotalConfigurableItemsPrice($product, $finalPrice);
    $finalPrice += $this->_applyOptionsPrice($product, $qty, $basePrice) - $basePrice;
    $finalPrice = max(0, $finalPrice);

    $product->setFinalPrice($finalPrice);
    return $finalPrice;
}

public function getSimpleProductPrice($qty=null, $product)
    {
        $cfgId = $product->getId();
        $product->getTypeInstance(true)
            ->setStoreFilter($product->getStore(), $product);
        $attributes = $product->getTypeInstance(true)
            ->getConfigurableAttributes($product);
        $selectedAttributes = array();
        if ($product->getCustomOption('attributes')) {
            $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
        }
        $db = Mage::getSingleton('core/resource')->getConnection('core_read');
        $dbMeta = Mage::getSingleton('core/resource');
        $sql = <<<SQL
SELECT main_table.entity_id FROM {$dbMeta->getTableName('catalog/product')} `main_table` INNER JOIN
{$dbMeta->getTableName('catalog/product_super_link')} `sl` ON sl.parent_id = {$cfgId}
SQL;
        foreach($selectedAttributes as $attributeId => $optionId) {
            $alias = "a{$attributeId}";
            $sql .= ' INNER JOIN ' . $dbMeta->getTableName('catalog/product') . "_int" . " $alias ON $alias.entity_id = main_table.entity_id AND $alias.attribute_id = $attributeId AND $alias.value = $optionId AND $alias.entity_id = sl.product_id";
        }
        $id = $db->fetchOne($sql);
        return Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
    }

    public function getPrice($product)
    {
        #Just return indexed_price, if it's been fetched already
        #(which it will have been for collections, but not on product page)
        $price = $product->getIndexedPrice();
        if ($price !== null) {
            return $price;
        }

        $childProduct = $this->getChildProductWithLowestPrice($product, "finalPrice");
        #If there aren't any salable child products we return the lowest price
        #of all child products, including any ones not currently salable.
        if (!$childProduct) {
            $childProduct = $this->getChildProductWithLowestPrice($product, "finalPrice", false);
        }

        if ($childProduct) {
            return $childProduct->getPrice();
        }

        return false;
    }

    public function getChildProducts($product, $checkSalable=true)
    {
        static $childrenCache = array();
        $cacheKey = $product->getId() . ':' . $checkSalable;

        if (isset($childrenCache[$cacheKey])) {
            return $childrenCache[$cacheKey];
        }

        $childProducts = $product->getTypeInstance(true)->getUsedProductCollection($product);
        $childProducts->addAttributeToSelect(array('price', 'special_price', 'status', 'special_from_date', 'special_to_date'));

        if ($checkSalable) {
            $salableChildProducts = array();
            foreach($childProducts as $childProduct) {
                if($childProduct->isSalable()) {
                    $salableChildProducts[] = $childProduct;
                }
            }
            $childProducts = $salableChildProducts;
        }

        $childrenCache[$cacheKey] = $childProducts;
        return $childProducts;
    }

/*
    public function getLowestChildPrice($product, $priceType, $checkSalable=true)
    {
        $childProduct = $this->getChildProductWithLowestPrice($product, $priceType, $checkSalable);
        if ($childProduct) {
            if ($priceType == "finalPrice") {
                $childPrice = $childProduct->getFinalPrice();
            } else {
                $childPrice = $childProduct->getPrice();
            }
        } else {
            $childPrice = false;
        }
        return $childPrice;
    }
*/
    #Could no doubt add highest/lowest as param to save 2 near-identical functions
    public function getChildProductWithHighestPrice($product, $priceType, $checkSalable=true)
    {
        $childProducts = $this->getChildProducts($product, $checkSalable);
        if (count($childProducts) == 0) { #If config product has no children
            return false;
        }
        $maxPrice = 0;
        $maxProd = false;
        foreach($childProducts as $childProduct) {
            if ($priceType == "finalPrice") {
                $thisPrice = $childProduct->getFinalPrice();
            } else {
                $thisPrice = $childProduct->getPrice();
            }
            if($thisPrice > $maxPrice) {
                $maxPrice = $thisPrice;
                $maxProd = $childProduct;
            }
        }
        return $maxProd;
    }

    public function getChildProductWithLowestPrice($product, $priceType, $checkSalable=true)
    {
        $childProducts = $this->getChildProducts($product, $checkSalable);
        if (count($childProducts) == 0) { #If config product has no children
            return false;
        }
        $minPrice = PHP_INT_MAX;
        $minProd = false;
        foreach($childProducts as $childProduct) {
            if ($priceType == "finalPrice") {
                $thisPrice = $childProduct->getFinalPrice();
            } else {
                $thisPrice = $childProduct->getPrice();
            }
            if($thisPrice < $minPrice) {
                $minPrice = $thisPrice;
                $minProd = $childProduct;
            }
        }
        return $minProd;
    }

    //Force tier pricing to be empty for configurable products:
    public function getTierPrice($qty=null, $product)
    {
        return array();
    }
}
役に立ちましたか?

解決

構成可能な製品を作成する場合、単純な製品の価格は問題ではありません。これらの価格は完全に無視されます。したがって、価格が $29.99 の単純な製品 A と単純な製品 B ($39.99) を販売したい場合は、構成可能な製品を作成し、その価格を $29.99 に設定して、[関連製品] タブを開く必要があります。この構成可能な製品に関連付ける製品を追加します。それらを追加すると、オプションと価格差を含むスーパー製品属性構成という名前のブロックが表示されます。製品 A の価格を空のままにし、製品 B の価格フィールドに 10 (+$10) を入力すると、出来上がりです。シンプルな製品が異なれば、価格も異なります。

実際には、価格差の代わりに単純な製品価格を使用できる拡張機能がありますが、設定が少し難しいです。無料の拡張機能なので、ここにそのリンクを貼り付けることに誰も文句を言わないことを願っています。

https://github.com/organicinternet/magento-configurable-simple

または

問題が解決したらこれを試してください

<?php 
  if($_product->getTypeId() == "configurable"):
  $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
  $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
  foreach($simple_collection as $simple_product){
    echo $simple_product->getSku() . " - " . $simple_product->getName() . " - " . Mage::helper('core')->currency($simple_product->getPrice()) . "<br>";
}
endif;

他のヒント

これは実行可能ですが、多くの MOD が必要になります。説明のために、ここでは「コア」コードを直接参照し、カスタム モジュールの作成はユーザーに任せます。

商品詳細ページでは、子商品の価格情報は optionPrice という javascript オブジェクト

 var optionsPrice = new Product.OptionsPrice( .....

このオブジェクトは、次のデザインファイルによってページに書き込まれました design/frontend/base/default/template/catalog/product/view.phtml に追加します。

var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);

optionsPrice オブジェクトに書き込まれた情報は、関数「reloadPrice」で適切な価格情報を書き込むページを更新する configurable.js で使用されます。

特別価格も表示するには、次のことをお勧めします。

1) getJsonConfig 関数を変更する特別価格情報を optionsPrice に追加します。

2) configurable.js ファイルを変更してページを更新します。

configurable.js ファイルは、構成可能な製品ページで複製された価格ボックスのコピーである「価格クローン」を参照します。

開発を適切な方向に導くことを願っています。

<?php

#The methods in there have become a bit convoluted, so it could benefit from a tidy,
#...though the logic is not that simple any more.

class OrganicInternet_SimpleConfigurableProducts_Catalog_Model_Product_Type_Configurable_Price
    extends Mage_Catalog_Model_Product_Type_Configurable_Price
{
    #We don't want to show a separate 'minimal' price for configurable products.
    public function getMinimalPrice($product)
    {
        return $this->getPrice($product);
    }

    public function getMaxPossibleFinalPrice($product) {
        #Indexer calculates max_price, so if this value's been loaded, use it
        $price = $product->getMaxPrice();
        if ($price !== null) {
            return $price;
        }

        $childProduct = $this->getChildProductWithHighestPrice($product, "finalPrice");
        #If there aren't any salable child products we return the highest price
        #of all child products, including any ones not currently salable.

        if (!$childProduct) {
            $childProduct = $this->getChildProductWithHighestPrice($product, "finalPrice", false);
        }

        if ($childProduct) {
            return $childProduct->getFinalPrice();
        }
        return false;
    }

    #If there aren't any salable child products we return the lowest price
    #of all child products, including any ones not currently salable.
    public function getFinalPrice($qty=null, $product)
{
    //Start edit
    $selectedAttributes = array();
    if ($product->getCustomOption('attributes')) {
        $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
    }
    //End edit
    if (sizeof($selectedAttributes)) return $this->getSimpleProductPrice($qty, $product);

    if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
        return $product->getCalculatedFinalPrice();
    }

    $basePrice = $this->getBasePrice($product, $qty);
    $finalPrice = $basePrice;
    $product->setFinalPrice($finalPrice);
    Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product, 'qty' => $qty));
    $finalPrice = $product->getData('final_price');

    $finalPrice += $this->getTotalConfigurableItemsPrice($product, $finalPrice);
    $finalPrice += $this->_applyOptionsPrice($product, $qty, $basePrice) - $basePrice;
    $finalPrice = max(0, $finalPrice);

    $product->setFinalPrice($finalPrice);
    return $finalPrice;
}

public function getSimpleProductPrice($qty=null, $product)
    {
        $cfgId = $product->getId();
        $product->getTypeInstance(true)
            ->setStoreFilter($product->getStore(), $product);
        $attributes = $product->getTypeInstance(true)
            ->getConfigurableAttributes($product);
        $selectedAttributes = array();
        if ($product->getCustomOption('attributes')) {
            $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
        }
        $db = Mage::getSingleton('core/resource')->getConnection('core_read');
        $dbMeta = Mage::getSingleton('core/resource');
        $sql = <<<SQL
SELECT main_table.entity_id FROM {$dbMeta->getTableName('catalog/product')} `main_table` INNER JOIN
{$dbMeta->getTableName('catalog/product_super_link')} `sl` ON sl.parent_id = {$cfgId}
SQL;
        foreach($selectedAttributes as $attributeId => $optionId) {
            $alias = "a{$attributeId}";
            $sql .= ' INNER JOIN ' . $dbMeta->getTableName('catalog/product') . "_int" . " $alias ON $alias.entity_id = main_table.entity_id AND $alias.attribute_id = $attributeId AND $alias.value = $optionId AND $alias.entity_id = sl.product_id";
        }
        $id = $db->fetchOne($sql);
        return Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty);
    }

    public function getPrice($product)
    {
        #Just return indexed_price, if it's been fetched already
        #(which it will have been for collections, but not on product page)
        $price = $product->getIndexedPrice();
        if ($price !== null) {
            return $price;
        }

        $childProduct = $this->getChildProductWithLowestPrice($product, "finalPrice");
        #If there aren't any salable child products we return the lowest price
        #of all child products, including any ones not currently salable.
        if (!$childProduct) {
            $childProduct = $this->getChildProductWithLowestPrice($product, "finalPrice", false);
        }

        if ($childProduct) {
            return $childProduct->getPrice();
        }

        return false;
    }

    public function getChildProducts($product, $checkSalable=true)
    {
        static $childrenCache = array();
        $cacheKey = $product->getId() . ':' . $checkSalable;

        if (isset($childrenCache[$cacheKey])) {
            return $childrenCache[$cacheKey];
        }

        $childProducts = $product->getTypeInstance(true)->getUsedProductCollection($product);
        $childProducts->addAttributeToSelect(array('price', 'special_price', 'status', 'special_from_date', 'special_to_date'));

        if ($checkSalable) {
            $salableChildProducts = array();
            foreach($childProducts as $childProduct) {
                if($childProduct->isSalable()) {
                    $salableChildProducts[] = $childProduct;
                }
            }
            $childProducts = $salableChildProducts;
        }

        $childrenCache[$cacheKey] = $childProducts;
        return $childProducts;
    }

/*
    public function getLowestChildPrice($product, $priceType, $checkSalable=true)
    {
        $childProduct = $this->getChildProductWithLowestPrice($product, $priceType, $checkSalable);
        if ($childProduct) {
            if ($priceType == "finalPrice") {
                $childPrice = $childProduct->getFinalPrice();
            } else {
                $childPrice = $childProduct->getPrice();
            }
        } else {
            $childPrice = false;
        }
        return $childPrice;
    }
*/
    #Could no doubt add highest/lowest as param to save 2 near-identical functions
    public function getChildProductWithHighestPrice($product, $priceType, $checkSalable=true)
    {
        $childProducts = $this->getChildProducts($product, $checkSalable);
        if (count($childProducts) == 0) { #If config product has no children
            return false;
        }
        $maxPrice = 0;
        $maxProd = false;
        foreach($childProducts as $childProduct) {
            if ($priceType == "finalPrice") {
                $thisPrice = $childProduct->getFinalPrice();
            } else {
                $thisPrice = $childProduct->getPrice();
            }
            if($thisPrice > $maxPrice) {
                $maxPrice = $thisPrice;
                $maxProd = $childProduct;
            }
        }
        return $maxProd;
    }

    public function getChildProductWithLowestPrice($product, $priceType, $checkSalable=true)
    {
        $childProducts = $this->getChildProducts($product, $checkSalable);
        if (count($childProducts) == 0) { #If config product has no children
            return false;
        }
        $minPrice = PHP_INT_MAX;
        $minProd = false;
        foreach($childProducts as $childProduct) {
            if ($priceType == "finalPrice") {
                $thisPrice = $childProduct->getFinalPrice();
            } else {
                $thisPrice = $childProduct->getPrice();
            }
            if($thisPrice < $minPrice) {
                $minPrice = $thisPrice;
                $minProd = $childProduct;
            }
        }
        return $minProd;
    }


    public function getChildProductWithLowestSpecialPrice($product, $priceType, $checkSalable=true)
    {
        $childProducts = $this->getChildProducts($product, $checkSalable);
        if (count($childProducts) == 0) { #If config product has no children
            return false;
        }
        $minPrice = PHP_INT_MAX;
        $minProd = false;
        foreach($childProducts as $childProduct) {
            if ($priceType == "finalPrice") {
                $thisPrice = $childProduct->getFinalPrice();
            } else {
                $thisPrice = $childProduct->getPrice();
            }
            if($thisPrice < $minPrice) {
                $minPrice = $thisPrice;
                $minProd = $childProduct;
            }
        }
        return $minProd;
    }

    //Force tier pricing to be empty for configurable products:
    public function getTierPrice($qty=null, $product)
    {
        return array();
    }
}
.
ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top