I want to update some tier prices of a product based on a calculation I run. Basically it is printing costs, depending on a price per page, compared to some fixed prices.
I am using the following code to retrieve the old tier prices, do my calculations and replace some prices with the new price:
# price for digital printing: 0,066 Euro/per page
define('PPP', 0.066);
# $id is set outside of this, it's a valid product ID
$product = Mage::getModel("catalog/product")->load($id);
$data = $product->getData();
$_tierPrices = Mage::getResourceModel('catalog/product_attribute_backend_tierprice')->loadPriceData($id, Mage::app()->getWebsite()->getId());
$dpp = $data['page_count'] * PPP;
$_tierPricesNew = array();
foreach ($_tierPrices as $price) {
if ($price['price'] > $dpp) {
$price['price'] = $dpp;
}
$price['website'] = '0';
$price['customer_group_id'] = '0';
$_tierPricesNew[] = $price;
}
echo '<pre>';
print_r($_tierPricesNew);
The result of this, the content of $_tierPricesNew
, looks fine to me:
Array
(
[0] => Array
(
[price_id] => 2342
[website_id] => 0
[all_groups] => 1
[cust_group] => 0
[price] => 26.4
[price_qty] => 1.0000
[website] => 0
[customer_group_id] => 0
)
[1] => Array
(
[price_id] => 2343
[website_id] => 0
[all_groups] => 1
[cust_group] => 0
[price] => 26.4
[price_qty] => 5.0000
[website] => 0
[customer_group_id] => 0
)
[...]
I am not sure about the additional parameters "website" and "customer_group_id" but they will probably not hurt if present.
When trying to update the prices I run this code:
$soap = new SoapClient('https://magento.host/api/v2_soap/?wsdl=1');
$session = $soap->login('my_user', 'api_key');
$res = $soap->catalogProductAttributeTierPriceUpdate($session, $id, $price);
$soap->endSession($session);
This is basically the example from the documentation.
And while I can obtain a session ID, so login seems to work, but the result of $res
is always empty.
Any ideas why this happens? Or how I can debug this?