當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Product::getCustomOption方法代碼示例

本文整理匯總了PHP中Magento\Catalog\Model\Product::getCustomOption方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::getCustomOption方法的具體用法?PHP Product::getCustomOption怎麽用?PHP Product::getCustomOption使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Catalog\Model\Product的用法示例。


在下文中一共展示了Product::getCustomOption方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getFinalPrice

 /**
  * Get product final price
  *
  * @param   float $qty
  * @param   \Magento\Catalog\Model\Product $product
  * @return  float
  */
 public function getFinalPrice($qty, $product)
 {
     if ($qty === null && $product->getCalculatedFinalPrice() !== null) {
         return $product->getCalculatedFinalPrice();
     }
     if ($product->getCustomOption('simple_product')) {
         $product->setSelectedConfigurableOption($product->getCustomOption('simple_product')->getProduct());
     }
     //TODO: MAGETWO-23739 catalogrule price must get from simple product.
     $finalPrice = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue();
     $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
     $finalPrice = max(0, $finalPrice);
     $product->setFinalPrice($finalPrice);
     return $finalPrice;
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:22,代碼來源:Price.php

示例2: getFinalPrice

 /**
  * Get product final price
  *
  * @param   float $qty
  * @param   \Magento\Catalog\Model\Product $product
  * @return  float
  */
 public function getFinalPrice($qty, $product)
 {
     if ($qty === null && $product->getCalculatedFinalPrice() !== null) {
         return $product->getCalculatedFinalPrice();
     }
     if ($product->getCustomOption('simple_product') && $product->getCustomOption('simple_product')->getProduct()) {
         $finalPrice = parent::getFinalPrice($qty, $product->getCustomOption('simple_product')->getProduct());
     } else {
         $priceInfo = $product->getPriceInfo();
         $finalPrice = $priceInfo->getPrice('final_price')->getAmount()->getValue();
     }
     $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
     $finalPrice = max(0, $finalPrice);
     $product->setFinalPrice($finalPrice);
     return $finalPrice;
 }
開發者ID:koliaGI,項目名稱:magento2,代碼行數:23,代碼來源:Price.php

示例3: getSelectionQty

 /**
  * Get selection quantity
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param int $selectionId
  * @return float
  */
 public function getSelectionQty(\Magento\Catalog\Model\Product $product, $selectionId)
 {
     $selectionQty = $product->getCustomOption('selection_qty_' . $selectionId);
     if ($selectionQty) {
         return $selectionQty->getValue();
     }
     return 0;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:15,代碼來源:Configuration.php

示例4: getSelectionQty

 /**
  * Get selection quantity
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param int $selectionId
  *
  * @return float
  */
 public function getSelectionQty($product, $selectionId)
 {
     $selectionQty = $product->getCustomOption('selection_qty_' . $selectionId);
     if ($selectionQty) {
         return $selectionQty->getValue();
     }
     return 0;
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:16,代碼來源:Configuration.php

示例5: testCustomOptionsApi

 /**
  * @covers \Magento\Catalog\Model\Product::addCustomOption
  * @covers \Magento\Catalog\Model\Product::setCustomOptions
  * @covers \Magento\Catalog\Model\Product::getCustomOptions
  * @covers \Magento\Catalog\Model\Product::getCustomOption
  * @covers \Magento\Catalog\Model\Product::hasCustomOptions
  */
 public function testCustomOptionsApi()
 {
     $this->assertEquals([], $this->_model->getCustomOptions());
     $this->assertFalse($this->_model->hasCustomOptions());
     $this->_model->setId(99);
     $this->_model->addCustomOption('one', 'value1');
     $option = $this->_model->getCustomOption('one');
     $this->assertInstanceOf('Magento\\Framework\\DataObject', $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(['one' => $option], $this->_model->getCustomOptions());
     $this->assertTrue($this->_model->hasCustomOptions());
     $this->_model->setCustomOptions(['test']);
     $this->assertTrue(is_array($this->_model->getCustomOptions()));
 }
開發者ID:BlackIkeEagle,項目名稱:magento2-continuousphp,代碼行數:24,代碼來源:ProductExternalTest.php

示例6: getSku

 /**
  * Get sku of product
  *
  * @param  \Magento\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;
 }
開發者ID:niranjanssiet,項目名稱:magento2,代碼行數:21,代碼來源:Configurable.php

示例7: _applyOptionsPrice

 /**
  * Apply options price
  *
  * @param Product $product
  * @param int $qty
  * @param float $finalPrice
  * @return float
  * @deprecated (MAGETWO-31469)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     $optionIds = $product->getCustomOption('option_ids');
     if ($optionIds) {
         $basePrice = $finalPrice;
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $product->getOptionById($optionId)) {
                 $confItemOption = $product->getCustomOption('option_' . $option->getId());
                 $group = $option->groupFactory($option->getType())->setOption($option)->setConfigurationItemOption($confItemOption);
                 $finalPrice += $group->getOptionPrice($confItemOption->getValue(), $basePrice);
             }
         }
     }
     return $finalPrice;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:25,代碼來源:Price.php

示例8: getBeforeQty

 /**
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\DataObject $selection
  * @return float|int
  */
 protected function getBeforeQty($product, $selection)
 {
     $beforeQty = 0;
     $customOption = $product->getCustomOption('product_qty_' . $selection->getId());
     if ($customOption && $customOption->getProduct()->getId() == $selection->getId()) {
         $beforeQty = (double) $customOption->getValue();
         return $beforeQty;
     }
     return $beforeQty;
 }
開發者ID:rafaelstz,項目名稱:magento2,代碼行數:15,代碼來源:Type.php

示例9: getTotalBundleItemsPrice

 /**
  * Get Total price  for Bundle items
  *
  * @param \Magento\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()->getSelectionsByIds($selectionIds, $product);
             $selections->addTierPriceData();
             $this->_eventManager->dispatch('prepare_catalog_product_collection_prices', ['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;
 }
開發者ID:opexsw,項目名稱:magento2,代碼行數:29,代碼來源:Price.php

示例10: getBundleSelectionIds

 /**
  * Retrieve array of bundle selection IDs
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return array
  */
 protected function getBundleSelectionIds(\Magento\Catalog\Model\Product $product)
 {
     $customOption = $product->getCustomOption('bundle_selection_ids');
     if ($customOption) {
         $selectionIds = unserialize($customOption->getValue());
         if (!empty($selectionIds) && is_array($selectionIds)) {
             return $selectionIds;
         }
     }
     return [];
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:17,代碼來源:Price.php

示例11: getOptionSku

 /**
  * Default action to get sku of product with option
  *
  * @param \Magento\Catalog\Model\Product $product Product with Custom Options
  * @param string $sku Product SKU without option
  * @return string
  */
 public function getOptionSku($product, $sku = '')
 {
     $skuDelimiter = '-';
     if (empty($sku)) {
         $sku = $product->getData('sku');
     }
     $optionIds = $product->getCustomOption('option_ids');
     if ($optionIds) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             $option = $product->getOptionById($optionId);
             if ($option) {
                 $confItemOption = $product->getCustomOption(self::OPTION_PREFIX . $optionId);
                 $group = $option->groupFactory($option->getType())->setOption($option)->setListener(new \Magento\Framework\DataObject());
                 $optionSku = $group->getOptionSku($confItemOption->getValue(), $skuDelimiter);
                 if ($optionSku) {
                     $sku .= $skuDelimiter . $optionSku;
                 }
                 if ($group->getListener()->getHasError()) {
                     $product->setHasError(true)->setMessage($group->getListener()->getMessage());
                 }
             }
         }
     }
     return $sku;
 }
開發者ID:koliaGI,項目名稱:magento2,代碼行數:32,代碼來源:AbstractType.php

示例12: isVirtual

 /**
  * Check is virtual product
  *
  * @param \Magento\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;
 }
開發者ID:zhangjiachao,項目名稱:magento2,代碼行數:24,代碼來源:Type.php

示例13: getCustomOption

 /**
  * {@inheritdoc}
  */
 public function getCustomOption($code)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getCustomOption');
     if (!$pluginInfo) {
         return parent::getCustomOption($code);
     } else {
         return $this->___callPlugins('getCustomOption', func_get_args(), $pluginInfo);
     }
 }
開發者ID:dragonsword007008,項目名稱:magento2,代碼行數:12,代碼來源:Interceptor.php

示例14: importProduct

 /**
  * Import product recurring payment information
  * Returns false if it cannot be imported
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this|false
  */
 public function importProduct(\Magento\Catalog\Model\Product $product)
 {
     if ($product->getIsRecurring() && is_array($product->getRecurringPayment())) {
         // import recurring payment data
         $this->addData($product->getRecurringPayment());
         // automatically set product name if there is no schedule description
         if (!$this->hasScheduleDescription()) {
             $this->setScheduleDescription($product->getName());
         }
         // collect start datetime from the product options
         $options = $product->getCustomOption(self::PRODUCT_OPTIONS_KEY);
         if ($options) {
             $options = unserialize($options->getValue());
             if (is_array($options)) {
                 if (isset($options['start_datetime'])) {
                     $startDatetime = new \Magento\Framework\Stdlib\DateTime\Date($options['start_datetime'], \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
                     $this->setNearestStartDatetime($startDatetime);
                 }
             }
         }
         return $this->_filterValues();
     }
     return false;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:31,代碼來源:RecurringPayment.php


注:本文中的Magento\Catalog\Model\Product::getCustomOption方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。