当前位置: 首页>>代码示例>>PHP>>正文


PHP Product\Option类代码示例

本文整理汇总了PHP中Magento\Catalog\Model\Product\Option的典型用法代码示例。如果您正苦于以下问题:PHP Option类的具体用法?PHP Option怎么用?PHP Option使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Option类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: read

 /**
  * {@inheritdoc}
  */
 public function read(\Magento\Catalog\Model\Product\Option $option)
 {
     $fields = [Metadata::PRICE => $option->getPrice(), Metadata::PRICE_TYPE => $option->getPriceType(), Metadata::SKU => $option->getSku()];
     $fields = array_merge($fields, $this->getCustomAttributes($option));
     $value = $this->valueBuilder->populateWithArray($fields)->create();
     return [$value];
 }
开发者ID:aiesh,项目名称:magento2,代码行数:10,代码来源:DefaultReader.php

示例2: _prepareLayout

 /**
  * Prepare item info
  *
  * @return void
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     $this->_shouldRenderInfo = true;
     $key = 'order_item_info';
     foreach (array('name' => __('Product Name'), 'sku' => __('SKU'), 'qty' => __('Quantity')) as $itemKey => $label) {
         $value = $this->_recurringPayment->getInfoValue($key, $itemKey);
         if ($value) {
             $this->_addInfo(array('label' => $label, 'value' => $value));
         }
     }
     $request = $this->_recurringPayment->getInfoValue($key, 'info_buyRequest');
     if (empty($request)) {
         return;
     }
     $request = unserialize($request);
     if (empty($request['options'])) {
         return;
     }
     $options = $this->_option->getCollection()->addIdsToFilter(array_keys($request['options']))->addTitleToResult($this->_recurringPayment->getInfoValue($key, 'store_id'))->addValuesToResult();
     foreach ($options as $option) {
         $quoteItemOption = $this->_quoteItemOptionFactory->create()->setId($option->getId());
         $group = $option->groupFactory($option->getType())->setOption($option)->setRequest(new \Magento\Framework\Object($request))->setProduct($this->_product)->setUseQuotePath(true)->setQuoteItemOption($quoteItemOption)->validateUserValue($request['options']);
         $skipHtmlEscaping = false;
         if ('file' == $option->getType()) {
             $skipHtmlEscaping = true;
             $downloadParams = array('id' => $this->_recurringPayment->getId(), 'option_id' => $option->getId(), 'key' => $request['options'][$option->getId()]['secret_key']);
             $group->setCustomOptionDownloadUrl('sales/download/downloadProfileCustomOption')->setCustomOptionUrlParams($downloadParams);
         }
         $optionValue = $group->prepareForCart();
         $this->_addInfo(array('label' => $option->getTitle(), 'value' => $group->getFormattedOptionValue($optionValue), 'skip_html_escaping' => $skipHtmlEscaping));
     }
 }
开发者ID:aiesh,项目名称:magento2,代码行数:38,代码来源:Item.php

示例3: getOptionHtml

 /**
  * Get option html block
  *
  * @param \Magento\Catalog\Model\Product\Option $option
  *
  * @return string
  */
 public function getOptionHtml(\Magento\Catalog\Model\Product\Option $option)
 {
     $type = $this->getGroupOfOption($option->getType());
     $renderer = $this->getChildBlock($type);
     $renderer->setSkipJsReloadPrice(1)->setProduct($this->getProduct())->setOption($option);
     return $this->getChildHtml($type, false);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:14,代码来源:Options.php

示例4: read

 /**
  * {@inheritdoc}
  */
 public function read(\Magento\Catalog\Model\Product\Option $option)
 {
     $output = [];
     foreach ($option->getValues() as $value) {
         $output[] = $this->metadataBuilder->populateWithArray([Metadata::PRICE => $value->getPrice(), Metadata::PRICE_TYPE => $value->getPriceType(), Metadata::SKU => $value->getSku(), Metadata::TITLE => $value->getTitle(), Metadata::SORT_ORDER => $value->getSortOrder(), Metadata::OPTION_TYPE_ID => $value->getId()])->create();
     }
     return $output;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:11,代码来源:Select.php

示例5: testValidateWithInvalidFile

 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage The file 'File Title' for 'Option Title' has an invalid extension.
  */
 public function testValidateWithInvalidFile()
 {
     $relativePath = '/custom_options/quote/file';
     $optionValues = ['quote_path' => '/custom_options/quote/file', 'title' => 'File Title'];
     $this->prepare();
     $this->directoryRead->expects($this->once())->method('isReadable')->with($relativePath)->willReturn(false);
     $this->option->expects($this->once())->method('getTitle')->willReturn('Option Title');
     $this->zendValidator->expects($this->at(2))->method('getErrors')->willReturn(true);
     $this->zendValidator->expects($this->at(3))->method('getErrors')->willReturn([\Zend_Validate_File_ExcludeExtension::FALSE_EXTENSION]);
     $this->validator->validate($optionValues, $this->option);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:ValidatorTest.php

示例6: testSave

 /**
  *  Test for `save` method
  */
 public function testSave()
 {
     $this->imageCache->expects($this->once())->method('generate')->with($this->model);
     $this->imageCacheFactory->expects($this->once())->method('create')->willReturn($this->imageCache);
     $this->model->setIsDuplicate(false);
     $this->configureSaveTest();
     $this->optionInstanceMock->expects($this->any())->method('setProduct')->will($this->returnSelf());
     $this->optionInstanceMock->expects($this->once())->method('saveOptions')->will($this->returnSelf());
     $this->model->beforeSave();
     $this->model->afterSave();
 }
开发者ID:opexsw,项目名称:magento2,代码行数:14,代码来源:ProductTest.php

示例7: validateOptionValue

 /**
  * Validate option type fields
  *
  * @param Option $option
  * @return bool
  */
 protected function validateOptionValue(Option $option)
 {
     $values = $option->getData('values');
     if (!is_array($values) || $this->isEmpty($values)) {
         return false;
     }
     //forbid removal of last value for option
     if ($this->checkAllValuesRemoved($values)) {
         return false;
     }
     foreach ($option->getData('values') as $value) {
         $type = isset($value['price_type']) ? $value['price_type'] : '';
         $price = isset($value['price']) ? $value['price'] : 0;
         $title = isset($value['title']) ? $value['title'] : '';
         if (!$this->isInRange($type, $this->priceTypes) || $this->isNegative($price) || $this->isEmpty($title)) {
             return false;
         }
     }
     return true;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:26,代码来源:Select.php

示例8: validateOptionValue

 /**
  * Validate option type fields
  *
  * @param Option $option
  * @return bool
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function validateOptionValue(Option $option)
 {
     $values = $option->getValues() ?: $option->getData('values');
     if (!is_array($values) || $this->isEmpty($values)) {
         return false;
     }
     //forbid removal of last value for option
     if ($this->checkAllValuesRemoved($values)) {
         return false;
     }
     $storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID;
     if ($option->getProduct()) {
         $storeId = $option->getProduct()->getStoreId();
     }
     foreach ($values as $value) {
         $type = isset($value['price_type']) ? $value['price_type'] : null;
         $price = isset($value['price']) ? $value['price'] : null;
         $title = isset($value['title']) ? $value['title'] : null;
         if (!$this->isValidOptionPrice($type, $price, $storeId) || !$this->isValidOptionTitle($title, $storeId)) {
             return false;
         }
     }
     return true;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:32,代码来源:Select.php

示例9: testExecuteBadSecretKey

 public function testExecuteBadSecretKey()
 {
     $this->itemOptionMock->expects($this->once())->method('load')->willReturnSelf();
     $this->itemOptionMock->expects($this->once())->method('getId')->willReturn(self::OPTION_ID);
     $this->itemOptionMock->expects($this->any())->method('getCode')->willReturn(self::OPTION_CODE);
     $this->itemOptionMock->expects($this->any())->method('getProductId')->willReturn(self::OPTION_PRODUCT_ID);
     $this->itemOptionMock->expects($this->any())->method('getValue')->willReturn(self::OPTION_VALUE);
     $this->productOptionMock->expects($this->once())->method('load')->willReturnSelf();
     $this->productOptionMock->expects($this->any())->method('getId')->willReturn(self::OPTION_ID);
     $this->productOptionMock->expects($this->any())->method('getProductId')->willReturn(self::OPTION_PRODUCT_ID);
     $this->productOptionMock->expects($this->any())->method('getType')->willReturn(self::OPTION_TYPE);
     $this->unserializeMock->expects($this->once())->method('unserialize')->with(self::OPTION_VALUE)->willReturn([self::SECRET_KEY => 'bad_test_secret_key']);
     $this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturn(true);
     $this->objectMock->execute();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:DownloadCustomOptionTest.php

示例10: testGetRegularPrice

 public function testGetRegularPrice()
 {
     $priceInfoMock = $this->getMockForAbstractClass('Magento\\Framework\\Pricing\\PriceInfoInterface', [], '', false, false, true, ['getAmount', 'getPrice']);
     $priceInfoMock->expects($this->once())->method('getPrice')->willReturnSelf();
     $amountMock = $this->getMockForAbstractClass('Magento\\Framework\\Pricing\\Amount\\AmountInterface');
     $priceInfoMock->expects($this->once())->method('getAmount')->willReturn($amountMock);
     $this->productMock->expects($this->once())->method('getPriceInfo')->willReturn($priceInfoMock);
     $amountMock->expects($this->once())->method('getValue')->willReturn(50);
     $this->model->setPrice(50);
     $this->model->setPriceType(\Magento\Catalog\Model\Product\Option\Value::TYPE_PERCENT);
     $this->assertEquals(25, $this->model->getRegularPrice());
     $this->model->setPriceType(null);
     $this->assertEquals(50, $this->model->getRegularPrice());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:14,代码来源:OptionTest.php

示例11: buildImageValidator

 /**
  * @param \Zend_File_Transfer_Adapter_Http|\Zend_Validate $object
  * @param \Magento\Catalog\Model\Product\Option $option
  * @param array $fileFullPath
  * @return \Zend_File_Transfer_Adapter_Http|\Zend_Validate $object
  * @throws \Magento\Framework\Exception\InputException
  */
 protected function buildImageValidator($object, $option, $fileFullPath = null)
 {
     $dimensions = [];
     if ($option->getImageSizeX() > 0) {
         $dimensions['maxwidth'] = $option->getImageSizeX();
     }
     if ($option->getImageSizeY() > 0) {
         $dimensions['maxheight'] = $option->getImageSizeY();
     }
     if (count($dimensions) > 0) {
         if ($fileFullPath !== null && !$this->isImage($fileFullPath)) {
             throw new \Magento\Framework\Exception\InputException(__('File \'%1\' is not an image.', $option->getTitle()));
         }
         $object->addValidator(new \Zend_Validate_File_ImageSize($dimensions));
     }
     // File extension
     $allowed = $this->parseExtensionsString($option->getFileExtension());
     if ($allowed !== null) {
         $object->addValidator(new \Zend_Validate_File_Extension($allowed));
     } else {
         $forbidden = $this->parseExtensionsString($this->getConfigData('forbidden_extensions'));
         if ($forbidden !== null) {
             $object->addValidator(new \Zend_Validate_File_ExcludeExtension($forbidden));
         }
     }
     $object->addValidator(new \Zend_Validate_File_FilesSize(['max' => $this->fileSize->getMaxFileSize()]));
     return $object;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:35,代码来源:Validator.php

示例12: _createOptionDataObject

 /**
  * Create option data object
  *
  * @param \Magento\Catalog\Model\Product\Option $option
  * @return \Magento\Catalog\Service\V1\Product\CustomOptions\Data\Option array
  */
 protected function _createOptionDataObject(\Magento\Catalog\Model\Product\Option $option)
 {
     $data = array(Data\Option::OPTION_ID => $option->getId(), Data\Option::TITLE => $option->getTitle(), Data\Option::TYPE => $option->getType(), Data\Option::IS_REQUIRE => $option->getIsRequire(), Data\Option::SORT_ORDER => $option->getSortOrder(), Data\Option::METADATA => $this->optionMetadataReader->read($option));
     return $this->optionBuilder->populateWithArray($data)->create();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:11,代码来源:ReadService.php

示例13: getCustomAttributes

 /**
  * {@inheritdoc}
  */
 protected function getCustomAttributes(\Magento\Catalog\Model\Product\Option $option)
 {
     return [Metadata::MAX_CHARACTERS => $option->getMaxCharacters()];
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:7,代码来源:Text.php

示例14: validateOptionValue

 /**
  * Validate option type fields
  *
  * @param Option $option
  * @return bool
  */
 protected function validateOptionValue(Option $option)
 {
     return $this->isInRange($option->getPriceType(), $this->priceTypes) && !$this->isNegative($option->getPrice());
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:10,代码来源:DefaultValidator.php

示例15: getOptionValues

 /**
  * Retrieve option values or false for options which has no values
  *
  * @param \Magento\Catalog\Model\Product\Option $option
  * @return array|bool
  */
 protected function getOptionValues(\Magento\Catalog\Model\Product\Option $option)
 {
     $values = $option->getValues();
     if (!empty($values)) {
         $result = [];
         /** @var $value \Magento\Catalog\Model\Product\Option\Value */
         foreach ($values as $value) {
             $optionData = [];
             foreach ($this->_assertOptionValues as $assertKey) {
                 if ($value->hasData($assertKey)) {
                     $optionData[$assertKey] = $value->getData($assertKey);
                 }
             }
             $result[] = $optionData;
         }
         return $result;
     }
     return false;
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:25,代码来源:ProductTest.php


注:本文中的Magento\Catalog\Model\Product\Option类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。