Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
magento2-base
dev
tests
integration
testsuite
Magento
SalesRule
_files
coupon_code_with_wildcard.php
Go to the documentation of this file.
1
<?php
6
declare(strict_types=1);
7
8
use
Magento\Customer\Model\GroupManagement
;
9
use
Magento\SalesRule\Api\CouponRepositoryInterface
;
10
use
Magento\SalesRule\Model\Coupon
;
11
use
Magento\SalesRule\Model\Rule
;
12
use
Magento\Store\Model\StoreManagerInterface
;
13
use
Magento\TestFramework\Helper\Bootstrap
;
14
15
$objectManager
= Bootstrap::getObjectManager();
16
18
$salesRule
=
$objectManager
->create(Rule::class);
19
$salesRule
->setData(
20
[
21
'name'
=>
'5$ fixed discount on whole cart'
,
22
'is_active'
=> 1,
23
'customer_group_ids'
=> [GroupManagement::NOT_LOGGED_IN_ID],
24
'coupon_type'
=> Rule::COUPON_TYPE_SPECIFIC,
25
'conditions'
=> [],
26
'simple_action'
=> Rule::CART_FIXED_ACTION,
27
'discount_amount'
=> 5,
28
'discount_step'
=> 0,
29
'stop_rules_processing'
=> 1,
30
'website_ids'
=> [
31
$objectManager
->get(StoreManagerInterface::class)->getWebsite()->getId(),
32
],
33
]
34
);
35
$objectManager
->get(\
Magento
\SalesRule\Model\
ResourceModel
\Rule::class)->save(
$salesRule
);
36
37
// Create coupon and assign "15$ fixed discount" rule to this coupon.
38
$coupon
=
$objectManager
->create(Coupon::class);
39
$coupon
->setRuleId(
$salesRule
->getId())
40
->setCode(
'2?ds5!2d'
)
41
->setType(0);
42
44
$couponRepository
=
$objectManager
->get(CouponRepositoryInterface::class);
45
$couponRepository
->save(
$coupon
);
Magento\Catalog\Model\ResourceModel\Product
Definition:
CollectionTest.php:6
$objectManager
$objectManager
Definition:
coupon_code_with_wildcard.php:15
Magento\TestFramework\Helper\Bootstrap
Definition:
Bootstrap.php:12
Magento\Customer\Model\GroupManagement
Definition:
GroupManagement.php:23
$couponRepository
$couponRepository
Definition:
coupon_code_with_wildcard.php:44
Magento\SalesRule\Model\Coupon
Definition:
Codegenerator.php:6
Magento\Store\Model\StoreManagerInterface
Definition:
StoreManagerInterface.php:17
$salesRule
$salesRule
Definition:
coupon_code_with_wildcard.php:18
Magento
$coupon
$coupon
Definition:
coupon_code_with_wildcard.php:38
Magento\SalesRule\Model\Rule
Magento\SalesRule\Api\CouponRepositoryInterface
Definition:
CouponRepositoryInterface.php:14