15
Nov

Using product attributes and configuration for calculation

  • Font size: Larger Smaller
  • Hits: 1715
  • Print

We have already shown you how to use your product custom fields to use the selected values at your calculator. In some cases, you may also want to use some other data regarding the actual product, like its configuration or its attributes.

For this purpouse, you need to add some lines at the configuration section 'php code before execution'. There you will recover all needed information from your product, in order to use it afterwards at your calculator in code and/or, send it to your excel sheet to continue with price calculation.

You only need to add:
$_modelproduct = Mage::getModel('catalog/product');
//Get product object
$_product = $_modelproduct->load($idProduct);

Now you have all your product data available, and you can get the value of any attribute:

//Recovering value of attribute called 'att1'
$att1=$_product->getAtt1();

Once you have your attribute value, you can use it at your next calculations at the code, or, send it to your excel sheet, so you will use it the same way you do for the custom fields, mapping its name at the first column. To send one value to the excel sheet, just type:
$params['att1']=$att1;

The whole code:
$_modelproduct = Mage::getModel('catalog/product');
//Get product object
$_product = $_modelproduct->load($idProduct);
//Recovering value of attribute called 'att1'
$att1=$_product->getAtt1();
$params['att1']=$att1;

At the excel sheet you can now write att1 at the first column and its value will be placed at 'B' column, same it happens with the custom fields.

Having recovered the product, you have also access to all the inner configuration parameters, it's very unlikely you will need to use any of them in your price calculator, but it's worth to take a look just in case:

// get Product's name
$_product->getName();
//get product's short description
$_product->getShortDescription();
//get Product's Long Description
$_product->getDescription();
//get Product's Regular Price
$_product->getPrice();
//get Product's Special price
$_product->getSpecialPrice();
//get Product's Url
$_product->getProductUrl();
//get Product's image Url
$_product->getImageUrl();

This means if you need to pass your product short description to your excel sheet, you'd write:
$_modelproduct = Mage::getModel('catalog/product');
//Get product object
$_product = $_modelproduct->load($idProduct);
//get product's short description
$shortdesc=$_product->getShortDescription();
//pass short description to excel sheet
$params['ShortDesc']=$shortdesc;

Following this example at the excel sheet you will be able to place ShortDesc (or whatever name you want to give to your parameter) at column A to get the short description at column B. You can handle rest of the parameters same way in case you need it for your price calculator.

In fact using this code section you'd able to recover any parameter from your Magento database, regarding store, customer, groups data... (even from an external source!). If you have any specific need about this, you can use our helpdesk system and we'll help you to recover any data to use at your calculations.

Last modified on
Trackback URL for this blog entry.

Lo que nuestros clientes opinan de nosotros