本文整理汇总了PHP中Magento\Catalog\Model\Product\Option类的典型用法代码示例。如果您正苦于以下问题:PHP Option类的具体用法?PHP Option怎么用?PHP Option使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Option类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: duplicate
/**
* Duplicate custom options for product
*
* @param \Magento\Catalog\Model\Product\Option $object
* @param int $oldProductId
* @param int $newProductId
* @return \Magento\Catalog\Model\Product\Option
*/
public function duplicate(\Magento\Catalog\Model\Product\Option $object, $oldProductId, $newProductId)
{
$connection = $this->getConnection();
$optionsCond = [];
$optionsData = [];
// read and prepare original product options
$select = $connection->select()->from($this->getTable('catalog_product_option'))->where('product_id = ?', $oldProductId);
$query = $connection->query($select);
while ($row = $query->fetch()) {
$optionsData[$row['option_id']] = $row;
$optionsData[$row['option_id']]['product_id'] = $newProductId;
unset($optionsData[$row['option_id']]['option_id']);
}
// insert options to duplicated product
foreach ($optionsData as $oId => $data) {
$connection->insert($this->getMainTable(), $data);
$optionsCond[$oId] = $connection->lastInsertId($this->getMainTable());
}
// copy options prefs
foreach ($optionsCond as $oldOptionId => $newOptionId) {
// title
$table = $this->getTable('catalog_product_option_title');
$select = $this->getConnection()->select()->from($table, [new \Zend_Db_Expr($newOptionId), 'store_id', 'title'])->where('option_id = ?', $oldOptionId);
$insertSelect = $connection->insertFromSelect($select, $table, ['option_id', 'store_id', 'title'], \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE);
$connection->query($insertSelect);
// price
$table = $this->getTable('catalog_product_option_price');
$select = $connection->select()->from($table, [new \Zend_Db_Expr($newOptionId), 'store_id', 'price', 'price_type'])->where('option_id = ?', $oldOptionId);
$insertSelect = $connection->insertFromSelect($select, $table, ['option_id', 'store_id', 'price', 'price_type'], \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE);
$connection->query($insertSelect);
$object->getValueInstance()->duplicate($oldOptionId, $newOptionId);
}
return $object;
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:42,代码来源:Option.php
示例17: getValuesCollection
/**
* Enter description here...
*
* @param Option $option
* @return \Magento\Catalog\Model\Resource\Product\Option\Value\Collection
*/
public function getValuesCollection(Option $option)
{
$collection = $this->_valueCollectionFactory->create()->addFieldToFilter('option_id', $option->getId())->getValues($option->getStoreId());
return $collection;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:11,代码来源:Value.php
示例18: validate
/**
* @param \Magento\Framework\Object $processingParams
* @param \Magento\Catalog\Model\Product\Option $option
* @return array
* @throws LocalizedException
* @throws ProductException
* @throws \Exception
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Validator\Exception
* @throws \Zend_File_Transfer_Exception
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function validate($processingParams, $option)
{
$upload = $this->httpFactory->create();
$file = $processingParams->getFilesPrefix() . 'options_' . $option->getId() . '_file';
try {
$runValidation = $option->getIsRequire() || $upload->isUploaded($file);
if (!$runValidation) {
throw new \Magento\Framework\Validator\Exception(__('Validation failed. Required options were not filled or file was not uploaded.'));
}
$fileInfo = $upload->getFileInfo($file)[$file];
$fileInfo['title'] = $fileInfo['name'];
} catch (\Magento\Framework\Validator\Exception $e) {
throw $e;
} catch (\Exception $e) {
// when file exceeds the upload_max_filesize, $_FILES is empty
if ($this->validateContentLength()) {
$value = $this->fileSize->getMaxFileSizeInMb();
throw new LocalizedException(__('The file you uploaded is larger than %1 Megabytes allowed by server', $value));
} else {
throw new ProductException(__('Option required.'));
}
}
/**
* Option Validations
*/
$upload = $this->buildImageValidator($upload, $option);
/**
* Upload process
*/
$this->initFilesystem();
$userValue = [];
if ($upload->isUploaded($file) && $upload->isValid($file)) {
$extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
$fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($fileInfo['name']);
$dispersion = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
$filePath = $dispersion;
$tmpDirectory = $this->filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
$fileHash = md5($tmpDirectory->readFile($tmpDirectory->getRelativePath($fileInfo['tmp_name'])));
$filePath .= '/' . $fileHash . '.' . $extension;
$fileFullPath = $this->mediaDirectory->getAbsolutePath($this->quotePath . $filePath);
$upload->addFilter(new \Zend_Filter_File_Rename(['target' => $fileFullPath, 'overwrite' => true]));
if ($this->product !== null) {
$this->product->getTypeInstance()->addFileQueue(['operation' => 'receive_uploaded_file', 'src_name' => $file, 'dst_name' => $fileFullPath, 'uploader' => $upload, 'option' => $this]);
}
$_width = 0;
$_height = 0;
if ($tmpDirectory->isReadable($tmpDirectory->getRelativePath($fileInfo['tmp_name']))) {
$imageSize = getimagesize($fileInfo['tmp_name']);
if ($imageSize) {
$_width = $imageSize[0];
$_height = $imageSize[1];
}
}
$uri = $this->filesystem->getUri(DirectoryList::MEDIA);
$userValue = ['type' => $fileInfo['type'], 'title' => $fileInfo['name'], 'quote_path' => $uri . $this->quotePath . $filePath, 'order_path' => $uri . $this->orderPath . $filePath, 'fullpath' => $fileFullPath, 'size' => $fileInfo['size'], 'width' => $_width, 'height' => $_height, 'secret_key' => substr($fileHash, 0, 20)];
} elseif ($upload->getErrors()) {
$errors = $this->getValidatorErrors($upload->getErrors(), $fileInfo, $option);
if (count($errors) > 0) {
throw new LocalizedException(__(implode("\n", $errors)));
}
} else {
throw new LocalizedException(__('Please specify the product\'s required option(s).'));
}
return $userValue;
}
开发者ID:opexsw,项目名称:magento2,代码行数:78,代码来源:ValidatorFile.php
示例19: getCustomAttributes
/**
* {@inheritdoc}
*/
protected function getCustomAttributes(\Magento\Catalog\Model\Product\Option $option)
{
return [Metadata::FILE_EXTENSION => $option->getFileExtension(), Metadata::IMAGE_SIZE_X => $option->getImageSizeX(), Metadata::IMAGE_SIZE_Y => $option->getImageSizeY()];
}
开发者ID:aiesh,项目名称:magento2,代码行数:7,代码来源:File.php
示例20: getSearchableData
/**
* Retrieve additional searchable data from type instance
* Using based on product id and store_id data
*
* @param \Magento\Catalog\Model\Product $product
* @return array
*/
public function getSearchableData($product)
{
$searchData = [];
if ($product->getHasOptions()) {
$searchData = $this->_catalogProductOption->getSearchableData($product->getEntityId(), $product->getStoreId());
}
return $searchData;
}
开发者ID:koliaGI,项目名称:magento2,代码行数:15,代码来源:AbstractType.php
注:本文中的Magento\Catalog\Model\Product\Option类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论