/** * Skip checks for images since this is an non-apparel configurable, * because the image is mapped later using criteria to grab from configurable * * @return $this */ public function _beforeMap() { if ($parentMap = $this->getParentMap()) { if ($parentMap->getProduct()->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE || $parentMap->getProduct()->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED || $parentMap->getProduct()->getTypeId() == RocketWeb_GoogleBaseFeedGenerator_Model_Map_Product_Subscription_Configurable::PRODUCT_TYPE_SUBSCTIPTION_CONFIGURABLE || $parentMap->getProduct()->getTypeId() == RocketWeb_GoogleBaseFeedGenerator_Model_Map_Product_Subscription_Grouped::PRODUCT_TYPE_SUBSCTIPTION_GROUPED) { return $this; } } // do the regular image check return parent::_beforeMap(); }
public function _map() { $rows = array(); if ($this->getConfig()->isAllowConfigurableMode($this->getStoreId())) { if (!$this->isSkip()) { $row = parent::_map(); } reset($row); $row = current($row); $rows[] = $row; } if ($this->getConfig()->isAllowAssociatedMode($this->getStoreId())) { foreach ($this->getAssocMaps() as $assocId => $assocMap) { $row = $assocMap->map(); reset($row); $row = current($row); if (!$assocMap->isSkip()) { $rows[] = $row; } } } return $rows; }
/** * @param $rows * @return array */ public function _afterMap($rows) { // Free some memory foreach ($this->_assocs as $assoc) { $this->getTools()->clearNestedObject($assoc); } return parent::_afterMap($rows); }
/** * @param RocketWeb_GoogleBaseFeedGenerator_Model_Map_Product_Abstract $productMap */ protected function addProductToFeed($productMap) { try { $rows = $productMap->map(); // if (get_class($productMap) != 'RocketWeb_GoogleBaseFeedGenerator_Model_Map_Product_Configurable_Apparel') { $rows = $productMap->map(); } if ($productMap->isSkip()) { $this->_count_products_skipped++; return $this; } if (($productMap->getProduct()->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE || $productMap->getProduct()->getTypeId() == RocketWeb_GoogleBaseFeedGenerator_Model_Map_Product_Subscription_Configurable::PRODUCT_TYPE_SUBSCTIPTION_CONFIGURABLE) && $productMap->getIsApparel() && $productMap->hasAssocMaps() && $productMap->getIsVariants()) { foreach ($productMap->getAssocMaps() as $assocMap) { if ($assocMap->isSkip()) { $this->_count_products_skipped++; } } } foreach ($rows as $row) { // format prices foreach ($row as $column => $value) { if (($column == "price" || $column == "sale_price") && trim($value) != "") { $row[$column] = $this->formatPrice($value); } } $this->writeFeed($row); $this->_count_products_exported++; } } catch (Exception $e) { $this->log($e->getMessage(), Zend_Log::ERR); if ($this->getTestMode()) { if ($productMap instanceof RocketWeb_GoogleBaseFeedGenerator_Model_Map_Product_Abstract && $productMap->getProduct() instanceof Mage_Catalog_Model_Product) { Mage::throwException(sprintf("product id %d product sku %s: " . $e->getMessage(), $productMap->getProduct()->getId(), $productMap->getProduct()->getSku())); } else { Mage::throwException($e->getMessage()); } } } return $this; }
/** * @param $params * @param $attributes_codes * @return string */ public function mapDirectiveVariantAttributes($params = array()) { // try to get value from parent first $value = $this->hasParentMap() ? $this->getParentMap()->mapDirectiveVariantAttributes($params) : ''; if (empty($value)) { $value = parent::mapDirectiveVariantAttributes($params); } return $value; }
/** * @param RocketWeb_GoogleBaseFeedGenerator_Model_Map_Product_Abstract $productMap */ protected function addProductToFeed($productMap) { try { $rows = $productMap->map(); if ($productMap->isSkip()) { return $this; } foreach ($rows as $row) { // format prices foreach ($row as $column => $value) { if (($column == "price" || $column == "sale_price") && trim($value) != "") { $row[$column] = $this->formatPrice($value); } } $this->writeFeed($row); $this->_count_products_exported++; } } catch (Exception $e) { $this->log($e->getMessage(), Zend_Log::ERR); if ($this->getTestMode()) { if ($productMap instanceof RocketWeb_GoogleBaseFeedGenerator_Model_Map_Product_Abstract && $productMap->getProduct() instanceof Mage_Catalog_Model_Product) { Mage::throwException(sprintf("product id %d product sku %s: " . $e->getMessage(), $productMap->getProduct()->getId(), $productMap->getProduct()->getSku())); } else { Mage::throwException($e->getMessage()); } } } return $this; }
/** * @param array $params * @return string */ protected function mapDirectiveAvailability($params = array()) { $map = $params['map']; // Set the Static Value / overwrite $default_value = isset($map['default_value']) ? $map['default_value'] : ""; if ($default_value != "") { $stock_status = trim(strtolower($default_value)); if (array_search($stock_status, $this->getConfig()->getAllowedStockStatuses()) === false) { $stock_status = $this->getConfig()->getOutOfStockStatus(); } return $this->cleanField($stock_status, $params); } // Set the computed configurable stock status if ($this->hasAssociatedStockStatus() && $this->getAssociatedStockStatus() == $this->getConfig()->getOutOfStockStatus()) { return $this->cleanField($this->getAssociatedStockStatus(), $params); } return parent::mapDirectiveAvailability($params); }
/** * @return array */ public function map() { $rows = array(); $parentRow = null; $this->_beforeMap(); if ($this->getConfig()->isAllowBundleMode($this->getStoreId())) { if (!$this->isSkip()) { // simulate parent::map() without clearing associated_maps from memory, as associated more could be on. $row = parent::_map(); reset($row); $parentRow = current($row); // remove parent and skipping flag so that the associated items could still be processed. if ($this->isSkip()) { $parentRow = null; } } } if ($this->getConfig()->isAllowBundleAssociatedMode($this->getStoreId()) && $this->hasAssocMaps()) { foreach ($this->getAssocMaps() as $assocMap) { $row = $assocMap->map(); reset($row); $row = current($row); if (!$assocMap->isSkip()) { $rows[] = $row; } } } // Fill in parent columns specified in $inherit_columns with values list from associated items if (!is_null($parentRow)) { $this->mergeVariantValuesToParent($parentRow, $rows); array_unshift($rows, $parentRow); } // if any of the associated not skipped, force add them to the feed if (count($rows)) { $this->unSkip(); } return $this->_afterMap($rows); }
public function _beforeMap() { parent::_beforeMap(); if ($this->isSkip()) { return $this; } $this->_assocs = array(); $bundleType = $this->getProduct()->getTypeInstance(true); $assocCollection = $bundleType->getSelectionsCollection($bundleType->getOptionsIds($this->getProduct()), $this->getProduct()); $stockStatusFlag = false; $stockStatus = false; foreach ($assocCollection as $option) { $assocId = $option->product_id; $assoc = Mage::getModel('catalog/product'); $assoc->setStoreId($this->getStoreId()); $assoc->getResource()->load($assoc, $assocId); if ($this->getGenerator()->getData('verbose')) { echo $this->getGenerator()->formatMemory(memory_get_usage(true)) . " - Bundle Associated: " . $assoc->getId() . "\n"; } $stock = $this->getConfig()->getOutOfStockStatus(); if (!$this->getConfigVar('use_default_stock', 'columns')) { $stock_attribute = $this->getGenerator()->getAttribute($this->getConfigVar('stock_attribute_code', 'columns')); if ($stock_attribute === false) { Mage::throwException(sprintf('Couldn\'t find attribute \'%s\'.', $this->getConfigVar('stock_attribute_code', 'columns'))); } $stock = trim(strtolower($this->getAttributeValue($assoc, $stock_attribute))); if (array_search($stock, $this->getConfig()->getAllowedStockStatuses()) === false) { $stock = $this->getConfig()->getOutOfStockStatus(); } } else { $stockItem = Mage::getModel('cataloginventory/stock_item'); $stockItem->setStoreId($this->getStoreId()); $stockItem->getResource()->loadByProductId($stockItem, $assoc->getId()); $stockItem->setOrigData(); if ($stockItem->getId() && $stockItem->getIsInStock()) { $assoc->setData('quantity', $stockItem->getQty()); $stock = $this->getConfig()->getInStockStatus(); } // Clear stockItem memory unset($stockItem->_data); $this->getTools()->clearNestedObject($stockItem); } // Append assoc considering the appropriate stock status if ($this->getConfigVar('add_out_of_stock')) { $this->_assocs[$assocId] = $assoc; $this->_assoc_ids[] = $assocId; } elseif ($stock == $this->getConfig()->getInStockStatus()) { $this->_assocs[$assocId] = $assoc; $this->_assoc_ids[] = $assocId; } else { // Set skip messages if ($this->getConfigVar('log_skip')) { $this->log(sprintf("product id %d sku %s, configurable item, skipped - out of stock", $assocId, $assoc->getSku())); } } // Set stock status of the current item and check if the status has changed if ($stockStatus != false && $stock != $stockStatus) { $stockStatusFlag = true; } $stockStatus = $stock; } // Set bundle stock status if all assocs have the same stock status, only for default stocks if ($this->getConfigVar('use_default_stock', 'columns') && $stockStatus && !$stockStatusFlag) { $this->setAssociatedStockStatus($stockStatus); if ($stockStatus == $this->getConfig()->getOutOfStockStatus() && !$this->getConfigVar('add_out_of_stock')) { $this->setSkip(sprintf("product id %d sku %s, bundle, skipped - out of stock.", $this->getProduct()->getId(), $this->getProduct()->getSku())); } } // Set associated prices $this->setCacheAssociatedPrices(); // TODO: convert this piece to Bundle settings when we decide to add it in configs. // $assocMapArr = array(); // if ($this->getConfig()->isAllowConfigurableAssociatedMode($this->getStoreId()) && !$this->getIsApparel()) { // foreach ($this->_assocs as $assoc) { // $assocMap = $this->getAssocMapModel($assoc); // if ($assocMap->checkSkipSubmission()->isSkip()) { // if ($this->getConfigVar('log_skip')) { // $this->log(sprintf("product id %d sku %s, configurable associated, skipped - product has 'Skip from Being Submitted' = 'Yes'.", $assoc->getId(), $assoc->getSku())); // } // continue; // } // $assocMapArr[$assoc->getId()] = $assocMap; // } // } // // $this->setAssocMaps($assocMapArr); return $this; }
/** * @param array $params * @return string */ protected function mapDirectiveAvailability($params = array()) { // Set the computed configurable stock status if ($this->hasAssociatedStockStatus() && $this->getAssociatedStockStatus() == $this->getConfig()->getOutOfStockStatus()) { return $this->cleanField($this->getAssociatedStockStatus(), $params); } return parent::mapDirectiveAvailability($params); }