扩展SCP(简单可配置产品)和Firegento德语设置之间的冲突

时间:2013-10-01 06:23:23

标签: php magento

我刚刚安装了Magento扩展程序Firegento German Setup,它运行正常。不幸的是,另一个扩展SCP(简单可配置产品)现在显示出一些不受欢迎的行为。安装Firegento德国设置后,“价格来自”字段 - 由SCP创建的文章 - 消失。当再次卸载Firegento时,SCP会像以前一样显示“Price from”字段。显然,SCP领域的“Price from”被Firegento覆盖。两个扩展都有自己的“price.php”,我想这两个文件存在冲突。有谁知道解决方案?请提前帮助,谢谢。 马里奥

扩展名为SCP Simple Configurable Products的price.php以下

public function _toHtml() {
    $htmlToInsertAfter = '<div class="price-box">';
    if ($this->getTemplate() == 'catalog/product/price.phtml') {
        $product = $this->getProduct();
        if (is_object($product) && $product->isConfigurable()) {
            $extraHtml = '<span class="label" id="configurable-price-from-'
            . $product->getId()
            . $this->getIdSuffix()
            . '"><span class="configurable-price-from-label">';
    if ($product->getMaxPossibleFinalPrice() != $product->getFinalPrice()) {
                $extraHtml .= $this->__('Price From:');
            }
            $extraHtml .= '</span></span>';
            $priceHtml = parent::_toHtml();
            #manually insert extra html needed by the extension into the normal price html
            return substr_replace($priceHtml, $extraHtml, strpos($priceHtml, $htmlToInsertAfter)+strlen($htmlToInsertAfter),0);
        }
    }
    return parent::_toHtml();
}

此处是扩展名Firegento _的

 */


public function _toHtml()

{
    $html = trim(parent::_toHtml());

    if (empty($html) || !Mage::getStoreConfigFlag('catalog/price/display_block_below_price')) {
        return $html;
    }

    if (!in_array($this->getTemplate(), $this->_tierPriceDefaultTemplates)) {
        $htmlObject = new Varien_Object();
        $htmlObject->setParentHtml($html);
        $htmlTemplate = $this->getLayout()->createBlock('core/template')
            ->setTemplate('germansetup/price_info.phtml')
            ->setFormattedTaxRate($this->getFormattedTaxRate())
            ->setIsIncludingTax($this->isIncludingTax())
            ->setIsIncludingShippingCosts($this->isIncludingShippingCosts())
            ->setIsShowShippingLink($this->isShowShippingLink())
            ->setIsShowWeightInfo($this->getIsShowWeightInfo())
            ->setFormattedWeight($this->getFormattedWeight())
            ->toHtml();
        $htmlObject->setHtml($htmlTemplate);

        $this->_addDeliveryTimeHtml($htmlObject);

        Mage::dispatchEvent('germansetup_after_product_price',
            array(
                'html_obj' => $htmlObject,
                'block' => $this,
            )
        );

        $html = $htmlObject->getPrefix();
        $html .= $htmlObject->getParentHtml();
        $html .= $htmlObject->getHtml();
        $html .= $htmlObject->getSuffix();
    }

    return $html;
}

/**
 * Add delivery time on category pages only
 *
 * @param $htmlObject
 */
protected function _addDeliveryTimeHtml($htmlObject)
{
    if (!Mage::getStoreConfigFlag('catalog/price/display_delivery_time_on_categories')) {
        return;
    }

    $pathInfo = Mage::app()->getRequest()->getPathInfo();
    if (strpos($pathInfo, 'catalog/category/view') !== false
        || strpos($pathInfo, 'catalogsearch/result') !== false) {
        if ($this->getProduct()->getDeliveryTime()) {
            $html = '<p class="delivery-time">';
            $html .= $this->__('Delivery Time') . ': ' . $this->getProduct()->getDeliveryTime();
            $html .= '</p>';
            $htmlObject->setSuffix($html);
        }
    }
}

/**
 * Read tax rate from current product.
 *
 * @return string
 */
public function getTaxRate()
{
    $taxRateKey = 'tax_rate_'.$this->getProduct()->getId();
    if (!$this->getData($taxRateKey)) {
        $this->setData($taxRateKey, $this->_loadTaxCalculationRate($this->getProduct()));
    }

    return $this->getData($taxRateKey);
}

