/** * Map an array of website ids the product should be linked to, based upon * the item's client id, catalog id and/or store id. * * @param DOMNodeList * @param Mage_Catalog_Model_Product * @return array */ public function extractWebsiteIds(DOMNodeList $nodes, Mage_Catalog_Model_Product $product) { $websiteIds = $product->getWebsiteIds(); $itemNode = $nodes->item(0); // If there's no node to get data from, just let website ids remain // what it is. if (!$itemNode) { return $websiteIds; } $clientId = $itemNode->getAttribute('gsi_client_id'); $catalogId = $itemNode->getAttribute('catalog_id'); $storeId = $itemNode->getAttribute('gsi_store_id'); $websites = $this->catalogHelper->loadWebsiteFilters(); foreach ($websites as $websiteFilter) { $websiteId = $websiteFilter['mage_website_id']; // Assume no value in feed is a wildcard. $matches = !$catalogId || $catalogId === $websiteFilter['catalog_id']; $matches = $matches && (!$clientId || $clientId === $websiteFilter['client_id']); $matches = $matches && (!$storeId || $storeId === $websiteFilter['store_id']); // Just add any matched websites to the list, ignoring that this // might end up with dupes, list will be made unique when returned. if ($matches) { $websiteIds[] = $websiteId; } } return array_unique($websiteIds); }
/** * given a collection of products and a collection deleted sku data remove * each product that matches in catalog id and client id in a specific website * @param Mage_Catalog_Model_Resource_Product_Collection $collection * @param array $dData * @return self */ protected function _removeFromWebsites(Mage_Catalog_Model_Resource_Product_Collection $collection, array $dData) { foreach ($this->_helper->loadWebsiteFilters() as $siteFilter) { foreach ($this->_getSkusInWebsite($dData, $siteFilter) as $dSku) { $product = $collection->getItemById($dSku); if ($product) { $product->setWebsiteIds($this->_removeWebsiteId($product->getWebsiteIds(), $siteFilter['mage_website_id'])); } } } $collection->save(); return $this; }