I've integrated a function that generates a custom feed for Criteo.
All works fine except the product price, i can get the product price and the special price, but i can't get the final price (selling price that depends if the special price is active or if there are catalog rules applied on the product)
This is my code
<?php
define('SAVE_FEED_LOCATION','criteo.txt');
set_time_limit(1800);
require_once 'app/Mage.php';
Mage::app('default');
try{
$handle = fopen(SAVE_FEED_LOCATION, 'w');
$heading = array('id','name','producturl','bigimage','smallimage','description','price','retailprice','stock');
$feed_line=implode("|", $heading)."\r\n";
fwrite($handle, $feed_line);
$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToFilter('status', 1);
$products->addAttributeToFilter('visibility', 4);
$products->addAttributeToSelect('*');
$prodIds=$products->getAllIds();
$product = Mage::getModel('catalog/product');
$counter_test = 0;
foreach($prodIds as $productId) {
if (++$counter_test < 30000){
$product->load($productId);
$product_data = array();
$product_data['sku'] = $product->getSku();
$title_temp = $product->getName();
if (strlen($title_temp) > 70){
$title_temp = str_replace("Supply", "", $title_temp);
$title_temp = str_replace(" ", " ", $title_temp);
}
$product_data['title'] = $title_temp;
$product_data['Deeplink'] = "http://www.test.com/".$product->getUrlPath();
$product_data['image_big'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getBigImage();
$product_data['image_small'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getSmallImage();
$descriptionFull = $product->getShortDescription();
preg_match('/<h2>(.*?)<\/h2>/', $descriptionFull, $matches);
$descriptionHtml = strip_tags($matches[1]);
$product_data['description'] = substr(iconv("UTF-8","UTF-8//IGNORE",$descriptionHtml), 0, 500);
//******************************************
//***********PRODUCT PRICE *****************
//******************************************
// Selling price
$product_data['price'] = number_format((float)$product->getFinalPrice(), 2, '.', '');
// Original price
$product_data['retailprice'] = number_format((float)$product->getPrice(), 2, '.', '');
//******************************************
//*********** /PRODUCT PRICE *****************
//******************************************
//
if($product->getIsInStock())
{
//in stock!
$product_data['stock'] = "true";
}
else
{
//not in stock!
$product_data['stock'] = "false";
}
foreach($product_data as $k=>$val){
$bad=array('"',"\r\n","\n","\r","\t");
$good=array(""," "," "," ","");
$product_data[$k] = str_replace($bad,$good,$val);
}
echo $product_prezzo . " prezzo ";
$feed_line = implode("|", $product_data)."\r\n";
fwrite($handle, $feed_line);
fflush($handle);
}
}
fclose($handle);
}
catch(Exception $e){
die($e->getMessage());
}
GetFinalPrice() doesn't work, it gives me the price of the first product (even if special) for all product... example:
final price product 1 = 19,00 (ok, and if there is a special price gives me special price, but no rules are applyed!!)
final price product 2 = 19,00 (wrong is the price of product 1!)
final price product 3 = 19,00 (wrong is the price of product 1!)
final price product ... = 19,00 (wrong is the price of product 1!)
I've tried this solution but doesn't work (no price is given)
$product_data['price'] = Mage::getModel('catalogrule/rule')->calcProductPriceRule($product, $product->getFinalPrice());
Thanks a lot!