Mage_Catalog_Model_Product_Api Class Reference

Inheritance diagram for Mage_Catalog_Model_Product_Api:

Mage_Catalog_Model_Api_Resource Mage_Api_Model_Resource_Abstract Mage_Catalog_Model_Product_Api_V2

List of all members.

Public Member Functions

 __construct ()
 items ($filters=null, $store=null)
 info ($productId, $store=null, $attributes=null)
 create ($type, $set, $sku, $productData)
 update ($productId, $productData=array(), $store=null)
 setSpecialPrice ($productId, $specialPrice=null, $fromDate=null, $toDate=null, $store=null)
 getSpecialPrice ($productId, $store=null)
 delete ($productId)

Protected Member Functions

 _prepareDataForSave ($product, $productData)

Protected Attributes

 $_filtersMap


Detailed Description

Definition at line 34 of file Api.php.


Constructor & Destructor Documentation

__construct (  ) 

Definition at line 42 of file Api.php.

00043     {
00044         $this->_storeIdSessionField = 'product_store_id';
00045         $this->_ignoredAttributeTypes[] = 'gallery';
00046         $this->_ignoredAttributeTypes[] = 'media_image';
00047     }


Member Function Documentation

_prepareDataForSave ( product,
productData 
) [protected]

Set additional data before product saved

Parameters:
Mage_Catalog_Model_Product $product
array $productData
Returns:
object

Reimplemented in Mage_Catalog_Model_Product_Api_V2.

Definition at line 234 of file Api.php.

00235     {
00236         if (isset($productData['categories']) && is_array($productData['categories'])) {
00237             $product->setCategoryIds($productData['categories']);
00238         }
00239 
00240         if (isset($productData['websites']) && is_array($productData['websites'])) {
00241             foreach ($productData['websites'] as &$website) {
00242                 if (is_string($website)) {
00243                     try {
00244                         $website = Mage::app()->getWebsite($website)->getId();
00245                     } catch (Exception $e) { }
00246                 }
00247             }
00248             $product->setWebsiteIds($productData['websites']);
00249         }
00250 
00251         if (isset($productData['stock_data']) && is_array($productData['stock_data'])) {
00252             $product->setStockData($productData['stock_data']);
00253         }
00254     }

create ( type,
set,
sku,
productData 
)

Create new product.

Parameters:
string $type
int $set
array $productData
Returns:
int

Reimplemented in Mage_Catalog_Model_Product_Api_V2.

Definition at line 136 of file Api.php.

00137     {
00138         if (!$type || !$set || !$sku) {
00139             $this->_fault('data_invalid');
00140         }
00141 
00142         $product = Mage::getModel('catalog/product');
00143         /* @var $product Mage_Catalog_Model_Product */
00144         $product->setStoreId($this->_getStoreId($store))
00145             ->setAttributeSetId($set)
00146             ->setTypeId($type)
00147             ->setSku($sku);
00148 
00149         if (isset($productData['website_ids']) && is_array($productData['website_ids'])) {
00150             $product->setWebsiteIds($productData['website_ids']);
00151         }
00152 
00153         foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
00154             if ($this->_isAllowedAttribute($attribute)
00155                 && isset($productData[$attribute->getAttributeCode()])) {
00156                 $product->setData(
00157                     $attribute->getAttributeCode(),
00158                     $productData[$attribute->getAttributeCode()]
00159                 );
00160             }
00161         }
00162 
00163         $this->_prepareDataForSave($product, $productData);
00164 
00165         if (is_array($errors = $product->validate())) {
00166             $this->_fault('data_invalid', implode("\n", $errors));
00167         }
00168 
00169         try {
00170             $product->save();
00171         } catch (Mage_Core_Exception $e) {
00172             $this->_fault('data_invalid', $e->getMessage());
00173         }
00174 
00175         return $product->getId();
00176     }

delete ( productId  ) 

Delete product

Parameters:
int|string $productId
Returns:
boolean

Definition at line 293 of file Api.php.

00294     {
00295         $product = $this->_getProduct($productId);
00296 
00297         if (!$product->getId()) {
00298             $this->_fault('not_exists');
00299         }
00300 
00301         try {
00302             $product->delete();
00303         } catch (Mage_Core_Exception $e) {
00304             $this->_fault('not_deleted', $e->getMessage());
00305         }
00306 
00307         return true;
00308     }

getSpecialPrice ( productId,
store = null 
)

Retrieve product special price

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

Reimplemented in Mage_Catalog_Model_Product_Api_V2.

Definition at line 282 of file Api.php.

00283     {
00284         return $this->info($productId, $store, array('special_price', 'special_from_date', 'special_to_date'));
00285     }

info ( productId,
store = null,
attributes = null 
)

Retrieve product info

Parameters:
int|string $productId
string|int $store
array $attributes
Returns:
array

