getAvailability($product) ? $this->__('In stock') : (count(array_intersect($product->getCategoryIds(), $this->_categoriesWithAnotherOutOfStockLabel)) ? $this->__('By request (up to three months)') : $this->__('Out of stock')); } /** * @param $product Mage_Catalog_Model_Product * @return int */ public function getAvailability($product) { if (count(array_intersect($product->getCategoryIds(), $this->_getInStockCategories()))) { return true; } $outOfStock = true; if ('simple' === $product->getTypeId()) { //Чоботи if (31 == $product->getData('attribute_set_id')) { return (float) $product->getData('stock_item')->getData('qty'); } $stockItem = $product->getData('stock_item'); $outOfStock = !$product->isSalable() || $stockItem->getData('manage_stock') && $stockItem->getData('is_in_stock') && !(float)$stockItem->getData('qty'); } else if ('configurable' === $product->getTypeId()) { /** @var Mage_Catalog_Model_Product_Type_Configurable $type */ $type = $product->getTypeInstance(true); foreach ($type->getUsedProducts(null, $product) as $_usedProduct) { /** @var Mage_Catalog_Model_Product $_usedProduct */ if ($this->getAvailability($_usedProduct)) { $outOfStock = false; break; } } } return !$outOfStock; } protected function _getInStockCategories($outerIds = null) { if (null === $this->_manageStockCategories) { if (null === $outerIds) { $ids = $this->_manageStockParentCategories; } else { $ids = $outerIds; } $result = array(); foreach ($ids as $id) { /** @var Mage_Catalog_Model_Category $model */ $model = Mage::getModel('catalog/category')->load($id); $keys = array(); foreach($model->getChildrenCategories()as$key=>$item){ $keys[]= $key; } if (sizeof($model->getChildrenCategories())) { $result = array_merge($result, $keys); } } if (!$outerIds) { $this->_manageStockCategories = array_merge($result, $ids); } } return $this->_manageStockCategories; } }