本文整理汇总了PHP中Magento\Framework\Exception\NoSuchEntityException类的典型用法代码示例。如果您正苦于以下问题:PHP NoSuchEntityException类的具体用法?PHP NoSuchEntityException怎么用?PHP NoSuchEntityException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NoSuchEntityException类的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: testConstructor
public function testConstructor()
{
$exception = new NoSuchEntityException();
$this->assertEquals('No such entity.', $exception->getRawMessage());
$this->assertEquals('No such entity.', $exception->getMessage());
$this->assertEquals('No such entity.', $exception->getLogMessage());
$exception = new NoSuchEntityException(new Phrase(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'field', 'fieldValue' => 'value']));
$this->assertEquals('No such entity with field = value', $exception->getMessage());
$this->assertEquals(NoSuchEntityException::MESSAGE_SINGLE_FIELD, $exception->getRawMessage());
$this->assertEquals('No such entity with field = value', $exception->getLogMessage());
$exception = new NoSuchEntityException(new Phrase(NoSuchEntityException::MESSAGE_DOUBLE_FIELDS, ['fieldName' => 'field1', 'fieldValue' => 'value1', 'field2Name' => 'field2', 'field2Value' => 'value2']));
$this->assertEquals(NoSuchEntityException::MESSAGE_DOUBLE_FIELDS, $exception->getRawMessage());
$this->assertEquals('No such entity with field1 = value1, field2 = value2', $exception->getMessage());
$this->assertEquals('No such entity with field1 = value1, field2 = value2', $exception->getLogMessage());
}
示例3: testConstructor
public function testConstructor()
{
$exception = new NoSuchEntityException();
$this->assertEquals('No such entity.', $exception->getRawMessage());
$this->assertEquals('No such entity.', $exception->getMessage());
$this->assertEquals('No such entity.', $exception->getLogMessage());
$exception = new NoSuchEntityException(new Phrase('No such entity with %fieldName = %fieldValue', ['fieldName' => 'field', 'fieldValue' => 'value']));
$this->assertEquals('No such entity with field = value', $exception->getMessage());
$this->assertEquals('No such entity with %fieldName = %fieldValue', $exception->getRawMessage());
$this->assertEquals('No such entity with field = value', $exception->getLogMessage());
$exception = new NoSuchEntityException(new Phrase('No such entity with %fieldName = %fieldValue, %field2Name = %field2Value', ['fieldName' => 'field1', 'fieldValue' => 'value1', 'field2Name' => 'field2', 'field2Value' => 'value2']));
$this->assertEquals('No such entity with %fieldName = %fieldValue, %field2Name = %field2Value', $exception->getRawMessage());
$this->assertEquals('No such entity with field1 = value1, field2 = value2', $exception->getMessage());
$this->assertEquals('No such entity with field1 = value1, field2 = value2', $exception->getLogMessage());
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: testDoubleField
/**
* @return void
*/
public function testDoubleField()
{
$website = 'website';
$websiteValue = 15;
$email = 'email';
$emailValue = 'example@magento.com';
NoSuchEntityException::doubleField($website, $websiteValue, $email, $emailValue);
$this->assertSame("No such entity with {$website} = {$websiteValue}, {$email} = {$emailValue}", NoSuchEntityException::doubleField($website, $websiteValue, $email, $emailValue)->getMessage());
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}