我刚刚安装了 Magento 扩展 Firegento German Setup,它工作正常。不幸的是,另一个扩展 SCP(简单可配置产品)现在显示了一些不良行为。由 SCP 为文章创建的“Price from”字段在安装 Firegento German Setup 后消失。再次卸载 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_ 的 price.php
*/
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);
}
}