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


PHP InputException::invalidFieldValue方法代码示例

本文整理汇总了PHP中Magento\Framework\Exception\InputException::invalidFieldValue方法的典型用法代码示例。如果您正苦于以下问题:PHP InputException::invalidFieldValue方法的具体用法?PHP InputException::invalidFieldValue怎么用?PHP InputException::invalidFieldValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Exception\InputException的用法示例。


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

示例1: save

 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem)
 {
     $qty = $cartItem->getQty();
     if (!is_numeric($qty) || $qty <= 0) {
         throw InputException::invalidFieldValue('qty', $qty);
     }
     $cartId = $cartItem->getQuoteId();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     $itemId = $cartItem->getItemId();
     try {
         /** update item qty */
         if (isset($itemId)) {
             $cartItem = $quote->getItemById($itemId);
             if (!$cartItem) {
                 throw new NoSuchEntityException(__('Cart %1 doesn\'t contain item  %2', $cartId, $itemId));
             }
             $product = $this->productRepository->get($cartItem->getSku());
             $cartItem->setData('qty', $qty);
         } else {
             $product = $this->productRepository->get($cartItem->getSku());
             $quote->addProduct($product, $qty);
         }
         $this->quoteRepository->save($quote->collectTotals());
     } catch (\Exception $e) {
         if ($e instanceof NoSuchEntityException) {
             throw $e;
         }
         throw new CouldNotSaveException(__('Could not save quote'));
     }
     return $quote->getItemByProduct($product);
 }
开发者ID:nja78,项目名称:magento2,代码行数:35,代码来源:Repository.php

示例2: save

 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem)
 {
     $qty = $cartItem->getQty();
     if (!is_numeric($qty) || $qty <= 0) {
         throw InputException::invalidFieldValue('qty', $qty);
     }
     $cartId = $cartItem->getQuoteId();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     $itemId = $cartItem->getItemId();
     try {
         /** update item */
         if (isset($itemId)) {
             $item = $quote->getItemById($itemId);
             if (!$item) {
                 throw new NoSuchEntityException(__('Cart %1 doesn\'t contain item  %2', $cartId, $itemId));
             }
             $productType = $item->getProduct()->getTypeId();
             $buyRequestData = $this->getBuyRequest($productType, $cartItem);
             if (is_object($buyRequestData)) {
                 /** update item product options */
                 /** @var  \Magento\Quote\Model\Quote\Item $cartItem */
                 $cartItem = $quote->updateItem($itemId, $buyRequestData);
             } else {
                 /** update item qty */
                 $item->setData('qty', $qty);
             }
         } else {
             /** add item to shopping cart */
             $product = $this->productRepository->get($cartItem->getSku());
             $productType = $product->getTypeId();
             /** @var  \Magento\Quote\Model\Quote\Item|string $cartItem */
             $cartItem = $quote->addProduct($product, $this->getBuyRequest($productType, $cartItem));
             if (is_string($cartItem)) {
                 throw new \Magento\Framework\Exception\LocalizedException(__($cartItem));
             }
         }
         $this->quoteRepository->save($quote->collectTotals());
     } catch (\Exception $e) {
         if ($e instanceof NoSuchEntityException || $e instanceof LocalizedException) {
             throw $e;
         }
         throw new CouldNotSaveException(__('Could not save quote'));
     }
     $itemId = $cartItem->getId();
     foreach ($quote->getAllItems() as $quoteItem) {
         if ($itemId == $quoteItem->getId()) {
             $cartItem = $this->addProductOptions($productType, $quoteItem);
             return $this->applyCustomOptions($cartItem);
         }
     }
     throw new CouldNotSaveException(__('Could not save quote'));
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:57,代码来源:Repository.php

示例3: save

 /**
  * @param CartInterface $quote
  * @param CartItemInterface $item
  * @return CartItemInterface
  * @throws CouldNotSaveException
  * @throws InputException
  * @throws LocalizedException
  * @throws NoSuchEntityException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function save(CartInterface $quote, CartItemInterface $item)
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $qty = $item->getQty();
     if (!is_numeric($qty) || $qty <= 0) {
         throw InputException::invalidFieldValue('qty', $qty);
     }
     $cartId = $item->getQuoteId();
     $itemId = $item->getItemId();
     try {
         /** Update existing item */
         if (isset($itemId)) {
             $currentItem = $quote->getItemById($itemId);
             if (!$currentItem) {
                 throw new NoSuchEntityException(__('Cart %1 does not contain item %2', $cartId, $itemId));
             }
             $productType = $currentItem->getProduct()->getTypeId();
             $buyRequestData = $this->cartItemOptionProcessor->getBuyRequest($productType, $item);
             if (is_object($buyRequestData)) {
                 /** Update item product options */
                 $item = $quote->updateItem($itemId, $buyRequestData);
             } else {
                 if ($item->getQty() !== $currentItem->getQty()) {
                     $currentItem->setQty($qty);
                 }
             }
         } else {
             /** add new item to shopping cart */
             $product = $this->productRepository->get($item->getSku());
             $productType = $product->getTypeId();
             $item = $quote->addProduct($product, $this->cartItemOptionProcessor->getBuyRequest($productType, $item));
             if (is_string($item)) {
                 throw new LocalizedException(__($item));
             }
         }
     } catch (NoSuchEntityException $e) {
         throw $e;
     } catch (LocalizedException $e) {
         throw $e;
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Could not save quote'));
     }
     $itemId = $item->getId();
     foreach ($quote->getAllItems() as $quoteItem) {
         /** @var \Magento\Quote\Model\Quote\Item $quoteItem */
         if ($itemId == $quoteItem->getId()) {
             $item = $this->cartItemOptionProcessor->addProductOptions($productType, $quoteItem);
             return $this->cartItemOptionProcessor->applyCustomOptions($item);
         }
     }
     throw new CouldNotSaveException(__('Could not save quote'));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:62,代码来源:CartItemPersister.php

