00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Catalog_Model_Product_Attribute_Tierprice_Api_V2 extends Mage_Catalog_Model_Product_Attribute_Tierprice_Api
00035 {
00036
00037
00038
00039
00040
00041
00042
00043 public function update($productId, $tierPrices)
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 }
00105 }