Example #1
0
 /**
  * Retrieve product info.
  * Optional attributes configurable_attributes_data and configurable_products_data
  * show info on children products and configurable options
  *
  * @param int|string $productId
  * @param string|int $store
  * @param stdClass $attributes
  * @param string $identifierType (sku or null)
  * @return array
  */
 public function info($productId, $store = null, $attributes = null, $identifierType = null)
 {
     $product = $this->_getProduct($productId, $store, $identifierType);
     $all_attributes = in_array('*', $attributes->attributes);
     $result = parent::info($productId, $store, $attributes, $identifierType);
     $standard_attributes = $attributes->attributes;
     return Mage::getSingleton('Yameveo_ProductInfo_Model_Catalog_Product_Api')->infoResult($result, $product, $standard_attributes, $store, $all_attributes);
 }
Example #2
0
 public function update($productId, $productData, $store = null, $identifierType = null)
 {
     $tries = 0;
     $maxtries = 3;
     for ($tries = 0; $tries < $maxtries; $tries++) {
         try {
             return parent::update($productId, $productData, $store, $identifierType);
         } catch (Exception $e) {
             if ($e->getMessage() == 'SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction') {
                 sleep(1);
             } else {
                 throw $e;
             }
         }
     }
 }
 protected function _prepareDataForSave($product, $productData)
 {
     /* @var $product Mage_Catalog_Model_Product */
     if (property_exists($productData, 'categories')) {
         $categoryIds = Mage::helper('springboard_retail_api/catalog_product')->getCategoryIdsByNames((array) $productData->categories);
         if (!empty($categoryIds)) {
             $productData->categories = array_unique($categoryIds);
         }
     }
     if (property_exists($productData, 'additional_attributes')) {
         $singleDataExists = property_exists((object) $productData->additional_attributes, 'single_data');
         $multiDataExists = property_exists((object) $productData->additional_attributes, 'multi_data');
         if ($singleDataExists || $multiDataExists) {
             if ($singleDataExists) {
                 foreach ($productData->additional_attributes->single_data as $_attribute) {
                     $_attrCode = $_attribute->key;
                     $productData->{$_attrCode} = Mage::helper('springboard_retail_api/catalog_product')->getOptionKeyByLabel($_attrCode, $_attribute->value);
                 }
             }
             if ($multiDataExists) {
                 foreach ($productData->additional_attributes->multi_data as $_attribute) {
                     $_attrCode = $_attribute->key;
                     $productData->{$_attrCode} = Mage::helper('springboard_retail_api/catalog_product')->getOptionKeyByLabel($_attrCode, $_attribute->value);
                 }
             }
         } else {
             foreach ($productData->additional_attributes as $_attrCode => $_value) {
                 $productData->{$_attrCode} = Mage::helper('springboard_retail_api/catalog_product')->getOptionKeyByLabel($_attrCode, $_value);
             }
         }
         unset($productData->additional_attributes);
     }
     if (property_exists($productData, 'website_ids')) {
         $websiteIds = (array) $productData->website_ids;
         foreach ($websiteIds as $i => $websiteId) {
             if (!is_numeric($websiteId)) {
                 $website = Mage::app()->getWebsite($websiteId);
                 if ($website->getId()) {
                     $websiteIds[$i] = $website->getId();
                 }
             }
         }
         $product->setWebsiteIds($websiteIds);
         unset($productData->website_ids);
     }
     parent::_prepareDataForSave($product, $productData);
     if (property_exists($productData, 'associated_skus')) {
         $simpleSkus = (array) $productData->associated_skus;
         $priceChanges = array();
         if (property_exists($productData, 'price_changes')) {
             if (key($productData->price_changes) === 0) {
                 $priceChanges = $productData->price_changes[0];
             } else {
                 $priceChanges = $productData->price_changes;
             }
         }
         $configurableAttributes = array();
         if (property_exists($productData, 'configurable_attributes')) {
             $configurableAttributes = $productData->configurable_attributes;
         }
         Mage::helper('springboard_retail_api/catalog_product')->associateProducts($product, $simpleSkus, $priceChanges, $configurableAttributes);
     }
 }
Example #4
0
 protected function _prepareDataForSave($product, $productData)
 {
     /* @var $product Mage_Catalog_Model_Product */
     $configAttributes = array();
     if (property_exists($productData, 'categories')) {
         $categoryIds = Mage::helper('jr_api/catalog_product')->getCategoryIdsByNames((array) $productData->categories);
         if (!empty($categoryIds)) {
             $productData->categories = array_unique($categoryIds);
         }
     }
     if (property_exists($productData, 'media')) {
         $path = Mage::getBaseDir() . '/media/catalog/product';
         if (file_exists($path . $productData->media['image'])) {
             $product->addImageToMediaGallery($path . $productData->media['image'], array('image', 'small_image', 'thumbnail'), true, false);
         }
     }
     if (property_exists($productData, 'additional_attributes')) {
         $singleDataExists = property_exists((object) $productData->additional_attributes, 'single_data');
         $multiDataExists = property_exists((object) $productData->additional_attributes, 'multi_data');
         $configAttributesExists = property_exists((object) $productData->additional_attributes, 'config_attributes');
         if ($configAttributesExists) {
             $configAttributes = explode(',', $productData->additional_attributes['config_attributes']);
         }
         if ($singleDataExists || $multiDataExists) {
             if ($singleDataExists) {
                 foreach ($productData->additional_attributes->single_data as $_attribute) {
                     $_attrCode = $_attribute->key;
                     $productData->{$_attrCode} = Mage::helper('jr_api/catalog_product')->getOptionKeyByLabel($_attrCode, $_attribute->value);
                 }
             }
             if ($multiDataExists) {
                 foreach ($productData->additional_attributes->multi_data as $_attribute) {
                     $_attrCode = $_attribute->key;
                     $productData->{$_attrCode} = Mage::helper('jr_api/catalog_product')->getOptionKeyByLabel($_attrCode, $_attribute->value);
                 }
             }
         } else {
             foreach ($productData->additional_attributes as $_attrCode => $_value) {
                 $productData->{$_attrCode} = Mage::helper('jr_api/catalog_product')->getOptionKeyByLabel($_attrCode, $_value);
             }
         }
         unset($productData->additional_attributes);
     }
     if (property_exists($productData, 'website_ids')) {
         $websiteIds = (array) $productData->website_ids;
         foreach ($websiteIds as $i => $websiteId) {
             if (!is_numeric($websiteId)) {
                 $website = Mage::app()->getWebsite($websiteId);
                 if ($website->getId()) {
                     $websiteIds[$i] = $website->getId();
                 }
             }
         }
         $product->setWebsiteIds($websiteIds);
         unset($productData->website_ids);
     }
     parent::_prepareDataForSave($product, $productData);
     if (property_exists($productData, 'associated_skus')) {
         $simpleSkus = (array) $productData->associated_skus;
         $priceChanges = array();
         if (property_exists($productData, 'price_changes')) {
             if (key($productData->price_changes) === 0) {
                 $priceChanges = $productData->price_changes[0];
             } else {
                 $priceChanges = $productData->price_changes;
             }
         }
         Mage::helper('jr_api/catalog_product')->associateProducts($product, $simpleSkus, $priceChanges, $configAttributes);
     }
 }