示例4: updateItem

 /**
  * {@inheritdoc}
  */
 public function updateItem($cartId, $itemId, \Magento\Checkout\Service\V1\Data\Cart\Item $data)
 {
     $qty = $data->getQty();
     if (!is_numeric($qty) || $qty <= 0) {
         throw InputException::invalidFieldValue('qty', $qty);
     }
     /** @var \Magento\Sales\Model\Quote $quote */
     $quote = $this->quoteRepository->get($cartId);
     $quoteItem = $quote->getItemById($itemId);
     if (!$quoteItem) {
         throw new NoSuchEntityException("Cart {$cartId} doesn't contain item  {$itemId}");
     }
     $quoteItem->setData('qty', $qty);
     try {
         $quote->collectTotals()->save();
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not update quote item');
     }
     return true;
 }
开发者ID:zhangjiachao,项目名称:magento2,代码行数:23,代码来源:WriteService.php

示例5: create

 /**
  * {@inheritdoc}
  */
 public function create($entityTypeCode, AttributeSetInterface $attributeSet, $skeletonId)
 {
     /** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
     if ($attributeSet->getId() !== null) {
         throw InputException::invalidFieldValue('id', $attributeSet->getId());
     }
     if ($skeletonId == 0) {
         throw InputException::invalidFieldValue('skeletonId', $skeletonId);
     }
     // Make sure that skeleton attribute set is valid (try to load it)
     $this->repository->get($skeletonId);
     try {
         $attributeSet->setEntityTypeId($this->eavConfig->getEntityType($entityTypeCode)->getId());
         $attributeSet->validate();
     } catch (\Exception $exception) {
         throw new InputException(__($exception->getMessage()));
     }
     $this->repository->save($attributeSet);
     $attributeSet->initFromSkeleton($skeletonId);
     return $this->repository->save($attributeSet);
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:24,代码来源:AttributeSetManagement.php

示例6: validateFrontendInput

 /**
  * Validate Frontend Input Type
  *
  * @param  string $frontendInput
  * @return void
  * @throws \Magento\Framework\Exception\InputException
  */
 protected function validateFrontendInput($frontendInput)
 {
     /** @var \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator $validator */
     $validator = $this->inputtypeValidatorFactory->create();
     if (!$validator->isValid($frontendInput)) {
         throw InputException::invalidFieldValue('frontend_input', $frontendInput);
     }
 }
开发者ID:nja78,项目名称:magento2,代码行数:15,代码来源:Repository.php

示例7: save

 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false)
 {
     if ($saveOptions) {
         $productOptions = $product->getProductOptions();
     }
     $isDeleteOptions = $product->getIsDeleteOptions();
     $tierPrices = $product->getData('tier_price');
     $productId = $this->resourceModel->getIdBySku($product->getSku());
     $ignoreLinksFlag = $product->getData('ignore_links_flag');
     $productDataArray = $this->extensibleDataObjectConverter->toNestedArray($product, [], 'Magento\\Catalog\\Api\\Data\\ProductInterface');
     $productLinks = null;
     if (!$ignoreLinksFlag && $ignoreLinksFlag !== null) {
         $productLinks = $product->getProductLinks();
     }
     $product = $this->initializeProductData($productDataArray, empty($productId));
     if (isset($productDataArray['options'])) {
         if (!empty($productDataArray['options']) || $isDeleteOptions) {
             $this->processOptions($product, $productDataArray['options']);
             $product->setCanSaveCustomOptions(true);
         }
     }
     $this->processLinks($product, $productLinks);
     if (isset($productDataArray['media_gallery_entries'])) {
         $this->processMediaGallery($product, $productDataArray['media_gallery_entries']);
     }
     $validationResult = $this->resourceModel->validate($product);
     if (true !== $validationResult) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Invalid product data: %1', implode(',', $validationResult)));
     }
     try {
         if ($saveOptions) {
             $product->setProductOptions($productOptions);
             $product->setCanSaveCustomOptions(true);
         }
         if ($tierPrices !== null) {
             $product->setData('tier_price', $tierPrices);
         }
         $this->resourceModel->save($product);
     } catch (\Magento\Eav\Model\Entity\Attribute\Exception $exception) {
         throw \Magento\Framework\Exception\InputException::invalidFieldValue($exception->getAttributeCode(), $product->getData($exception->getAttributeCode()), $exception);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Unable to save product'));
     }
     unset($this->instances[$product->getSku()]);
     unset($this->instancesById[$product->getId()]);
     return $this->get($product->getSku());
 }
