Пример #1
0
 /**
  * Collect the basic information about the product and return it as an array.
  *
  * @param Mage_Catalog_Model_Product $product
  * @return array
  */
 protected function _collectProductInfo(Mage_Catalog_Model_Product $product)
 {
     //basic product info, same for every possible product type
     $productInfo = array('id' => $product->getId(), 'type' => $product->getTypeId(), 'name' => $product->getName(), 'saleable' => $product->isSaleable(), 'price' => Mage::helper('tax')->getPrice($product, $product->getFinalPrice()), 'priceTemplate' => $this->getPriceTemplate());
     $manufacturer = $this->_getManufacturer($product);
     if ($manufacturer) {
         $productInfo['manufacturer'] = $manufacturer;
     }
     //if product has active special price
     if ($oldPrice = $this->getOldPrice($product)) {
         $productInfo['oldPrice'] = $oldPrice;
     }
     //allowed sale quantities
     if ($qtyLimits = $this->getProductQtyLimits($product)) {
         list($minQty, $maxQty) = $qtyLimits;
         if ($minQty !== null) {
             $productInfo['minqty'] = $minQty;
         }
         if ($maxQty !== null) {
             $productInfo['maxqty'] = $maxQty;
         }
     }
     //add product tax info
     if ($taxInfo = $this->getProductTax($product)) {
         $productInfo['tax'] = $taxInfo;
     }
     //get additional info, if possible
     //this may be different for various product types
     $productInfo = $this->_collectAdditionalProductInfo($product, $productInfo);
     return $productInfo;
 }
Пример #2
0
 /**
  * @covers Mage_Catalog_Model_Product::isSalable
  * @covers Mage_Catalog_Model_Product::isSaleable
  * @covers Mage_Catalog_Model_Product::isAvailable
  * @covers Mage_Catalog_Model_Product::isInStock
  */
 public function testIsSalable()
 {
     $this->_model->load(1);
     // fixture
     $this->assertTrue((bool) $this->_model->isSalable());
     $this->assertTrue((bool) $this->_model->isSaleable());
     $this->assertTrue((bool) $this->_model->isAvailable());
     $this->assertTrue($this->_model->isInStock());
     $this->_model->setStatus(0);
     $this->assertFalse((bool) $this->_model->isSalable());
     $this->assertFalse((bool) $this->_model->isSaleable());
     $this->assertFalse((bool) $this->_model->isAvailable());
     $this->assertFalse($this->_model->isInStock());
 }
Пример #3
0
 /**
  * Create produc custom options Mage_XmlConnect_Model_Simplexml_Element object
  *
  * @param Mage_Catalog_Model_Product $product
  * @return Mage_XmlConnect_Model_Simplexml_Element
  */
 public function getProductCustomOptionsXmlObject(Mage_Catalog_Model_Product $product)
 {
     $xmlModel = new Mage_XmlConnect_Model_Simplexml_Element('<product></product>');
     $optionsNode = $xmlModel->addChild('options');
     if (!$product->getId()) {
         return $xmlModel;
     }
     $xmlModel->addAttribute('id', $product->getId());
     if (!$product->isSaleable() || !sizeof($product->getOptions())) {
         return $xmlModel;
     }
     foreach ($product->getOptions() as $option) {
         $optionNode = $optionsNode->addChild('option');
         $type = $this->_getOptionTypeForXmlByRealType($option->getType());
         $code = 'options[' . $option->getId() . ']';
         if ($type == self::OPTION_TYPE_CHECKBOX) {
             $code .= '[]';
         }
         $optionNode->addAttribute('code', $code);
         $optionNode->addAttribute('type', $type);
         $optionNode->addAttribute('label', $xmlModel->xmlentities(strip_tags($option->getTitle())));
         if ($option->getIsRequire()) {
             $optionNode->addAttribute('is_required', 1);
         }
         /**
          * Process option price
          */
         $price = Mage::helper('xmlconnect')->formatPriceForXml($option->getPrice());
         if ($price > 0.0) {
             $optionNode->addAttribute('price', $price);
             $formatedPrice = Mage::app()->getStore($product->getStoreId())->formatPrice($price, false);
             $optionNode->addAttribute('formated_price', $formatedPrice);
         }
         if ($type == self::OPTION_TYPE_CHECKBOX || $type == self::OPTION_TYPE_SELECT) {
             foreach ($option->getValues() as $value) {
                 $valueNode = $optionNode->addChild('value');
                 $valueNode->addAttribute('code', $value->getId());
                 $valueNode->addAttribute('label', $xmlModel->xmlentities(strip_tags($value->getTitle())));
                 $price = Mage::helper('xmlconnect')->formatPriceForXml($value->getPrice());
                 if ($price > 0.0) {
                     $valueNode->addAttribute('price', $price);
                     $formatedPrice = $this->_formatPriceString($price, $product);
                     $valueNode->addAttribute('formated_price', $formatedPrice);
                 }
             }
         }
     }
     return $xmlModel;
 }
