Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Magento中获得捆绑包默认选择的特价_Php_Magento_Bundle - Fatal编程技术网

Php 在Magento中获得捆绑包默认选择的特价

Php 在Magento中获得捆绑包默认选择的特价,php,magento,bundle,Php,Magento,Bundle,所以我一直在努力让它工作,但是运气不好,而且我在网上找不到任何东西来解决这个问题。现在,我有一段代码可以更改捆绑产品下拉选择中的定价,以显示差异价格而不是绝对价格,这样您就可以看到默认选择和其他选项之间的价格差异: File: app/code/local/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php public function getSelectionTitlePrice($_selection, $inclu

所以我一直在努力让它工作,但是运气不好,而且我在网上找不到任何东西来解决这个问题。现在,我有一段代码可以更改捆绑产品下拉选择中的定价,以显示差异价格而不是绝对价格,这样您就可以看到默认选择和其他选项之间的价格差异:

File: app/code/local/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php

public function getSelectionTitlePrice($_selection, $includeContainer = true)
{
$defaultPrice = 0.00;
$_product = $this->getProduct();


$_mbmo = new Mage_Bundle_Model_Option();
$_mbmo->load($_selection->getProductId());
$_default = $_mbmo->getDefaultSelection();
if (gettype($this->getOption()->getDefaultSelection())==object){
$defaultPrice=$this->getOption()->getDefaultSelection()->getFinalPrice();

}

$price = $_product->getPriceModel()->getSelectionFinalPrice($_product, $_selection, 1);

if ($price == $defaultPrice)
{
    return $_selection->getName();
}
else
{
    $sign = ($price < $defaultPrice) ?  '-' : '+';
    $diff = ($price < $defaultPrice) ? $defaultPrice - $price : $price - $defaultPrice;
    return $_selection->getName() . ' &nbsp; ' .
        ($includeContainer ? '<span class="price-notice">':'') . $sign .
        $this->formatPriceString($diff, $includeContainer) . ($includeContainer ? '</span>':'');
}
}
文件:app/code/local/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php
公共函数getSelectionTitlePrice($\u selection,$includeContainer=true)
{
$defaultPrice=0.00;
$\u product=$this->getProduct();
$\u mbmo=新图像束\u模型\u选项();
$\u mbmo->load($\u selection->getProductId());
$\u default=$\u mbmo->getDefaultSelection();
if(gettype($this->getOption()->getDefaultSelection())==对象){
$defaultPrice=$this->getOption()->getDefaultSelection()->getFinalPrice();
}
$price=$\u product->getPriceModel()->getSelectionFinalPrice($\u product,$\u selection,1);
如果($price==$defaultPrice)
{
返回$_selection->getName();
}
其他的
{
$sign=($price<$defaultPrice)?“-”:“+”;
$diff=($price<$defaultPrice)?$defaultPrice-$price:$price-$defaultPrice;
返回$\u selection->getName()。
($includeContainer?“”):$sign。
$this->formatPriceString($diff,$includeContainer)。($includeContainer?“”:“”);
}
}
代码通过getSelectionFinalPrice()为下拉菜单中的其他选项成功获取最终价格,但对于默认选择,getFinalPrice()不起作用(它只提供正常价格)。在特价折扣应用后,我如何更改它以给我价格?我尝试过其他一些函数,比如getSpecialPrice(),但似乎什么都不起作用


谢谢

经过多次修补,我自己能够解决这个问题

基本上,我检查是否有特殊的价格百分比,然后将其应用于默认价格。这是一个解决办法,因为如果有特殊百分比,产品模型中的所有价格信息(最终价格等)都不准确

public function getSelectionTitlePrice($_selection, $includeContainer = true)
{
$defaultPrice = 0.00;
$_product = $this->getProduct();
$_specialpricepercent = ($this->getProduct()->getSpecialPrice()) / 100;

if (gettype($this->getOption()->getDefaultSelection())==object){

if (isset($_specialpricepercent) && $_specialpricepercent > 0){

$defaultPricePreSpecial=$this->getOption()->getDefaultSelection()->getPrice();
$defaultPrice=$defaultPricePreSpecial * $_specialpricepercent;

}
else {

$defaultPrice=$this->getOption()->getDefaultSelection()->getPrice();
}
}

$price = $_product->getPriceModel()->getSelectionFinalPrice($_product, $_selection, 1);

if ($price == $defaultPrice)
{
    return $_selection->getName();
}
else
{
    $sign = ($price < $defaultPrice) ?  '-' : '+';
    $diff = ($price < $defaultPrice) ? $defaultPrice - $price : $price - $defaultPrice;
    return $_selection->getName() . ' &nbsp; ' .
        ($includeContainer ? '<span class="price-notice">':'') . $sign .
        $this->formatPriceString($diff, $includeContainer) . ($includeContainer ? '</span>':'');
}
}
公共函数getSelectionTitlePrice($\u selection,$includeContainer=true)
{
$defaultPrice=0.00;
$\u product=$this->getProduct();
$\u specialpricepercent=($this->getProduct()->getSpecialPrice())/100;
if(gettype($this->getOption()->getDefaultSelection())==对象){
如果(isset($特殊价格百分比)和&$特殊价格百分比>0){
$defaultPricePreSpecial=$this->getOption()->getDefaultSelection()->getPrice();
$defaultPrice=$defaultPricePreSpecial*$\u specialpricepercent;
}
否则{
$defaultPrice=$this->getOption()->getDefaultSelection()->getPrice();
}
}
$price=$\u product->getPriceModel()->getSelectionFinalPrice($\u product,$\u selection,1);
如果($price==$defaultPrice)
{
返回$_selection->getName();
}
其他的
{
$sign=($price<$defaultPrice)?“-”:“+”;
$diff=($price<$defaultPrice)?$defaultPrice-$price:$price-$defaultPrice;
返回$\u selection->getName()。
($includeContainer?“”):$sign。
$this->formatPriceString($diff,$includeContainer)。($includeContainer?“”:“”);
}
}
希望这有助于解决同一问题的人