Magento在php脚本中使用final_price

Question regarding Magento: I need to make a PHP script where I grab the ‘final_price’ (the price after applying category and shopping cart price rules), of a product for a particular customer group, and use this in a calculation to populate a specific attribute with the outcome.

Example:

  • Product ‘X’ has a ‘price’ attribute set at $100 in Magento
  • After applying the category price rules for customer group ‘CG’, the final_price for product ‘X’ for this specific customer group is $10
  • Next, I populate the (self-created) attribute ‘price grabbed’ = (final_price for product group CG) * ( 1.56 ) = $15.60
  • The script needs to make the above calculation for each of the products

I have been searching all over the place how to use final_price for a specific customer group in a PHP script in Magento CE 1.7.2, but can’t find a proper method. The idea is to call the script nightly through cron.

I have full access to Magento, the dedicated (Centos 5, LAMP) server, and all databases. The database has 15000 products.

Does anybody have an idea how I best do this?

Regards, Jan

What is used in the product to determine the customer group is

Mage::getSingleton('customer/session')->getCustomerGroupId();

So what you want to do is to ensure that you set the customer group id in the customer session before calling the getFinalPrice() method on the catalog/product model.