public function _beforeMap() { $this->_assocs = array(); foreach ($this->getAssocIds() as $assocId) { $assoc = Mage::getModel('catalog/product'); $assoc->setStoreId($this->getStoreId()); $assoc->getResource()->load($assoc, $assocId); $this->_assocs[$assocId] = $assoc; } $assocMapArr = array(); if ($this->getConfig()->isAllowAssociatedMode($this->getStoreId())) { foreach ($this->_assocs as $assoc) { $assocMap = $this->getAssocMapModel($assoc); if ($assocMap->checkSkipSubmission()->isSkip()) { if ($this->getConfigVar('log_skip')) { $this->log(sprintf("product id %d product sku %s, skipped - product has 'Skip from Being Submitted' = 'Yes'.", $assoc->getId(), $assoc->getSku())); } continue; } $assocMapArr[$assoc->getId()] = $assocMap; } } $this->setAssocMaps($assocMapArr); return parent::_beforeMap(); }
/** * 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(); }
/** * Iterate through associated products and set mapping objects * * @return $this */ public function _beforeMap() { $this->_assocs = array(); foreach ($this->getAssocIds() as $assocId) { $assoc = Mage::getModel('catalog/product'); $assoc->setStoreId($this->getStoreId()); $assoc->getResource()->load($assoc, $assocId); $assoc->setData('quantity', 0); if ($this->getGenerator()->getData('verbose')) { echo $this->getGenerator()->formatMemory(memory_get_usage(true)) . " - Grouped associated SKU " . $assoc->getSku() . ", ID " . $assoc->getEntityId() . "\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('Invalid attribute for Availability column. Please make sure proper attribute is set under the setting "Alternate Stock/Availability Attribute.". Provided attribute code \'%s\' could not be found.', $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', 'grouped_products') || $stock == $this->getConfig()->getInStockStatus()) { $this->_assocs[$assocId] = $assoc; } else { // Set skip messages if ($this->getConfigVar('log_skip')) { $this->log(sprintf("product id %d sku %s, grouped associated, skipped - out of stock", $assocId, $assoc->getSku())); } } } return parent::_beforeMap(); }
/** * @return $this */ public function _beforeMap() { $this->_assocs = array(); foreach ($this->getAssocIds() as $assocId) { $assoc = Mage::getModel('catalog/product'); $assoc->setStoreId($this->getStoreId()); $assoc->getResource()->load($assoc, $assocId); $assoc->setData('quantity', 0); if ($this->getGenerator()->getData('verbose')) { echo $this->getGenerator()->formatMemory(memory_get_usage(true)) . " - Grouped Associated: " . $assoc->getEntityId() . "\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_grouped_assoc')) { $this->_assocs[$assocId] = $assoc; } elseif ($stock == $this->getConfig()->getInStockStatus()) { $this->_assocs[$assocId] = $assoc; } else { // Set skip messages if ($this->getConfigVar('log_skip')) { $this->log(sprintf("product id %d sku %s, grouped associated, skipped - out of stock", $assocId, $assoc->getSku())); } } } $assocMapArr = array(); foreach ($this->_assocs as $assoc) { $assocMap = $this->getAssocMapModel($assoc); if ($assocMap->checkSkipSubmission()->isSkip()) { unset($this->_assocs[$assoc->getEntityId()]); continue; } $assocMapArr[$assoc->getEntityId()] = $assocMap; } $this->setAssocMaps($assocMapArr); if (count($assocMapArr) <= 0) { $this->setSkip(sprintf("product id %d product sku %s, skipped - All associated products of the grouped product are disabled or out of stock.", $this->getProduct()->getId(), $this->getProduct()->getSku())); } return parent::_beforeMap(); }
public function _beforeMap() { parent::_beforeMap(); if ($this->isSkip()) { return $this; } $this->_assocs = array(); $stockStatusFlag = false; $stockStatus = false; foreach ($this->getAssocIds() as $assocId) { $assoc = Mage::getModel('catalog/product'); $assoc->setStoreId($this->getStoreId()); $assoc->getResource()->load($assoc, $assocId); $assoc->setData('quantity', 0); if ($this->getGenerator()->getData('verbose')) { echo $this->getGenerator()->formatMemory(memory_get_usage(true)) . " - Configurable 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_configurable_assoc')) { $this->_assocs[$assocId] = $assoc; } elseif ($stock == $this->getConfig()->getInStockStatus()) { $this->_assocs[$assocId] = $assoc; } 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 configurable 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, configurable, skipped - out of stock.", $this->getProduct()->getId(), $this->getProduct()->getSku())); } } // Set associated prices $this->setCacheAssociatedPrices(); $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; }
/** * Iterate through associated products and set mapping objects * * @return $this */ public function _beforeMap() { if ($this->isSkip()) { return $this; } $this->_assocs = array(); $bundleType = $this->getProduct()->getTypeInstance(true); $optionIds = $bundleType->getOptionsIds($this->getProduct()); if ($optionIds) { $assocCollection = $bundleType->getSelectionsCollection($optionIds, $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 SKU " . $assoc->getSku() . ", ID " . $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('Invalid attribute for Availability column. Please make sure proper attribute is set under the setting "Alternate Stock/Availability Attribute.". Provided attribute code \'%s\' could not be found.', $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', 'filters')) { $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', 'filters')) { $this->setSkip(sprintf("product id %d sku %s, bundle, skipped - out of stock.", $this->getProduct()->getId(), $this->getProduct()->getSku())); } } return parent::_beforeMap(); }
public function _beforeMap() { if (!empty($this->_assocs) || $this->isSkip()) { return $this; } parent::_beforeMap(); $this->_assocs = array(); $stockStatusFlag = false; $stockStatus = false; foreach ($this->getAssocIds() as $assocId) { $is_skip = false; $assoc = Mage::getModel('catalog/product'); $assoc->setStoreId($this->getStoreId()); $assoc->getResource()->load($assoc, $assocId); $assoc->setData('quantity', 0); if ($this->getGenerator()->getData('verbose')) { echo $this->getGenerator()->formatMemory(memory_get_usage(true)) . " - Configurable non-apparel associated SKU " . $assoc->getSku() . ", ID " . $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('Invalid attribute for Availability column. Please make sure proper attribute is set under the setting "Alternate Stock/Availability Attribute.". Provided attribute code \'%s\' could not be found.', $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); } // Skip assoc considering the appropriate stock status if (!$this->getConfigVar('add_out_of_stock', 'configurable_products') && $stock != $this->getConfig()->getInStockStatus()) { $is_skip = true; if ($this->getConfigVar('log_skip')) { $this->log(sprintf("product id %d sku %s, configurable item, skipped - out of stock", $assocId, $assoc->getSku())); } } if (!$is_skip) { $this->_assocs[$assocId] = $assoc; } // Set stock status of the current item and check if the status has changed if ($stockStatus != false && $stock != $stockStatus) { $stockStatusFlag = true; } $stockStatus = $stock; } // Set configurable 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', 'filters')) { $this->setSkip(sprintf("product id %d sku %s, configurable, skipped - out of stock.", $this->getProduct()->getId(), $this->getProduct()->getSku())); } } // Set associated prices $this->setCacheAssociatedPrices(); $assocMapArr = array(); foreach ($this->_assocs as $assoc) { $assocMap = $this->getAssocMapModel($assoc); if ($assocMap->checkSkipSubmission(true)->isSkip()) { continue; } $assocMapArr[$assoc->getId()] = $assocMap; } $this->setAssocMaps($assocMapArr); return $this; }