本文整理汇总了PHP中Mage_Catalog_Model_Product::isSaleable方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::isSaleable方法的具体用法?PHP Mage_Catalog_Model_Product::isSaleable怎么用?PHP Mage_Catalog_Model_Product::isSaleable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::isSaleable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _collectProductInfo
/**
* 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: testIsSalable
/**
* @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: getProductCustomOptionsXmlObject
/**
* 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: _isSelected
/**
* 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();
}
}
示例5: getProductCustomOptionsXmlObject
/**
* 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;
}
示例6: getProductCustomOptionsOption
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;
}
示例7: getAvailableText
/**
* 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;
}
示例8: _setIsAvailable
/**
* 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();
}