Mage_Catalog_Model_Product_Attribute_Tierprice_Api Class Reference

Inheritance diagram for Mage_Catalog_Model_Product_Attribute_Tierprice_Api:

Mage_Catalog_Model_Api_Resource Mage_Api_Model_Resource_Abstract Mage_Catalog_Model_Product_Attribute_Tierprice_Api_V2

List of all members.

Public Member Functions

 __construct ()
 info ($productId)
 update ($productId, $tierPrices)

Public Attributes

const ATTRIBUTE_CODE = 'tier_price'

Protected Member Functions

 _initProduct ($productId)


Detailed Description

Definition at line 34 of file Api.php.


Constructor & Destructor Documentation

__construct (  ) 

Definition at line 38 of file Api.php.

00039     {
00040         $this->_storeIdSessionField = 'product_store_id';
00041     }


Member Function Documentation

_initProduct ( productId  )  [protected]

Retrieve product

Parameters:
int $productId
string|int $store
Returns:
Mage_Catalog_Model_Product

Definition at line 137 of file Api.php.

00138     {
00139         $product = Mage::getModel('catalog/product')
00140                        ->setStoreId($this->_getStoreId());
00141 
00142         $idBySku = $product->getIdBySku($productId);
00143         if ($idBySku) {
00144             $productId = $idBySku;
00145         }
00146 
00147         $product->load($productId);
00148 
00149         /* @var $product Mage_Catalog_Model_Product */
00150 
00151         if (!$product->getId()) {
00152             $this->_fault('product_not_exists');
00153         }
00154 
00155         return $product;
00156     }

info ( productId  ) 

Definition at line 43 of file Api.php.

00044     {
00045         $product = $this->_initProduct($productId);
00046         $tierPrices = $product->getData(self::ATTRIBUTE_CODE);
00047 
00048         if (!is_array($tierPrices)) {
00049             return array();
00050         }
00051 
00052         $result = array();
00053 
00054         foreach ($tierPrices as $tierPrice) {
00055             $row = array();
00056             $row['customer_group_id'] = (empty($tierPrice['all_groups']) ? $tierPrice['cust_group'] : 'all' );
00057             $row['website']           = ($tierPrice['website_id'] ? Mage::app()->getWebsite($tierPrice['website_id'])->getCode() : 'all');
00058             $row['qty']               = $tierPrice['price_qty'];
00059             $row['price']             = $tierPrice['price'];
00060 
00061             $result[] = $row;
00062         }
00063 
00064         return $result;
00065     }

update ( productId,
tierPrices 
)

Reimplemented in Mage_Catalog_Model_Product_Attribute_Tierprice_Api_V2.

Definition at line 67 of file Api.php.

00068     {
00069         $product = $this->_initProduct($productId);
00070         if (!is_array($tierPrices)) {
00071             $this->_fault('data_invalid', Mage::helper('catalog')->__('Invalid Tier Prices'));
00072         }
00073 
00074         $updateValue = array();
00075 
00076         foreach ($tierPrices as $tierPrice) {
00077             if (!is_array($tierPrice)
00078                 || !isset($tierPrice['qty'])
00079                 || !isset($tierPrice['price'])) {
00080                 $this->_fault('data_invalid', Mage::helper('catalog')->__('Invalid Tier Prices'));
00081             }
00082 
00083             if (!isset($tierPrice['website']) || $tierPrice['website'] == 'all') {
00084                 $tierPrice['website'] = 0;
00085             } else {
00086                 try {
00087                     $tierPrice['website'] = Mage::app()->getWebsite($tierPrice['website'])->getId();
00088                 } catch (Mage_Core_Exception $e) {
00089                     $tierPrice['website'] = 0;
00090                 }
00091             }
00092 
00093             if (!isset($tierPrice['customer_group_id'])) {
00094                 $tierPrice['customer_group_id'] = 'all';
00095             }
00096 
00097             if ($tierPrice['customer_group_id'] == 'all') {
00098                 $tierPrice['customer_group_id'] = Mage_Customer_Model_Group::CUST_GROUP_ALL;
00099             }
00100 
00101             $updateValue[] = array(
00102                 'website_id' => $tierPrice['website'],
00103                 'cust_group' => $tierPrice['customer_group_id'],
00104                 'price_qty'  => $tierPrice['qty'],
00105                 'price'      => $tierPrice['price']
00106             );
00107 
00108         }
00109 
00110 
00111         try {
00112             if (is_array($errors = $product->validate())) {
00113                 $this->_fault('data_invalid', implode("\n", $errors));
00114             }
00115         } catch (Mage_Core_Exception $e) {
00116             $this->_fault('data_invalid', $e->getMessage());
00117         }
00118 
00119         try {
00120             $product->setData(self::ATTRIBUTE_CODE ,$updateValue);
00121             $product->validate();
00122             $product->save();
00123         } catch (Mage_Core_Exception $e) {
00124             $this->_fault('not_updated', $e->getMessage());
00125         }
00126 
00127         return true;
00128     }


Member Data Documentation

const ATTRIBUTE_CODE = 'tier_price'

Definition at line 36 of file Api.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:40 2009 for Magento by  doxygen 1.5.8