本文整理汇总了PHP中Mage_Catalog_Model_Product::getCustomOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::getCustomOption方法的具体用法?PHP Mage_Catalog_Model_Product::getCustomOption怎么用?PHP Mage_Catalog_Model_Product::getCustomOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::getCustomOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _applyOptionsPrice
/**
* Apply gift card amount to price
*
* @param Mage_Catalog_Model_Product $product
* @param int $qty
* @param double $finalPrice
* @return double
*/
protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
if ($product->getCustomOption('card_amount') && $product->getPrice() == 0) {
$amount = $product->getCustomOption('card_amount')->getValue();
$finalPrice += $amount;
}
return $finalPrice;
}
示例2: _applyOptionsPrice
/**
* Apply gift card amount to price
*
* @param Mage_Catalog_Model_Product $product
* @param int $qty
* @param double $finalPrice
* @return double
*/
protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
if ($product->getCustomOption('card_amount') && $product->getPrice() == 0) {
$amount = Mage::helper('directory')->currencyConvert($product->getCustomOption('card_amount')->getValue(), Mage::app()->getStore()->getCurrentCurrencyCode(), Mage::app()->getStore()->getBaseCurrency());
//$amount = $product->getCustomOption('card_amount')->getValue();
$finalPrice += $amount;
}
return $finalPrice;
}
示例3: _applyOptionsPrice
/**
* Apply options price
*
* @param Mage_Catalog_Model_Product $product
* @param int $qty
* @param double $finalPrice
* @return double
*/
protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
if ($optionIds = $product->getCustomOption('option_ids')) {
$helper = Mage::helper('mageworx_customoptions');
$basePrice = $finalPrice;
$product->setActualPrice($basePrice);
$finalPrice = 0;
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $product->getOptionById($optionId)) {
$product->setCurrentPrice($finalPrice);
$option->setProduct($product);
if ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT || $option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_TEXT) {
$quoteItemOption = $product->getCustomOption('option_' . $option->getId());
$group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
$finalPrice += $group->getOptionPrice($quoteItemOption->getValue(), $basePrice, $qty);
} else {
$price = $helper->getOptionPriceByQty($option, $qty);
if ($price != 0) {
$price = $price / $qty;
}
$finalPrice += $price;
}
}
}
$product->setBaseCustomoptionsPrice($finalPrice);
// for additional info
if (!$helper->getProductAbsolutePrice($product) || $finalPrice == 0) {
$finalPrice += $basePrice;
}
}
if (method_exists($this, '_applyOptionsPriceFME')) {
$finalPrice = $this->_applyOptionsPriceFME($product, $qty, $finalPrice);
}
return $finalPrice;
}
示例4: isVirtual
/**
* Check is virtual product
*
* @param Mage_Catalog_Model_Product $product
* @return bool
*/
public function isVirtual($product = null)
{
if (!$product) {
return false;
}
if ($product->getCustomOption('card_type')) {
$type = $product->getCustomOption('card_type')->getValue();
} else {
$type = $product->getAttributeText('wts_gc_type');
}
if ($product && $type == 'offline') {
return false;
} else {
return true;
}
}
示例5: _applyOptionsPrice
/**
* Apply options price
*
* @param Mage_Catalog_Model_Product $product
* @param int $qty
* @param double $finalPrice
* @return double
*/
protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
if ($optionIds = $product->getCustomOption('option_ids')) {
$helper = Mage::helper('customoptions');
$basePrice = $finalPrice;
$product->setActualPrice($basePrice);
$finalPrice = 0;
$post = $helper->getInfoBuyRequest($product);
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $product->getOptionById($optionId)) {
$option->setProduct($product);
$optionQty = 1;
switch ($option->getType()) {
case 'checkbox':
case 'multiswatch':
case 'hidden':
if (isset($post['options'][$optionId])) {
$optionValues = array();
$optionQtyArr = array();
foreach ($option->getValues() as $key => $itemV) {
if (isset($post['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty'])) {
$optionQty = intval($post['options_' . $optionId . '_' . $itemV->getOptionTypeId() . '_qty']);
}
$optionQtyArr[$itemV->getOptionTypeId()] = $optionQty;
}
$optionQty = $optionQtyArr;
}
break;
case 'drop_down':
case 'radio':
case 'swatch':
if (isset($post['options_' . $optionId . '_qty'])) {
$optionQty = intval($post['options_' . $optionId . '_qty']);
}
break;
}
if ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
$quoteItemOption = $product->getCustomOption('option_' . $option->getId());
$group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
$finalPrice += $group->getOptionPrice($quoteItemOption->getValue(), $basePrice, $qty, $optionQty, $product);
} else {
$price = $helper->getOptionPriceByQty($option, $qty, $product);
if ($price != 0) {
$price = $price / $qty;
}
$finalPrice += $price;
}
}
}
$product->setBaseCustomoptionsPrice($finalPrice);
// for additional info
if (!$helper->getProductAbsolutePrice($product) || $finalPrice == 0) {
$finalPrice += $basePrice;
}
}
if (method_exists($this, '_applyOptionsPriceFME')) {
$finalPrice = $this->_applyOptionsPriceFME($product, $qty, $finalPrice);
}
return $finalPrice;
}
示例6: getSelectionQty
/**
* Get selection quantity
*
* @param Mage_Catalog_Model_Product $product
* @param int $selectionId
*
* @return decimal
*/
public function getSelectionQty($product, $selectionId)
{
$selectionQty = $product->getCustomOption('selection_qty_' . $selectionId);
if ($selectionQty) {
return $selectionQty->getValue();
}
return 0;
}
示例7: getFinalPrice
/**
* Get product final price
*
* @param double $qty
* @param Mage_Catalog_Model_Product $product
* @return double
*/
public function getFinalPrice($qty = null, $product)
{
if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
return $product->getCalculatedFinalPrice();
}
$finalPrice = $product->getPrice();
if ($product->hasCustomOptions()) {
$customOption = $product->getCustomOption('bundle_option_ids');
$optionIds = unserialize($customOption->getValue());
$customOption = $product->getCustomOption('bundle_selection_ids');
$selectionIds = unserialize($customOption->getValue());
$selections = $product->getTypeInstance()->getSelectionsByIds($selectionIds);
foreach ($selections->getItems() as $selection) {
if ($selection->isSalable()) {
$selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId());
if ($selectionQty) {
$finalPrice = $finalPrice + $this->getSelectionPrice($product, $selection, $selectionQty->getValue());
}
}
}
} else {
if ($options = $this->getOptions($product)) {
/* some strange thing
foreach ($options as $option) {
$selectionCount = count($option->getSelections());
if ($selectionCount) {
foreach ($option->getSelections() as $selection) {
if ($selection->isSalable() && ($selection->getIsDefault() || ($option->getRequired() &&)) {
$finalPrice = $finalPrice + $this->getSelectionPrice($product, $selection);
}
}
}
}
*/
}
}
$finalPrice = $this->_applyTierPrice($product, $qty, $finalPrice);
$finalPrice = $this->_applySpecialPrice($product, $finalPrice);
$product->setFinalPrice($finalPrice);
Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product));
$finalPrice = $product->getData('final_price');
$finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
return max(0, $product->getData('final_price'));
}
示例8: getFinalPrice
/**
* Retrieve product final price
*
* @param integer $qty
* @param Mage_Catalog_Model_Product $product
* @return float
*/
public function getFinalPrice($qty = null, $product)
{
$finalPrice = $product->getPrice();
if ($product->hasCustomOptions()) {
$customOption = $product->getCustomOption('giftcard_amount');
if ($customOption) {
$finalPrice += $customOption->getValue();
}
}
$finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
$product->setData('final_price', $finalPrice);
return max(0, $product->getData('final_price'));
}
示例9: getTotalBundleItemsPrice
/**
* Get Total price for Bundle items
*
* @param Mage_Catalog_Model_Product $product
* @param null|float $qty
* @return float
*/
public function getTotalBundleItemsPrice($product, $qty = null)
{
$price = 0.0;
if ($product->hasCustomOptions()) {
$customOption = $product->getCustomOption('bundle_selection_ids');
if ($customOption) {
$selectionIds = unserialize($customOption->getValue());
$selections = $product->getTypeInstance(true)->getSelectionsByIds($selectionIds, $product);
$selections->addTierPriceData();
Mage::dispatchEvent('prepare_catalog_product_collection_prices', array('collection' => $selections, 'store_id' => $product->getStoreId()));
//I need to check the price base on an attribute added only to bundle type -- reservation price per product or general
//for specific product it works on add to cart but not for general
//here I use the parent or the children price base on
foreach ($selections->getItems() as $selection) {
if ($selection->isSalable()) {
$selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId());
if ($selectionQty) {
if ($selection->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE && $product->getBundlePricingtype() == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_FORALL) {
$price = 0;
if (is_object($product->getCustomOption('info_buyRequest'))) {
$source = unserialize($product->getCustomOption('info_buyRequest')->getValue());
if (!isset($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION])) {
continue;
}
$startingDate = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION];
$endingDate = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION];
$customerGroup = ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup();
$price = $qty * ITwebexperts_Payperrentals_Helper_Price::calculatePrice($product, $startingDate, $endingDate, $qty, $customerGroup);
break;
}
} else {
if ($selection->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE) {
$Product = Mage::getModel('catalog/product')->load($selection->getProductId());
if (is_object($product->getCustomOption('info_buyRequest'))) {
$source = unserialize($product->getCustomOption('info_buyRequest')->getValue());
if (isset($source['start_date']) && isset($source['end_date'])) {
$customerGroup = ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup();
$price = $price + $selectionQty->getValue() * ITwebexperts_Payperrentals_Helper_Price::calculatePrice($Product, $source['start_date'], $source['end_date'], $selectionQty, $customerGroup);
}
}
} else {
$price += $this->getSelectionFinalTotalPrice($product, $selection, $qty, $selectionQty->getValue());
}
}
}
}
}
}
}
return $price;
}
示例10: testCustomOptionsApi
/**
* @covers Mage_Catalog_Model_Product::addCustomOption
* @covers Mage_Catalog_Model_Product::setCustomOptions
* @covers Mage_Catalog_Model_Product::getCustomOptions
* @covers Mage_Catalog_Model_Product::getCustomOption
* @covers Mage_Catalog_Model_Product::hasCustomOptions
*/
public function testCustomOptionsApi()
{
$this->assertEquals(array(), $this->_model->getCustomOptions());
$this->assertFalse($this->_model->hasCustomOptions());
$this->_model->setId(99);
$this->_model->addCustomOption('one', 'value1');
$option = $this->_model->getCustomOption('one');
$this->assertInstanceOf('Varien_Object', $option);
$this->assertEquals($this->_model->getId(), $option->getProductId());
$this->assertSame($option->getProduct(), $this->_model);
$this->assertEquals('one', $option->getCode());
$this->assertEquals('value1', $option->getValue());
$this->assertEquals(array('one' => $option), $this->_model->getCustomOptions());
$this->assertTrue($this->_model->hasCustomOptions());
$this->_model->setCustomOptions(array('test'));
$this->assertTrue(is_array($this->_model->getCustomOptions()));
}
示例11: getTotalBundleItemsPrice
/**
* Get Total price for Bundle items
*
* @param Mage_Catalog_Model_Product $product
* @param null|float $qty
* @return float
*/
public function getTotalBundleItemsPrice($product, $qty = null)
{
$price = 0.0;
if ($product->hasCustomOptions()) {
$customOption = $product->getCustomOption('bundle_selection_ids');
if ($customOption) {
$selectionIds = unserialize($customOption->getValue());
$selections = $product->getTypeInstance(true)->getSelectionsByIds($selectionIds, $product);
$selections->addTierPriceData();
Mage::dispatchEvent('prepare_catalog_product_collection_prices', array('collection' => $selections, 'store_id' => $product->getStoreId()));
foreach ($selections->getItems() as $selection) {
if ($selection->isSalable()) {
$selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId());
if ($selectionQty) {
$price += $this->getSelectionFinalTotalPrice($product, $selection, $qty, $selectionQty->getValue());
}
}
}
}
}
return $price;
}
示例12: getProductSubscription
/**
* Retrieve product subscription, if product is a subscription, else false
*
* @param Mage_Catalog_Model_Product $product
* @return Adyen_Subscription_Model_Product_Subscription|false
*/
public function getProductSubscription($product)
{
if (isset($product->getAttributes()['adyen_subscription_type'])) {
if ($product->getData('adyen_subscription_type') != Adyen_Subscription_Model_Product_Subscription::TYPE_DISABLED) {
$option = $product->getCustomOption('additional_options');
if ($option) {
$additionalOptions = unserialize($option->getValue());
foreach ($additionalOptions as $additional) {
if ($additional['code'] == 'adyen_subscription') {
if ($additional['option_value'] != 'none') {
$subscription = Mage::getModel('adyen_subscription/product_subscription')->load($additional['option_value']);
if (!$subscription->getId()) {
return false;
}
return $subscription;
}
}
}
}
}
}
return false;
}
示例13: getProductSku
/**
* Since it's a bad practice to overwrite core magento abstract classes via
* copying the source in the local folder structure, this method contains the
* same code found in Mage_Catalog_Model_Product_Type_Abstract.getSku; however,
* it also includes logic to allow certain options to be disregarding from
* sku concatination.
*
* NOTE: Since we're providing the same logic here that is in the base abstract
* product type class, it is very important to check this logic during future
* magento upgrades to ensure nothing gets broken.
*
* @param Mage_Catalog_Model_Product $product
* @return string
*/
public function getProductSku($product)
{
$excludeSkus = explode(',', Mage::getConfig()->getNode(self::XML_PATH_EXCLUDE_OPTIONS_SKU));
$skuDelimiter = '-';
$sku = $product->getData('sku');
if ($optionIds = $product->getCustomOption('option_ids')) {
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $product->getOptionById($optionId)) {
// pass over options with a title contained in the config
if (in_array($option->getTitle(), $excludeSkus)) {
continue;
}
$quoteItemOption = $product->getCustomOption('option_' . $optionId);
$group = $option->groupFactory($option->getType())->setOption($option)->setListener(new Varien_Object());
if ($optionSku = $group->getOptionSku($quoteItemOption->getValue(), $skuDelimiter)) {
$sku .= $skuDelimiter . $optionSku;
}
if ($group->getListener()->getHasError()) {
$product->setHasError(true)->setMessage($group->getListener()->getMessage());
}
}
}
}
return $sku;
}
示例14: getSku
/**
* Get sku of product
*
* @param Mage_Catalog_Model_Product $product
* @return string
*/
public function getSku($product)
{
$simpleOption = $product->getCustomOption('simple_product');
if ($simpleOption) {
$optionProduct = $simpleOption->getProduct();
$simpleSku = null;
if ($optionProduct) {
$simpleSku = $simpleOption->getProduct()->getSku();
}
$sku = parent::getOptionSku($product, $simpleSku);
} else {
$sku = parent::getSku($product);
}
return $sku;
}
示例15: isVirtual
/**
* Check is virtual product
*
* @param Mage_Catalog_Model_Product $product
* @return bool
*/
public function isVirtual($product)
{
if ($product->hasCustomOptions()) {
$customOption = $product->getCustomOption('bundle_selection_ids');
$selectionIds = unserialize($customOption->getValue());
$selections = $this->getSelectionsByIds($selectionIds, $product);
$virtualCount = 0;
foreach ($selections->getItems() as $selection) {
if ($selection->isVirtual()) {
$virtualCount++;
}
}
if ($virtualCount == count($selections)) {
return true;
}
}
return false;
}