Magento以编程方式添加层级价格,但使用自定义字段

I have a problem about add product tier price by code. I did some research that there is a magento API that could be used to add tier price. However, since I have customized our magento and add a new field to the tier price, which is "production time", I don't know how to add tier price via API anymore.

Here is the sample code

$proxy = new SoapClient(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'/api/soap/?wsdl');
$sessionId = $proxy->login('API user','API Key');
$tierPrices[] = array(
    'website'           => 'all',
    'customer_group_id' => 'all',
    'production_time    => $data[2],
    'qty'               => $data[3],
    'price'             => $data[4]
);
 try {
        $proxy->call($sessionId, 'product_tier_price.update', array($sku, $tierPrices));
    } catch (Exception $e) {
        $e->getMessage() . "
";
}

I will get an error says "invalid tier price".

Any idea why does it happen? or is there other ways to add tier prices?

Thank you.

Better than API where are not all the functions you can use standard Magento script, you only need to be placed anywhere in magento folder:

require("../../app/Mage.php");
Mage::init();

// Set an Admin Session
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(1);
$session = Mage::getSingleton('admin/session');
$session->setUser($userModel);
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());


foreach ($youritemlist as $item) {  


   $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$item);  

    if(is_object($product)) {              


                $product->setTierPrice($yourprice);  
                echo "..(set)..";


                      $product->save();                          

                       echo "..saved
";                                      

      }; // end testing of product exist              


}; // enf foreach

I have found that it's easiest to load the model that the API uses for Tiered Prices so that it can help you by validating your data for you.

$tierPrices = array();

$tierPrices[] = array(
    'customer_group_id' => 1,       // or 'all' or whatever your customer group ID is
    'qty'               => 1,       // Must be greater than 0
    'price'             => 5.99,    // Use an int here, don't currency format
    'website_id'        => 0        // or whatever website ID you need to set this to
);

// Set more tiered prices here if you'd like...

$tierPriceModel = Mage::getModel('catalog/product_attribute_tierprice_api');

// Assume 12345 is your product ID
$tierPriceModel->update(12345, $tierPrices);

Fo whose like me who were wondering why tier prices were not updated taking into account website_id this is because there is a mistake in @Tyler V. code, or api code has changed.

This is the correct way to format new tier prices :

$tierPrices[] = array(
    'customer_group_id' => 'all',     
    'qty'               => 1,       
    'price'             => 5.99,    
    'website'        => 0         
);

This is no longer website_id but website when you specify website into tier price array!