fak*_*ken 18 catalog magento e-commerce
我正在开发一个脚本(Magento外部,而不是模块),旨在输出所有可用产品的文本列表,价格和其他一些属性.但是,目录价格规则似乎不适用于产品价格.如果我使用以下任何一项:
$_product->getPrice()
$_product->getFinalPrice()
Run Code Online (Sandbox Code Playgroud)
我得到正常价格(没有适用规则).
如果我使用:
$_product->getSpecialPrice()
Run Code Online (Sandbox Code Playgroud)
除非产品实际上在产品本身中插入了特殊价格(即特殊价格与目录规则无关),否则我将为空.
我也试过了
Mage::getModel('catalogrule/rule')->calcProductPriceRule($product,$product->getPrice())
Run Code Online (Sandbox Code Playgroud)
正如Fabian Blechschmidt给出的答案中所建议的那样,但有趣的是,只有当产品受到任何目录规则的影响时,它才会返回正常价格,否则返回null.
在StackOverflow和Magento论坛中有一个类似的问题,但是提供的答案(即插入下面的代码)对我来说不起作用(返回的价格保持不变).
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_FRONTEND,Mage_Core_Model_App_Area::PART_EVENTS);
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何实现这一目标?
我正在使用Magento 1.6.2.0.提前致谢.
Fab*_*idt 20
谢谢你,我找到了一个新网站:http: //www.catgento.com/magento-useful-functions-cheatsheet/
他们提到:
Mage::getModel('catalogrule/rule')->calcProductPriceRule($product,$product->getPrice())
Run Code Online (Sandbox Code Playgroud)
HTH
fak*_*ken 12
我发现了这个问题.折扣价格在商店前端显示Ok.问题是我正在为Magento开发一个"外部"脚本(因此不是Magento模块),例如:
<?php
set_time_limit(0);
ignore_user_abort();
error_reporting(E_ALL^E_NOTICE);
header("Content-Type: text/plain; charset=utf-8");
require_once "app/Mage.php";
// Get default store code
$default_store = Mage::app()->getStore();
...
Run Code Online (Sandbox Code Playgroud)
为了使一切正常工作,似乎必须遵循正确的Magento引导程序,并将所有内容开发为模块.我的脚本非常简单,我认为没有必要编写一个完整的模块.换句话说,Magento中的所有东西都应该是一个模块.
总之,使用模块方法,所有方法都按预期工作:
$_product->getPrice()
$_product->getFinalPrice()
$_product->getSpecialPrice()
Run Code Online (Sandbox Code Playgroud)
谢谢大家的意见.
aug*_*yer 12
这有助于我解决这个问题:http://www.magentocommerce.com/boards/viewthread/176883/ .Jernej的解决方案似乎是合理的,但它不处理通过使用"停止处理"覆盖其他规则的规则,因此可以应用多个规则.
$original_price = $_product->getPrice();
$store_id = 1; // Use the default store
$discounted_price = Mage::getResourceModel('catalogrule/rule')->getRulePrice(
Mage::app()->getLocale()->storeTimeStamp($store_id),
Mage::app()->getStore($store_id)->getWebsiteId(),
Mage::getSingleton('customer/session')->getCustomerGroupId(),
$_product->getId());
// if the product isn't discounted then default back to the original price
if ($discounted_price===false) {
$discounted_price=$original_price;
}
Run Code Online (Sandbox Code Playgroud)
小智 11
由于目录价格规则在很大程度上取决于时间,存储和访问客户,因此您需要在应用其价格规则检索产品最终价格时设置这些参数.
因此,在您的情况下,请确保提供的产品与所需的商店和客户组ID一起传递,可以将其设置为:
Mage::getModel('catalogrule/rule')->calcProductPriceRule($product->setStoreId('STORE_ID')->setCustomerGroupId('CUSTOMER_GROUP_ID'),$product->getPrice())
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
57030 次 |
| 最近记录: |