I need to export all products with prices from Magento 1.7.
For simple products this is no problem, but for configurable products I have this problem: The price exported is the price set for the associated simple product! As you know, Magento ignores this price and uses the price of the configurable product plus adjustments for the selected options.
I can get the price of the parent product, but how do I calculate the difference depending on the selected options?
My code looks something like this:
foreach($products as $p)
{
$price = $p->getPrice();
// I save it somewhere
// check if the item is sold in second shop
if (in_array($otherShopId, $p->getStoreIds()))
{
$otherConfProd = Mage::getModel('catalog/product')->setStoreId($otherShopId)->load($p->getId());
$otherPrice = $b2cConfProd->getPrice();
// I save it somewhere
unset($otherPrice);
}
if ($p->getTypeId() == "configurable"):
$_associatedProducts = $p->getTypeInstance()->getUsedProducts();
if (count($_associatedProducts))
{
foreach($_associatedProducts as $prod)
{
$p->getPrice(); //WRONG PRICE!!
// I save it somewhere
$size $prod->getAttributeText('size');
// I save it somewhere
if (in_array($otherShopId, $prod->getStoreIds()))
{
$otherProd = Mage::getModel('catalog/product')->setStoreId($otherShopId)->load($prod->getId());
$otherPrice = $otherProd->getPrice(); //WRONG PRICE!!
// I save it somewhere
unset($otherPrice);
$otherProd->clearInstance();
unset($otherProd);
}
}
if(isset($otherConfProd)) {
$otherConfProd->clearInstance();
unset($otherConfProd);
}
}
unset($_associatedProducts);
endif;
}