开发者ID:nblair,项目名称:magescotch,代码行数:52,代码来源:ProductRepository.php

示例8: update

 /**
  * {@inheritdoc}
  */
 public function update($id, \Magento\Catalog\Service\V1\Data\Product $product)
 {
     $productModel = $this->productLoader->load($id);
     try {
         $this->productMapper->toModel($product, $productModel);
         $this->initializationHelper->initialize($productModel);
         $this->productTypeManager->processProduct($productModel);
         $productModel->validate();
         $productModel->save();
     } catch (\Magento\Eav\Model\Entity\Attribute\Exception $exception) {
         throw \Magento\Framework\Exception\InputException::invalidFieldValue($exception->getAttributeCode(), $productModel->getData($exception->getAttributeCode()), $exception);
     }
     return $productModel->getSku();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:17,代码来源:ProductService.php

示例9: remove

 /**
  * {@inheritdoc}
  */
 public function remove($attributeSetId)
 {
     $id = intval($attributeSetId);
     if (0 == $id) {
         throw InputException::invalidFieldValue('id', $id);
     }
     /** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
     $attributeSet = $this->setFactory->create()->load($id);
     $defaultAttributeSetId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getDefaultAttributeSetId();
     $loadedData = $attributeSet->getData();
     if (empty($loadedData)) {
         throw NoSuchEntityException::singleField('id', $attributeSetId);
     }
     $productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
     if ($attributeSet->getEntityTypeId() != $productEntityId) {
         throw InputException::invalidFieldValue('id', $attributeSetId);
     }
     if ($attributeSetId == $defaultAttributeSetId) {
         throw new StateException('Default attribute set can not be deleted');
     }
     $attributeSet->delete();
     return true;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:26,代码来源:WriteService.php

示例10: _verifyTaxClassModel

 /**
  * Verifies that the tax class model exists and is a customer tax class type.
  *
  * @param int $taxClassId The id of the tax class model to check
  * @param CustomerGroup $group The original group parameters
  * @return void
  * @throws InputException Thrown if the tax class model is invalid
  */
 protected function _verifyTaxClassModel($taxClassId, $group)
 {
     try {
         /* @var TaxClass $taxClassData */
         $taxClassData = $this->_taxClassService->getTaxClass($taxClassId);
     } catch (NoSuchEntityException $e) {
         throw InputException::invalidFieldValue('taxClassId', $group->getTaxClassId());
     }
     if ($taxClassData->getClassType() !== TaxClassServiceInterface::TYPE_CUSTOMER) {
         throw InputException::invalidFieldValue('taxClassId', $group->getTaxClassId());
     }
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:20,代码来源:CustomerGroupService.php

示例11: _verifyTaxClassModel

 /**
  * Verifies that the tax class model exists and is a customer tax class type.
  *
  * @param int $taxClassId The id of the tax class model to check
  * @param \Magento\Customer\Api\Data\GroupInterface $group The original group parameters
  * @return void
  * @throws InputException Thrown if the tax class model is invalid
  */
 protected function _verifyTaxClassModel($taxClassId, $group)
 {
     try {
         /* @var TaxClassInterface $taxClassData */
         $taxClassData = $this->taxClassRepository->get($taxClassId);
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         throw InputException::invalidFieldValue('taxClassId', $group->getTaxClassId());
     }
     if ($taxClassData->getClassType() !== TaxClassManagementInterface::TYPE_CUSTOMER) {
         throw InputException::invalidFieldValue('taxClassId', $group->getTaxClassId());
     }
 }
开发者ID:nja78,项目名称:magento2,代码行数:20,代码来源:GroupRepository.php

示例12: types

 /**
  * {@inheritdoc}
  */
 public function types($attributeSetId)
 {
     $attributeSet = $this->setFactory->create()->load($attributeSetId);
     if (!$attributeSet->getId()) {
         throw NoSuchEntityException::singleField('attribute_set_id', $attributeSetId);
     }
     $productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
     if ($attributeSet->getEntityTypeId() != $productEntityId) {
         throw InputException::invalidFieldValue('entity_type_id', $attributeSetId);
     }
     $collection = $this->collectionFactory->create();
     $collection->setAttributeSetFilter($attributeSetId);
     $collection->setFrontendInputTypeFilter('media_image');
     $collection->addStoreLabel($this->storeManager->getStore()->getId());
     return $this->prepareData($collection->getItems());
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:19,代码来源:ReadService.php

示例13: validateFrontendInput

 /**
  * Validate Frontend Input Type
  *
  * @param  string $frontendInput
  * @return void
  * @throws \Magento\Framework\Exception\InputException
  */
 protected function validateFrontendInput($frontendInput)
 {
     $validator = $this->inputtypeValidatorFactory->create();
     if (!$validator->isValid($frontendInput)) {
         throw InputException::invalidFieldValue('frontend_input', $frontendInput);
     }
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:14,代码来源:WriteService.php

示例14: updateTaxClass

 /**
  * {@inheritdoc}
  */
 public function updateTaxClass($taxClassId, TaxClassDataObject $taxClass)
 {
     if ($taxClass->getClassId()) {
         throw new InputException(self::CLASS_ID_NOT_ALLOWED);
     }
     $this->validateTaxClassData($taxClass);
     if (!$taxClassId) {
         throw InputException::invalidFieldValue('taxClassId', $taxClassId);
     }
     $originalTaxClassModel = $this->classModelRegistry->retrieve($taxClassId);
     $taxClassModel = $this->converter->createTaxClassModel($taxClass);
     $taxClassModel->setId($taxClassId);
     /* should not be allowed to switch the tax class type */
     if ($originalTaxClassModel->getClassType() !== $taxClassModel->getClassType()) {
         throw new InputException('Updating classType is not allowed.');
     }
     try {
         $taxClassModel->save();
     } catch (\Exception $e) {
         return false;
     }
     $this->classModelRegistry->registerTaxClass($taxClassModel);
     return true;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:27,代码来源:TaxClassService.php

示例15: save

 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false)
 {
     if ($saveOptions) {
         $productOptions = $product->getProductOptions();
     }
     $groupPrices = $product->getData('group_price');
     $tierPrices = $product->getData('tier_price');
     $productId = $this->resourceModel->getIdBySku($product->getSku());
     $productDataArray = $this->extensibleDataObjectConverter->toNestedArray($product, [], 'Magento\\Catalog\\Api\\Data\\ProductInterface');
     $product = $this->initializeProductData($productDataArray, empty($productId));
     $validationResult = $this->resourceModel->validate($product);
     if (true !== $validationResult) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Invalid product data: %1', implode(',', $validationResult)));
     }
     try {
         if ($saveOptions) {
             $product->setProductOptions($productOptions);
             $product->setCanSaveCustomOptions(true);
         }
         $product->setData('group_price', $groupPrices);
         $product->setData('tier_price', $tierPrices);
         $this->resourceModel->save($product);
     } catch (\Magento\Eav\Model\Entity\Attribute\Exception $exception) {
         throw \Magento\Framework\Exception\InputException::invalidFieldValue($exception->getAttributeCode(), $product->getData($exception->getAttributeCode()), $exception);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Unable to save product'));
     }
     unset($this->instances[$product->getSku()]);
     unset($this->instancesById[$product->getId()]);
     return $product;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:34,代码来源:ProductRepository.php


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