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);
     }
 }
Ejemplo n.º 2
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);
     }
 }