Пример #4
0
 /**
  * Generate bundle product options xml
  *
  * @param Mage_Catalog_Model_Product $product
  * @param bool $isObject
  * @return string | Mage_XmlConnect_Model_Simplexml_Element
  */
 public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false)
 {
     $xmlModel = Mage::getModel('xmlconnect/simplexml_element', '<product></product>');
     $optionsNode = $xmlModel->addChild('options');
     if (!$product->getId()) {
         return $isObject ? $xmlModel : $xmlModel->asNiceXml();
     }
     $xmlModel->addAttribute('id', $product->getId());
     if (!$product->isSaleable()) {
         return $isObject ? $xmlModel : $xmlModel->asNiceXml();
     }
     /**
      * Grouped (associated) products
      */
     $_associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
     if (!sizeof($_associatedProducts)) {
         return $isObject ? $xmlModel : $xmlModel->asNiceXml();
     }
     foreach ($_associatedProducts as $_item) {
         if (!$_item->isSaleable()) {
             continue;
         }
         $optionNode = $optionsNode->addChild('option');
         $optionNode->addAttribute('code', 'super_group[' . $_item->getId() . ']');
         $optionNode->addAttribute('type', 'product');
         $optionNode->addAttribute('label', $xmlModel->xmlentities($_item->getName()));
         $optionNode->addAttribute('is_qty_editable', 1);
         $optionNode->addAttribute('qty', $_item->getQty() * 1);
         /**
          * Process product price
          */
         if ($_item->getPrice() != $_item->getFinalPrice()) {
             $productPrice = $_item->getFinalPrice();
         } else {
             $productPrice = $_item->getPrice();
         }
         if ($productPrice != 0) {
             $productPrice = Mage::helper('xmlconnect')->formatPriceForXml($productPrice);
             $optionNode->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml(Mage::helper('core')->currency($productPrice, false, false)));
             $optionNode->addAttribute('formated_price', $this->_formatPriceString($productPrice, $product));
         }
     }
     return $isObject ? $xmlModel : $xmlModel->asNiceXml();
 }
Пример #5
0
 /**
  * Define if selection is selected
  *
  * @param  Mage_Catalog_Model_Product $selection
  * @return bool
  */
 protected function _isSelected($selection)
 {
     $selectedOptions = $this->_getSelectedOptions();
     if (is_numeric($selectedOptions)) {
         return $selection->getSelectionId() == $this->_getSelectedOptions();
     } elseif (is_array($selectedOptions) && !empty($selectedOptions)) {
         return in_array($selection->getSelectionId(), $this->_getSelectedOptions());
     } elseif ($selectedOptions == 'None') {
         return false;
     } else {
         return $selection->getIsDefault() && $selection->isSaleable();
     }
 }
Пример #6
0
 /**
  * Create produc custom options Mage_XmlConnect_Model_Simplexml_Element object
  *
  * @param Mage_Catalog_Model_Product $product
  * @return Mage_XmlConnect_Model_Simplexml_Element
  */
 public function getProductCustomOptionsXmlObject(Mage_Catalog_Model_Product $product)
 {
     $xmlModel = Mage::getModel('xmlconnect/simplexml_element', '<product></product>');
     $optionsNode = $xmlModel->addChild('options');
     if ($product->hasPreconfiguredValues()) {
         $preConfiguredValues = $product->getPreconfiguredValues();
         $optionData = $preConfiguredValues->getData('options');
     }
     if (!$product->getId()) {
         return $xmlModel;
     }
     $xmlModel->addAttribute('id', $product->getId());
     if (!$product->isSaleable() || !sizeof($product->getOptions())) {
         return $xmlModel;
     }
     foreach ($product->getOptions() as $option) {
         $optionNode = $optionsNode->addChild('option');
         $type = $this->_getOptionTypeForXmlByRealType($option->getType());
         $code = 'options[' . $option->getId() . ']';
         if ($type == self::OPTION_TYPE_CHECKBOX) {
             $code .= '[]';
         }
         $optionNode->addAttribute('code', $code);
         $optionNode->addAttribute('type', $type);
         $optionNode->addAttribute('label', $xmlModel->escapeXml($option->getTitle()));
         if ($option->getIsRequire()) {
             $optionNode->addAttribute('is_required', 1);
         }
         /**
          * Process option price
          */
         $price = $option->getPrice();
         if ($price) {
             $optionNode->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml($price));
             $formattedPrice = Mage::app()->getStore($product->getStoreId())->formatPrice($price, false);
             $optionNode->addAttribute('formated_price', $formattedPrice);
         }
         $optionId = $option->getOptionId();
         if ($type == self::OPTION_TYPE_CHECKBOX || $type == self::OPTION_TYPE_SELECT) {
             foreach ($option->getValues() as $value) {
                 $code = $value->getId();
                 $valueNode = $optionNode->addChild('value');
                 $valueNode->addAttribute('code', $code);
                 $valueNode->addAttribute('label', $xmlModel->escapeXml($value->getTitle()));
                 if ($value->getPrice() != 0) {
                     $price = Mage::helper('xmlconnect')->formatPriceForXml($value->getPrice());
                     $valueNode->addAttribute('price', $price);
                     $formattedPrice = $this->_formatPriceString($price, $product);
                     $valueNode->addAttribute('formated_price', $formattedPrice);
                 }
                 if ($product->hasPreconfiguredValues()) {
                     $this->_setCartSelectedValue($valueNode, $type, $this->_getPreconfiguredOption($optionData, $optionId, $code));
                 }
             }
         } else {
             if ($product->hasPreconfiguredValues() && array_key_exists($option->getOptionId(), $optionData)) {
                 $this->_setCartSelectedValue($optionNode, $type, $optionData[$optionId]);
             }
         }
     }
     return $xmlModel;
 }
