Public Member Functions | |
update ($productId, $tierPrices) |
Definition at line 34 of file V2.php.
update | ( | $ | productId, | |
$ | tierPrices | |||
) |
Update tier prices of product
int|string | $productId | |
array | $tierPrices |
Reimplemented from Mage_Catalog_Model_Product_Attribute_Tierprice_Api.
Definition at line 43 of file V2.php.
00044 { 00045 Mage::log($tierPrices); 00046 $product = $this->_initProduct($productId); 00047 if (!is_array($tierPrices)) { 00048 $this->_fault('data_invalid', Mage::helper('catalog')->__('Invalid Tier Prices')); 00049 } 00050 00051 $updateValue = array(); 00052 00053 foreach ($tierPrices as $tierPrice) { 00054 if (!is_object($tierPrice) 00055 || !isset($tierPrice->qty) 00056 || !isset($tierPrice->price)) { 00057 $this->_fault('data_invalid', Mage::helper('catalog')->__('Invalid Tier Prices')); 00058 } 00059 00060 if (!isset($tierPrice->website) || $tierPrice->website == 'all') { 00061 $tierPrice->website = 0; 00062 } else { 00063 try { 00064 $tierPrice->website = Mage::app()->getWebsite($tierPrice->website)->getId(); 00065 } catch (Mage_Core_Exception $e) { 00066 $tierPrice->website = 0; 00067 } 00068 } 00069 00070 if (!isset($tierPrice->customer_group_id)) { 00071 $tierPrice->customer_group_id = 'all'; 00072 } 00073 00074 if ($tierPrice->customer_group_id == 'all') { 00075 $tierPrice->customer_group_id = Mage_Customer_Model_Group::CUST_GROUP_ALL; 00076 } 00077 00078 $updateValue[] = array( 00079 'website_id' => $tierPrice->website, 00080 'cust_group' => $tierPrice->customer_group_id, 00081 'price_qty' => $tierPrice->qty, 00082 'price' => $tierPrice->price 00083 ); 00084 00085 } 00086 00087 try { 00088 if (is_array($errors = $product->validate())) { 00089 $this->_fault('data_invalid', implode("\n", $errors)); 00090 } 00091 } catch (Mage_Core_Exception $e) { 00092 $this->_fault('data_invalid', $e->getMessage()); 00093 } 00094 00095 try { 00096 $product->setData(self::ATTRIBUTE_CODE ,$updateValue); 00097 $product->validate(); 00098 $product->save(); 00099 } catch (Mage_Core_Exception $e) { 00100 $this->_fault('not_updated', $e->getMessage()); 00101 } 00102 00103 return true; 00104 }