/**
 * Retrieves formatted string of tax rate for user output
 *
 * @return string
 */
public function getFormattedTaxRate()
{
    if ($this->getTaxRate() === null
        || $this->getProduct()->getTypeId() == 'bundle'
    ) {
        return '';
    }

    $locale  = Mage::app()->getLocale()->getLocaleCode();
    $taxRate = Zend_Locale_Format::toFloat($this->getTaxRate(), array('locale' => $locale));

    return $this->__('%s%%', $taxRate);
}

/**
 * Returns whether or not the price contains taxes
 *
 * @return bool
 */
public function isIncludingTax()
{
    if (!$this->getData('is_including_tax')) {
        $this->setData('is_including_tax', Mage::getStoreConfig('tax/display/type'));
    }

    return $this->getData('is_including_tax');
}

/**
 * Returns whether or not the price contains taxes
 *
 * @return bool
 */
public function isIncludingShippingCosts()
{
    if (!$this->getData('is_including_shipping_costs')) {
        $this->setData(
            'is_including_shipping_costs',
            Mage::getStoreConfig('catalog/price/including_shipping_costs')
        );
    }

    return $this->getData('is_including_shipping_costs');
}

/**
 * Returns whether the shipping link needs to be shown
 * on the frontend or not.
 *
 * @return bool
 */
public function isShowShippingLink()
{
    $productTypeId = $this->getProduct()->getTypeId();
    $ignoreTypeIds = array('virtual', 'downloadable');
    if (in_array($productTypeId, $ignoreTypeIds)) {
        return false;
    }

    return true;
}

/**
 * Gets tax percents for current product
 *
 * @param  Mage_Catalog_Model_Product $product
 * @return string
 */
protected function _loadTaxCalculationRate(Mage_Catalog_Model_Product $product)
{
    $taxPercent = $product->getTaxPercent();
    if (is_null($taxPercent)) {
        $taxClassId = $product->getTaxClassId();
        if ($taxClassId) {
            $request    = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, null);
            $taxPercent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
        }
    }

    if ($taxPercent) {
        return $taxPercent;
    }

    return 0;
}

/**
 * Check if Shipping by Weight is active
 *
 * @return bool
 */
public function getIsShowWeightInfo()
{
    return Mage::getStoreConfigFlag('catalog/price/display_product_weight');
}

/**
 * Get formatted weight incl. unit
 *
 * @return string
 */
public function getFormattedWeight()
{
    return floatval($this->getProduct()->getWeight()) . ' ' . Mage::getStoreConfig('catalog/price/weight_unit');
}

/**
 * Translate block sentence
 *
 * @return string
 */
public function __()
{
    $args = func_get_args();
    $expr = new Mage_Core_Model_Translate_Expr(array_shift($args), 'Mage_Catalog');
    array_unshift($args, $expr);

    return Mage::app()->getTranslator()->translate($args);
}

}

1 个答案:

答案 0 :(得分:0)

我遇到了完全相同的问题并以这种方式解决了这个问题:

  1. 将firegento的price.php复制到您的本地文件夹

  2. 在下面添加此代码

        $htmlToInsertAfter = '<div class="price-box">';
    if ($this->getTemplate() == 'catalog/product/price.phtml') {
        $product = $this->getProduct();
        if (is_object($product) && $product->isConfigurable()) {
            $extraHtml = '<span class="label" id="configurable-price-from-'
            . $product->getId()
            . $this->getIdSuffix()
            . '"><span class="configurable-price-from-label">';
    
            if ($product->getMaxPossibleFinalPrice() != $product->getFinalPrice()) {
                $extraHtml .= $this->__('Price from:');
            }
            $extraHtml .= '</span></span>';
            #manually insert extra html needed by the extension into the normal price html
            $html = substr_replace($html, $extraHtml, strpos($html, $htmlToInsertAfter)+strlen($htmlToInsertAfter),0);
        }
    }
    
  3. 以下

    $html = trim(parent::_toHtml());
    

    在price.php。

    中的_toHtml()方法内

    这是简单可配置产品price.php的代码,稍作调整。

    希望有所帮助