Пример #7
0
 private function getProductCustomOptionsOption(Mage_Catalog_Model_Product $product)
 {
     $options = array();
     if (!$product->getId()) {
         return $options;
     }
     if (!$product->isSaleable() || !sizeof($product->getOptions())) {
         return $options;
     }
     foreach ($product->getOptions() as $option) {
         $optionObj = array();
         $type = $this->_getOptionTypeForKanCartByRealType($option->getType());
         $optionObj['attribute_id'] = $option->getId();
         $optionObj['required'] = $option->getRequired() || $option->getIsRequire() || $option->getIsRequired();
         $optionObj['input'] = $type;
         $optionObj['title'] = $option->getTitle();
         $price = $option->getPrice();
         if ($price) {
             $optionObj['price'] = $this->getCurrencyPrice($price);
         } else {
             $optionObj['price'] = null;
         }
         $optionObj['options'] = array();
         if (!$optionObj['required'] && $optionObj['input'] == self::OPTION_TYPE_SELECT) {
             $none = array('attribute_id' => 'none', 'option_id' => '', 'title' => 'None');
             $optionObj['options'][] = $none;
         }
         foreach ($option->getValues() as $value) {
             $optionValueObj = array();
             $optionValueObj['attribute_id'] = $option->getId();
             $optionValueObj['option_id'] = $value->getId();
             $optionValueObj['title'] = $value->getTitle();
             $price = $value->getPrice();
             if ($price) {
                 $optionValueObj['price'] = $this->getCurrencyPrice($price);
             } else {
                 $optionValueObj['price'] = null;
             }
             $optionObj['options'][] = $optionValueObj;
         }
         $options[] = $optionObj;
     }
     return $options;
 }
Пример #8
0
 /**
  * fills the item-array available_text field
  * <strong>Note:</strong> the function isAvailable()  on the Product-Object is only available in Magento-Version >= 1.5
  *
  * @param Mage_Catalog_Model_Product $product
  * @param int $storeViewId
  *
  * @return string
  */
 public function getAvailableText($product, $storeViewId)
 {
     $availableText = "";
     $attributeCode = Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_AVAILABLE_TEXT_ATTRIBUTE_CODE);
     if ($attributeCode) {
         $attributeInputType = $product->getResource()->getAttribute($attributeCode)->getFrontendInput();
         $rawValue = $product->getResource()->getAttributeRawValue($product->getId(), $attributeCode, $storeViewId);
         switch ($attributeInputType) {
             case "select":
                 /** @var Mage_Eav_Model_Entity_Attribute_Option $attr */
                 $attr = Mage::getModel('eav/entity_attribute_option')->getCollection()->setStoreFilter($storeViewId)->join('attribute', 'attribute.attribute_id=main_table.attribute_id', 'attribute_code')->addFieldToFilter('main_table.option_id', array('eq' => $rawValue))->getFirstItem();
                 if ($attr) {
                     $availableText = $attr->getStoreValue() ? $attr->getStoreValue() : $attr->getValue();
                 }
                 break;
             case "date":
                 $availableText = Mage::helper('core')->formatDate($rawValue, 'medium', false);
                 break;
             case "text":
                 $availableText = $rawValue;
                 break;
             default:
         }
     }
     if (!$availableText) {
         /** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */
         $stockItem = $product->getStockItem();
         $isAvailable = $stockItem->checkQty(1) && $product->isSaleable();
         if ($product->isComposite()) {
             $isAvailable = true;
         }
         if ($isAvailable && $stockItem->getIsInStock()) {
             if ($stockItem->getManageStock() && $stockItem->getBackorders() == Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY && $stockItem->getQty() <= 0) {
                 $availableText = Mage::helper('shopgate')->__('Item will be backordered');
             } else {
                 $availableText = Mage::helper('shopgate')->__('In stock');
             }
         } else {
             $availableText = Mage::helper('shopgate')->__('Out of stock');
         }
     }
     return $availableText;
 }
Пример #9
0
 /**
  * Check if product is available by checking qty of 1 (will also trigger back orders).
  *
  * @param Mage_Catalog_Model_Product $product
  */
 protected function _setIsAvailable($product)
 {
     $this->_defaultRow['is_available'] = $product->isSaleable();
 }