/** * Iterator callback to add a product to the feed. * * @param array $args */ public function addProductToFeed($args) { $product = Mage::getModel('catalog/product')->setData($args['row']); /* @var $product Mage_Catalog_Model_Product */ // price $taxHelper = Mage::helper('tax'); if ($product->getData($this->getAttributeMapping('rakuten_feed_price'))) { $finalPrice = $taxHelper->getPrice($product, $product->getData($this->getAttributeMapping('rakuten_feed_price'))); } else { $finalPrice = $taxHelper->getPrice($product, $product->getFinalPrice()); } // required atts $name = trim($product->getData($this->getAttributeMapping('name'))); $shortDescription = trim(strip_tags($product->getData($this->getAttributeMapping('short_description')))); $categoryId = $product->getData($this->getAttributeMapping('rakuten_category_id')); if (!$finalPrice || !$name || !$shortDescription || !$categoryId) { return; } // images $imageFile = $product->getData($this->getAttributeMapping('image')); if ($imageFile && $imageFile != 'no_selection') { $mainImage = $this->getAttributeMapping('image'); } else { $mainImage = $this->getAttributeMapping('image2'); } $additionalImages = array(); $product->loadMediaGallery(); foreach ($product->getMediaGalleryImages(false) as $imageInfo) { $file = $imageInfo->getFile(); if ($file != $product->getData($mainImage) && $file != $product->getData($this->getAttributeMapping('image_exclude'))) { $product->setAdditionalImage($file); try { $additionalImages[] = $this->getImageUrl($product, 'additional_image', false); } catch (Exception $e) { } } } $row = array('gtin' => (string) $product->getData($this->getAttributeMapping('upc')), 'isbn' => (string) $product->getData($this->getAttributeMapping('isbn')), 'mfg_name' => $product->getAttributeText($this->getAttributeMapping('manufacturer_name')), 'mfg_part_number' => (string) $product->getData($this->getAttributeMapping('manufacturer_part_number')), 'asin' => (string) $product->getData($this->getAttributeMapping('asin')), 'merchant_sku' => (string) $product->getData($this->getAttributeMapping('sku')), 'title' => $name, 'description' => $shortDescription, 'main_image' => $this->getImageUrl($product, $mainImage), 'additional_images' => implode(self::SEPARATOR, $additionalImages), 'weight' => round($product->getData($this->getAttributeMapping('weight')), 2), 'features' => (string) $product->getData($this->getAttributeMapping('features')), 'listing_price' => $finalPrice, 'msrp' => (string) $product->getData($this->getAttributeMapping('msrp')), 'category_id' => $categoryId, 'keywords' => (string) $product->getData($this->getAttributeMapping('meta_keyword')), 'product_set_id' => ''); // ability to overwrite stock fields with category fields $categoryFields = $this->_processCategoryFields($product->getData($this->getAttributeMapping('rakuten_category_fields'))); foreach ($categoryFields as $field => $value) { if (isset($row[$field])) { $row[$field] = $value; unset($categoryFields[$field]); } else { $map = str_replace('-', '_', $field); // so product-set-id and product_set_id are both accounted for if (isset($row[$map])) { $row[$map] = $value; unset($categoryFields[$field]); } } } $row['category_fields'] = $categoryFields; $this->sanitizeRow($row); $row = new Varien_Object($row); Mage::dispatchEvent('productfeed_addproducttofeed', array('vendor' => $this, 'row' => $row)); $this->addCategoryFields($product->getId(), $row->getCategoryFields()); $row->unsCategoryFields(); $args['products'][$product->getId()] = $row->getData(); }