Reimplemented in Mage_Catalog_Model_Product_Api_V2.

Definition at line 101 of file Api.php.

00102     {
00103         $product = $this->_getProduct($productId, $store);
00104 
00105         if (!$product->getId()) {
00106             $this->_fault('not_exists');
00107         }
00108 
00109         $result = array( // Basic product data
00110             'product_id' => $product->getId(),
00111             'sku'        => $product->getSku(),
00112             'set'        => $product->getAttributeSetId(),
00113             'type'       => $product->getTypeId(),
00114             'categories' => $product->getCategoryIds(),
00115             'websites'   => $product->getWebsiteIds()
00116         );
00117 
00118         foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
00119             if ($this->_isAllowedAttribute($attribute, $attributes)) {
00120                 $result[$attribute->getAttributeCode()] = $product->getData(
00121                                                                 $attribute->getAttributeCode());
00122             }
00123         }
00124 
00125         return $result;
00126     }

items ( filters = null,
store = null 
)

Retrieve list of products with basic info (id, sku, type, set, name)

Parameters:
array $filters
string|int $store
Returns:
array

Reimplemented in Mage_Catalog_Model_Product_Api_V2.

Definition at line 56 of file Api.php.

00057     {
00058         $collection = Mage::getModel('catalog/product')->getCollection()
00059             ->setStoreId($this->_getStoreId($store))
00060             ->addAttributeToSelect('name');
00061 
00062         if (is_array($filters)) {
00063             try {
00064                 foreach ($filters as $field => $value) {
00065                     if (isset($this->_filtersMap[$field])) {
00066                         $field = $this->_filtersMap[$field];
00067                     }
00068 
00069                     $collection->addFieldToFilter($field, $value);
00070                 }
00071             } catch (Mage_Core_Exception $e) {
00072                 $this->_fault('filters_invalid', $e->getMessage());
00073             }
00074         }
00075 
00076         $result = array();
00077 
00078         foreach ($collection as $product) {
00079 //            $result[] = $product->getData();
00080             $result[] = array( // Basic product data
00081                 'product_id' => $product->getId(),
00082                 'sku'        => $product->getSku(),
00083                 'name'       => $product->getName(),
00084                 'set'        => $product->getAttributeSetId(),
00085                 'type'       => $product->getTypeId(),
00086                 'category_ids'       => $product->getCategoryIds()
00087             );
00088         }
00089 
00090         return $result;
00091     }

setSpecialPrice ( productId,
specialPrice = null,
fromDate = null,
toDate = null,
store = null 
)

Update product special price

Parameters:
int|string $productId
float $specialPrice
string $fromDate
string $toDate
string|int $store
Returns:
boolean

Reimplemented in Mage_Catalog_Model_Product_Api_V2.

Definition at line 266 of file Api.php.

00267     {
00268         return $this->update($productId, array(
00269             'special_price'     => $specialPrice,
00270             'special_from_date' => $fromDate,
00271             'special_to_date'   => $toDate
00272         ), $store);
00273     }

update ( productId,
productData = array(),
store = null 
)

Update product data

Parameters:
int|string $productId
array $productData
string|int $store
Returns:
boolean

Reimplemented in Mage_Catalog_Model_Product_Api_V2.

Definition at line 186 of file Api.php.

00187     {
00188         $product = $this->_getProduct($productId, $store);
00189 
00190         if (!$product->getId()) {
00191             $this->_fault('not_exists');
00192         }
00193 
00194         if (isset($productData['website_ids']) && is_array($productData['website_ids'])) {
00195             $product->setWebsiteIds($productData['website_ids']);
00196         }
00197 
00198         foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
00199             if ($this->_isAllowedAttribute($attribute)
00200                 && isset($productData[$attribute->getAttributeCode()])) {
00201                 $product->setData(
00202                     $attribute->getAttributeCode(),
00203                     $productData[$attribute->getAttributeCode()]
00204                 );
00205             }
00206         }
00207 
00208         $this->_prepareDataForSave($product, $productData);
00209 
00210         try {
00211             if (is_array($errors = $product->validate())) {
00212                 $this->_fault('data_invalid', implode("\n", $errors));
00213             }
00214         } catch (Mage_Core_Exception $e) {
00215             $this->_fault('data_invalid', $e->getMessage());
00216         }
00217 
00218         try {
00219             $product->save();
00220         } catch (Mage_Core_Exception $e) {
00221             $this->_fault('data_invalid', $e->getMessage());
00222         }
00223 
00224         return true;
00225     }


Member Data Documentation

$_filtersMap [protected]

Initial value:

 array(
        'product_id' => 'entity_id',
        'set'        => 'attribute_set_id',
        'type'       => 'type_id'
    )

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:39 2009 for Magento by  doxygen 1.5.8