public function updateProduct(Google_Service_ShoppingContent_Product $product) { // Let's fix the warning about product_type and update the product $product->setProductType('English/Classics'); // Notice that we use insert. The products service does not have an update // method. Inserting a product with an ID that already exists means the same // as doing an update anyway. $response = $this->service->products->insert($this->merchant_id, $product); // We should get one fewer warning now $warnings = $response->getWarnings(); printf("Product updated, there are now %d warnings\n", count($warnings)); foreach ($warnings as $warning) { printf(" [%s] %s\n", $warning->getReason(), $warning->getMessage()); } }
/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Google_Service_ShoppingContent_Product $shoppingProduct * @return Google_Service_ShoppingContent_Product */ public function convertAttribute($product, $shoppingProduct) { $productCategories = $product->getCategoryIds(); // TODO: set Default value for product_type attribute if product isn't assigned for any category $value = 'Shop'; if (!empty($productCategories)) { $category = Mage::getModel('catalog/category')->load(array_shift($productCategories)); $breadcrumbs = array(); foreach ($category->getParentCategories() as $cat) { $breadcrumbs[] = $cat->getName(); } $value = implode(' > ', $breadcrumbs); Mage::log($value); } $shoppingProduct->setProductType($value); return $shoppingProduct; }
/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Google_Service_ShoppingContent_Product $shoppingProduct * @return Google_Service_ShoppingContent_Product */ public function convertAttribute($product, $shoppingProduct) { $productCategories = $product->getCategoryIds(); $value = 'Shop'; if (!empty($productCategories)) { $category = Mage::getModel('catalog/category')->load(array_shift($productCategories)); $breadcrumbs = array(); foreach ($category->getParentCategories() as $cat) { $breadcrumbs[] = $cat->getName(); } $value = implode(' > ', $breadcrumbs); if (!count($breadcrumbs)) { $value = $category->getName(); } } $shoppingProduct->setProductType($value); return $shoppingProduct; }