本文整理汇总了PHP中Mage_Catalog_Model_Product::getOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::getOptions方法的具体用法?PHP Mage_Catalog_Model_Product::getOptions怎么用?PHP Mage_Catalog_Model_Product::getOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::getOptions方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: productHasOptions
/**
* @param Mage_Catalog_Model_Product $product
* @return boolean
*/
public function productHasOptions(Mage_Catalog_Model_Product $product)
{
if (count($product->getOptions()) > 0) {
return true;
}
return false;
}
示例3: testOptionApi
/**
* @covers Mage_Catalog_Model_Product::addOption
* @covers Mage_Catalog_Model_Product::getOptionById
* @covers Mage_Catalog_Model_Product::getOptions
*/
public function testOptionApi()
{
$this->assertEquals(array(), $this->_model->getOptions());
$optionId = uniqid();
$option = new Mage_Catalog_Model_Product_Option(array('key' => 'value'));
$option->setId($optionId);
$this->_model->addOption($option);
$this->assertSame($option, $this->_model->getOptionById($optionId));
$this->assertEquals(array($optionId => $option), $this->_model->getOptions());
}
示例4: processData
/**
* @param array $productData
* @param Mage_Catalog_Model_Product $product
* @return mixed|void
*/
public function processData(array &$productData, $product)
{
if (isset($productData['custom_options'])) {
if ($product->getId()) {
$currentOptions = $product->getOptions();
foreach ($currentOptions as $option) {
$option->delete();
}
}
$optionsData = $productData['custom_options'];
if (!empty($optionsData)) {
foreach ($optionsData as $optionData) {
$this->_addOption($product, $optionData);
}
$product->setHasOptions(true);
} else {
$product->setHasOptions(false);
}
}
}
示例5: setInputs
/**
* set inputs
*/
public function setInputs()
{
$result = array();
foreach ($this->item->getOptions() as $option) {
/** @var Mage_Catalog_Model_Product_Option $option */
$inputType = $this->_mapInputType($option->getType());
$inputItem = new Shopgate_Model_Catalog_Input();
$inputItem->setUid($option->getId());
$inputItem->setType($inputType);
$inputItem->setLabel($option->getTitle());
$inputItem->setRequired($option->getIsRequire());
$inputItem->setValidation($this->_buildInputValidation($inputType, $option));
$inputItem->setSortOrder($option->getSortOrder());
/**
* add additional price for types without options
*/
switch ($inputType) {
case Shopgate_Model_Catalog_Input::DEFAULT_INPUT_TYPE_TEXT:
case Shopgate_Model_Catalog_Input::DEFAULT_INPUT_TYPE_AREA:
case Shopgate_Model_Catalog_Input::DEFAULT_INPUT_TYPE_FILE:
case Shopgate_Model_Catalog_Input::DEFAULT_INPUT_TYPE_DATE:
case Shopgate_Model_Catalog_Input::DEFAULT_INPUT_TYPE_DATETIME:
case Shopgate_Model_Catalog_Input::DEFAULT_INPUT_TYPE_TIME:
$inputItem->setAdditionalPrice($this->_getInputValuePrice($option));
break;
default:
$inputItem->setOptions($this->_buildInputOptions($option));
break;
}
$result[] = $inputItem;
}
if ($this->item->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
$result = $this->_setBundleOptions($result);
}
parent::setInputs($result);
}
示例6: hasOptions
/**
* Return true if product has options
*
* @param Mage_Catalog_Model_Product $product
* @return bool
*/
public function hasOptions($product)
{
if ($product->getOptions()) {
return true;
}
$attributes = $this->getConfigurableAttributes($product);
if (count($attributes)) {
foreach ($attributes as $attribute) {
/** @var Mage_Catalog_Model_Product_Type_Configurable_Attribute $attribute */
if ($attribute->getData('prices')) {
return true;
}
}
}
return false;
}
示例7: 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;
}
示例8: 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;
}
示例9: getProductSku
/**
* Returns product SKU for specified options set
* @param Mage_Catalog_Model_Product $Product
* @param mixed $options
* @return string
*/
public function getProductSku(Mage_Catalog_Model_Product $Product, $options = null)
{
if ($options) {
$productOptions = $Product->getOptions();
foreach ($options as $option) {
if ($ProductOption = @$productOptions[$option['option_id']]) {
$values = $ProductOption->getValues();
if (($value = $values[$option['option_value']]) && $value->getSku()) {
return $value->getSku();
}
}
}
}
return $Product->getSku();
}
示例10: checkProductBuyState
/**
* Check if product can be bought
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Catalog_Model_Product_Type_Abstract
* @throws Mage_Core_Exception
*/
public function checkProductBuyState($product)
{
if (!$product->getSkipCheckRequiredOption()) {
foreach ($product->getOptions() as $option) {
if ($option->getIsRequire()) {
$customOption = $product->getCustomOption(self::OPTION_PREFIX . $option->getId());
if (!$customOption || strlen($customOption->getValue()) == 0) {
$product->setSkipCheckRequiredOption(true);
Mage::throwException($this->_helper('Mage_Catalog_Helper_Data')->__('The product has required options'));
}
}
}
}
return $this;
}
示例11: productHasRequiredFileOption
/**
* Returns whether product has custom option of type file or not.
* (only if option is required)
*
* @param Mage_Catalog_Model_Product $product
*
* @return bool
*/
public function productHasRequiredFileOption($product)
{
$options = $product->getOptions();
foreach ($options as $option) {
/** @var $option Mage_Catalog_Model_Product_Option */
if ($option->getType() === Mage_Catalog_Model_Product_Option::OPTION_TYPE_FILE && $option->getIsRequire()) {
return true;
}
}
return false;
}