Magento 1.5.0.1/ 1.4.2.0 – Delete Tiered Pricing

Problem: Suddenly and Without Warning, I can’t Delete Magento Tiered Pricing via API

The failing code was written agains the (what I presume is called) version 1 of the SOAP kit for Magento. The returned error is “Invalid Tier Price“.

This code doesn’t work as of 1.4.2.0, and did not work in 1.5.0.1 to delete Tiered Pricing:

define( 'MAGENTO_WSDL_URL',
    "http://www.myMagentoStore.com/index.php/api/soap/?wsdl" );
/* Delete Tiered prices: */
try {
    $proxy = new SoapClient(MAGENTO_WSDL_URL);
    $sessionId = $proxy->login(USER, PASS);
 
    $killPrices="";
    $killPrices[] = array(
        'website'           => 'all',
        'customer_group_id' => 'all',
        'qty'               => '',
        'price'             => ''
    );
    print( "Killing tier price: "  . $sku . "\n" );
    $proxy->call($sessionId, 'product_tier_price.update',
            array($sku, $killPrices));
}   
catch( Exception $e ) { 
    print( "Tried killing tier price for $sku: " . $e->getMessage() . "\n" );
}

Solution

The solution works in (what I presume is called) version 2 of the SOAP kit for Magento. I mean, I don’t even remember how I found out there is a “version 2” of this thing, I stumbled across it somewhere. Anyway, using my own trusty WSDL-Dumper Gimme Gimme Thingie, I found the version 2 counterparts for manipulating Tiered Pricing: catalogProductAttributeTierPriceInfo and catalogProductAttributeTierPriceUpdate. And here’s what I ended up to get Delete Tiered Pricing to work!

This code does delete Tiered Pricing, in 1.4.2.0 and 1.5.0.1

define( 'MAGENTO_WSDL_URL_V2', "http://www.myMagentoStore.com/api/v2_soap?wsdl=1" );
/* Delete Tiered Prices using V2 API: */
try {
    $cli2 = new SoapClient(MAGENTO_WSDL_URL_V2);
    $sess2 = $cli2->login(USER, PASS);
 
    /* Just grabbing current info and dumping to stdout,
     * Important note: the 'sku' argument is a literal argument. It says that 
     * "value in $sku is the sku attribute for the product I'm looking for."     
     */
    $tp = $cli2->catalogProductAttributeTierPriceInfo($sess2,$sku,'sku');
    print_r($tp);
 
    $killPrices[] = array(
        'website'           => 'all',
        'customer_group_id' => 'all',
        'qty'               => '', 
        'price'             => ''
    );  
 
    /* Killing the pricing by updating with "empty tiers" (insert joke here)
     * Once again, the last argument 'sku' is a literal, describing the value
     * I'm passing in $sku as an SKU. It could be, for example a product ID.
     */
    $rc = $cli2->catalogProductAttributeTierPriceUpdate($sess2, $sku,
                   $killPrices, 'sku' );
 
    /* I'm printing the value returned in $rc, though I've never seen it be
     * anything other than 1.
     */
    echo "\t----->".$rc."<-------\n";
 
    /* After the kill, this should come back empty: */
    $tp2 = $cli2->catalogProductAttributeTierPriceInfo($sess2,$sku,'sku');
    print_r($tp2);
}
catch( Exception $e ) {
    print( "Tried killing tier price for $sku: " . $e->getMessage() . "\n" );
    print_r( $e ) ;
}