本文整理汇总了PHP中Magento\Framework\Exception\NoSuchEntityException类的典型用法代码示例。如果您正苦于以下问题:PHP NoSuchEntityException类的具体用法?PHP NoSuchEntityException怎么用?PHP NoSuchEntityException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NoSuchEntityException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:16,代码来源:Authorization.php
示例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());
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:NoSuchEntityExceptionTest.php
示例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());
}
开发者ID:Doability,项目名称:magento2dev,代码行数:15,代码来源:NoSuchEntityExceptionTest.php
示例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;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:40,代码来源:CouponRepository.php
示例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;
}
开发者ID:zhangjiachao,项目名称:magento2,代码行数:15,代码来源:Authorization.php
示例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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:20,代码来源:Authorization.php
示例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;
}
开发者ID:luo3555,项目名称:magento2-samples,代码行数:16,代码来源:QuoteRepository.php
示例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;
}
开发者ID:zhangjiachao,项目名称:magento2,代码行数:18,代码来源:QuoteRepository.php
示例9: testDoubleField
/**
* @return void
*/
public function testDoubleField()
{
$website = 'website';
$websiteValue = 15;
$email = 'email';
$emailValue = '[email protected]';
NoSuchEntityException::doubleField($website, $websiteValue, $email, $emailValue);
$this->assertSame("No such entity with {$website} = {$websiteValue}, {$email} = {$emailValue}", NoSuchEntityException::doubleField($website, $websiteValue, $email, $emailValue)->getMessage());
}
开发者ID:Doability,项目名称:magento2dev,代码行数:12,代码来源:NoSuchEntityExceptionTest.php
示例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;
}
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:16,代码来源:QuoteRepository.php
示例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;
}
开发者ID:aiesh,项目名称:magento2,代码行数:15,代码来源:ReadService.php
示例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;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:15,代码来源:AddressMetadata.php
示例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;
}
开发者ID:aiesh,项目名称:magento2,代码行数:20,代码来源:GroupRegistry.php
示例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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:20,代码来源:AddressRegistry.php
示例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;
}
开发者ID:aiesh,项目名称:magento2,代码行数:20,代码来源:TaxRuleRegistry.php
示例16: 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;
}
开发者ID:itmyprofession,项目名称:M2_Sample,代码行数:20,代码来源:DemoRegistry.php
示例17: 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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:20,代码来源:GroupRegistry.php
示例18: 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;
}
开发者ID:IlyaGluschenko,项目名称:protection,代码行数:16,代码来源:CustomerMetadata.php
示例19: retrieve
/**
* Get instance of the Slider Model identified by an id
*
* @param int $sliderId
* @return Slider
* @throws NoSuchEntityException
*/
public function retrieve($sliderId)
{
if (isset($this->registry[$sliderId])) {
return $this->registry[$sliderId];
}
$slider = $this->sliderFactory->create();
$slider->load($sliderId);
if ($slider->getId() === null || $slider->getId() != $sliderId) {
throw NoSuchEntityException::singleField(SliderInterface::ID, $sliderId);
}
$this->registry[$sliderId] = $slider;
return $slider;
}
开发者ID:stepzerosolutions,项目名称:tbslider,代码行数:20,代码来源:SliderRegistry.php
示例20: retrieve
/**
* Retrieve tax class model from the registry
*
* @param int $taxClassId
* @return TaxClassModel
* @throws NoSuchEntityException
*/
public function retrieve($taxClassId)
{
if (isset($this->taxClassRegistryById[$taxClassId])) {
return $this->taxClassRegistryById[$taxClassId];
}
/** @var TaxClassModel $taxClassModel */
$taxClassModel = $this->taxClassModelFactory->create()->load($taxClassId);
if (!$taxClassModel->getId()) {
// tax class does not exist
throw NoSuchEntityException::singleField(TaxClass::KEY_ID, $taxClassId);
}
$this->taxClassRegistryById[$taxClassModel->getId()] = $taxClassModel;
return $taxClassModel;
}
开发者ID:aiesh,项目名称:magento2,代码行数:21,代码来源:ClassModelRegistry.php
注:本文中的Magento\Framework\Exception\NoSuchEntityException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论