Magento를 배우고 있으며 이벤트와 관찰자를 배우기 시작했습니다. 금액의 백분율은 관리 제품 영역에서 설정하여 제품에 추가됩니다. 잘 작동하지만 할인 된 가격은 제품 페이지에만 표시됩니다. 아무도 나에게 Magento를 통해 가격을 어떻게 바꿀 수 있는지 제안 해 줄 수 있습니까? 나는 쇼핑 카트에 가야 가격을 변경 의미, 주문 등 아래 옵저버를 사용하여 모든 페이지의 가격 변경 Magento
내가 사용할 수있는 방법<?xml version="1.0"?>
<config>
<global>
<models>
<xyzcatalog>
<class>Xyz_Catalog_Model</class>
</xyzcatalog>
</models>
<events>
<catalog_product_get_final_price>
<observers>
<xyz_catalog_price_observer>
<type>singleton</type>
<class>Xyz_Catalog_Model_Price_Observer</class>
<method>apply_discount_percent</method>
</xyz_catalog_price_observer>
</observers>
</catalog_product_get_final_price>
</events>
</global>
</config>
은 알려 주시기 바랍니다 관찰자
<?php
class Xyz_Catalog_Model_Price_Observer
{
public function __construct()
{
}
/**
* Applies the special price percentage discount
* @param Varien_Event_Observer $observer
* @return Xyz_Catalog_Model_Price_Observer
*/
public function apply_discount_percent($observer)
{
$event = $observer->getEvent();
$product = $event->getProduct();
// process percentage discounts only for simple products
if ($product->getSuperProduct() && $product->getSuperProduct()->isConfigurable()) {
} else {
$percentDiscount = $product->getPercentDiscount();
if (is_numeric($percentDiscount)) {
$today = floor(time()/86400)*86400;
$from = floor(strtotime($product->getSpecialFromDate())/86400)*86400;
$to = floor(strtotime($product->getSpecialToDate())/86400)*86400;
if ($product->getSpecialFromDate() && $today < $from) {
} elseif ($product->getSpecialToDate() && $today > $to) {
} else {
$price = $product->getPrice();
$finalPriceNow = $product->getData('final_price');
$specialPrice = $price - $price * $percentDiscount/100;
// if special price is negative - negate the discount - this may be a mistake in data
if ($specialPrice < 0)
$specialPrice = $finalPriceNow;
if ($specialPrice < $finalPriceNow)
$product->setFinalPrice($specialPrice); // set the product final price
}
}
}
return $this;
}
}
config.xml의 코드입니다 Magento 전역의 새로운 할인 가격. 감사합니다
이 문제를 해결하기 위해 내 답변이 도움이 되셨나요? 그것을 고쳤습니까? –
@ dushyant 내가 문제를 해결할 수 있다고 생각하는 경우 –