本文整理汇总了PHP中Magento\Framework\Exception\NoSuchEntityException::singleField方法的典型用法代码示例。如果您正苦于以下问题:PHP NoSuchEntityException::singleField方法的具体用法?PHP NoSuchEntityException::singleField怎么用?PHP NoSuchEntityException::singleField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Exception\NoSuchEntityException
的用法示例。
在下文中一共展示了NoSuchEntityException::singleField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterGetActiveForCustomer
/**
* Check if quote is allowed
*
* @param \Magento\Quote\Api\CartRepositoryInterface $subject
* @param \Magento\Quote\Model\Quote $quote
* @return \Magento\Quote\Model\Quote
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetActiveForCustomer(\Magento\Quote\Api\CartRepositoryInterface $subject, \Magento\Quote\Model\Quote $quote)
{
if (!$this->isAllowed($quote)) {
throw NoSuchEntityException::singleField('cartId', $quote->getId());
}
return $quote;
}
示例2: afterGetForCustomer
/**
* Check if quote is allowed
*
* @param \Magento\Sales\Model\QuoteRepository $subject
* @param \Magento\Sales\Model\Quote $quote
* @return \Magento\Sales\Model\Quote
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function afterGetForCustomer(\Magento\Sales\Model\QuoteRepository $subject, \Magento\Sales\Model\Quote $quote)
{
if (!$this->isAllowed($quote)) {
throw NoSuchEntityException::singleField('cartId', $quote->getId());
}
return $quote;
}
示例3: save
/**
* Save coupon.
*
* @param \Magento\SalesRule\Api\Data\CouponInterface $coupon
* @return \Magento\SalesRule\Api\Data\CouponInterface
* @throws \Magento\Framework\Exception\InputException If there is a problem with the input
* @throws \Magento\Framework\Exception\NoSuchEntityException If a coupon ID is sent but the coupon does not exist
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function save(\Magento\SalesRule\Api\Data\CouponInterface $coupon)
{
//if coupon id is provided, use the existing coupon and blend in the new data supplied
$couponId = $coupon->getCouponId();
if ($couponId) {
$existingCoupon = $this->getById($couponId);
$mergedData = array_merge($existingCoupon->getData(), $coupon->getData());
$coupon->setData($mergedData);
}
//blend in specific fields from the rule
try {
$rule = $this->ruleFactory->create()->load($coupon->getRuleId());
if (!$rule->getRuleId()) {
throw \Magento\Framework\Exception\NoSuchEntityException::singleField('rule_id', $coupon->getRuleId());
}
if ($rule->getCouponType() == $rule::COUPON_TYPE_NO_COUPON) {
throw new \Magento\Framework\Exception\LocalizedException(__('Specified rule does not allow coupons'));
} elseif ($rule->getUseAutoGeneration() && $coupon->getType() == $coupon::TYPE_MANUAL) {
throw new \Magento\Framework\Exception\LocalizedException(__('Specified rule only allows auto generated coupons'));
} elseif (!$rule->getUseAutoGeneration() && $coupon->getType() == $coupon::TYPE_GENERATED) {
throw new \Magento\Framework\Exception\LocalizedException(__('Specified rule does not allow auto generated coupons'));
}
$coupon->setExpirationDate($rule->getToDate());
$coupon->setUsageLimit($rule->getUsesPerCoupon());
$coupon->setUsagePerCustomer($rule->getUsesPerCustomer());
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\LocalizedException(__('Error occurred when saving coupon: %1', $e->getMessage()));
}
$this->resourceModel->save($coupon);
return $coupon;
}
示例4: aroundLoad
/**
* Checks if order is allowed
*
* @param \Magento\Sales\Model\ResourceModel\Order $subject
* @param callable $proceed
* @param \Magento\Framework\Model\AbstractModel $order
* @param mixed $value
* @param null|string $field
* @return \Magento\Sales\Model\Order
* @throws NoSuchEntityException
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundLoad(\Magento\Sales\Model\ResourceModel\Order $subject, \Closure $proceed, \Magento\Framework\Model\AbstractModel $order, $value, $field = null)
{
$result = $proceed($order, $value, $field);
if (!$this->isAllowed($order)) {
throw NoSuchEntityException::singleField('orderId', $order->getId());
}
return $result;
}
示例5: get
/**
* Get active quote by id
*
* @param int $cartId
* @param int[] $sharedStoreIds
* @throws NoSuchEntityException
* @return CartInterface
*/
public function get($cartId, array $sharedStoreIds = [])
{
$quote = parent::get($cartId, $sharedStoreIds);
if (!$quote->getIsActive()) {
throw NoSuchEntityException::singleField('cartId', $cartId);
}
return $quote;
}
示例6: get
/**
* Get cart by id
*
* @param int $cartId
* @return Quote
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function get($cartId)
{
$quote = $this->quoteFactory->create();
$quote->setStoreId($this->storeManager->getStore()->getId())->load($cartId);
if (!$quote->getId() || !$quote->getIsActive()) {
throw NoSuchEntityException::singleField('cartId', $cartId);
}
return $quote;
}
示例7: loadQuote
/**
* Load quote with different methods
*
* @param string $loadMethod
* @param string $loadField
* @param int $identifier
* @return Quote
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
protected function loadQuote($loadMethod, $loadField, $identifier)
{
$quote = $this->quoteFactory->create();
$quote->setStoreId($this->storeManager->getStore()->getId())->{$loadMethod}($identifier);
if (!$quote->getId() || !$quote->getIsActive()) {
throw NoSuchEntityException::singleField($loadField, $identifier);
}
return $quote;
}
示例8: getCategory
/**
* @param int $id
* @return CategoryModel
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
private function getCategory($id)
{
/** @var CategoryModel $category */
$category = $this->categoryFactory->create();
$category->load($id);
if (!$category->getId()) {
throw NoSuchEntityException::singleField(Category::ID, $id);
}
return $category;
}
示例9: getAttributes
/**
* {@inheritdoc}
*/
public function getAttributes($formCode)
{
$attributes = [];
$attributesFormCollection = $this->attributeMetadataDataProvider->loadAttributesCollection(AddressMetadataInterface::ENTITY_TYPE_ADDRESS, $formCode);
foreach ($attributesFormCollection as $attribute) {
$attributes[$attribute->getAttributeCode()] = $this->attributeMetadataConverter->createMetadataAttribute($attribute);
}
if (empty($attributes)) {
throw NoSuchEntityException::singleField('formCode', $formCode);
}
return $attributes;
}
示例10: retrieve
/**
* Get instance of the Group Model identified by an id
*
* @param int $groupId
* @return Group
* @throws NoSuchEntityException
*/
public function retrieve($groupId)
{
if (isset($this->registry[$groupId])) {
return $this->registry[$groupId];
}
$group = $this->groupFactory->create();
$group->load($groupId);
if (is_null($group->getId())) {
throw NoSuchEntityException::singleField('groupId', $groupId);
}
$this->registry[$groupId] = $group;
return $group;
}
示例11: retrieve
/**
* Get instance of the Address Model identified by id
*
* @param int $addressId
* @return Address
* @throws NoSuchEntityException
*/
public function retrieve($addressId)
{
if (isset($this->registry[$addressId])) {
return $this->registry[$addressId];
}
$address = $this->addressFactory->create();
$address->load($addressId);
if (!$address->getId()) {
throw NoSuchEntityException::singleField('addressId', $addressId);
}
$this->registry[$addressId] = $address;
return $address;
}
示例12: retrieveTaxRule
/**
* Retrieve TaxRule Model from registry given an id
*
* @param int $taxRuleId
* @return TaxRuleModel
* @throws NoSuchEntityException
*/
public function retrieveTaxRule($taxRuleId)
{
if (isset($this->registry[$taxRuleId])) {
return $this->registry[$taxRuleId];
}
$taxRuleModel = $this->taxRuleModelFactory->create()->load($taxRuleId);
if (!$taxRuleModel->getId()) {
// tax rule does not exist
throw NoSuchEntityException::singleField('taxRuleId', $taxRuleId);
}
$this->registry[$taxRuleModel->getId()] = $taxRuleModel;
return $taxRuleModel;
}
示例13: retrieve
/**
* Get instance of the Demo Model identified by an id
*
* @param int $demoId
* @return Demo
* @throws NoSuchEntityException
*/
public function retrieve($demoId)
{
if (isset($this->registry[$demoId])) {
return $this->registry[$demoId];
}
$demo = $this->demoFactory->create();
$demo->load($demoId);
if ($demo->getId() === null || $demo->getId() != $demoId) {
throw NoSuchEntityException::singleField(DemoInterface::ID, $demoId);
}
$this->registry[$demoId] = $demo;
return $demo;
}
示例14: retrieve
/**
* Get instance of the Group Model identified by an id
*
* @param int $groupId
* @return Group
* @throws NoSuchEntityException
*/
public function retrieve($groupId)
{
if (isset($this->registry[$groupId])) {
return $this->registry[$groupId];
}
$group = $this->groupFactory->create();
$group->load($groupId);
if ($group->getId() === null || $group->getId() != $groupId) {
throw NoSuchEntityException::singleField(GroupInterface::ID, $groupId);
}
$this->registry[$groupId] = $group;
return $group;
}
示例15: getAttributes
/**
* {@inheritdoc}
*/
public function getAttributes($formCode)
{
$attributes = [];
$attributesFormCollection = $this->attributeMetadataDataProvider->loadAttributesCollection(self::ENTITY_TYPE_CUSTOMER, $formCode);
foreach ($attributesFormCollection as $attribute) {
/** @var $attribute \Magento\Customer\Model\Attribute */
$attributes[$attribute->getAttributeCode()] = $this->attributeMetadataConverter->createMetadataAttribute($attribute);
}
if (empty($attributes)) {
throw NoSuchEntityException::singleField('formCode', $formCode);
}
return $attributes;
}