@@ -71,54 +71,35 @@ public function execute()
71
71
72
72
/** @var \Magento\Store\Model\StoreManager $storeManager */
73
73
$ storeManager = $ this ->fixtureModel ->getObjectManager ()->create (\Magento \Store \Model \StoreManager::class);
74
- /** @var $category \Magento\Catalog\Model\Category */
75
- $ category = $ this ->fixtureModel ->getObjectManager ()->get (\Magento \Catalog \Model \Category::class);
76
74
77
75
//Get all websites
78
- $ categoriesArray = [];
76
+ $ websitesArray = [];
79
77
$ websites = $ storeManager ->getWebsites ();
80
78
foreach ($ websites as $ website ) {
81
- //Get all groups
82
- $ websiteGroups = $ website ->getGroups ();
83
- foreach ($ websiteGroups as $ websiteGroup ) {
84
- $ websiteGroupRootCategory = $ websiteGroup ->getRootCategoryId ();
85
- $ category ->load ($ websiteGroupRootCategory );
86
- $ categoryResource = $ category ->getResource ();
87
- //Get all categories
88
- $ resultsCategories = $ categoryResource ->getAllChildren ($ category );
89
- foreach ($ resultsCategories as $ resultsCategory ) {
90
- $ category ->load ($ resultsCategory );
91
- $ structure = explode ('/ ' , $ category ->getPath ());
92
- if (count ($ structure ) > 2 ) {
93
- $ categoriesArray [] = [$ category ->getId (), $ website ->getId ()];
94
- }
95
- }
96
- }
79
+ $ websitesArray [] = $ website ->getId ();
97
80
}
98
- asort ($ categoriesArray );
99
- $ categoriesArray = array_values ($ categoriesArray );
100
81
101
- $ this ->generateCouponCodes ($ this ->ruleFactory , $ this ->couponCodeFactory , $ categoriesArray );
82
+ $ this ->generateCouponCodes ($ this ->ruleFactory , $ this ->couponCodeFactory , $ websitesArray );
102
83
}
103
84
104
85
/**
105
86
* Generate Coupon Codes
106
87
*
107
88
* @param \Magento\SalesRule\Model\RuleFactory $ruleFactory
108
89
* @param \Magento\SalesRule\Model\CouponFactory $couponCodeFactory
109
- * @param array $categoriesArray
90
+ * @param array $websitesArray
110
91
*
111
92
* @return void
112
93
*/
113
- public function generateCouponCodes ($ ruleFactory , $ couponCodeFactory , $ categoriesArray )
94
+ public function generateCouponCodes ($ ruleFactory , $ couponCodeFactory , $ websitesArray )
114
95
{
115
96
for ($ i = 0 ; $ i < $ this ->couponCodesCount ; $ i ++) {
116
97
$ ruleName = sprintf ('Coupon Code %1$d ' , $ i );
117
98
$ data = [
118
99
'rule_id ' => null ,
119
100
'name ' => $ ruleName ,
120
101
'is_active ' => '1 ' ,
121
- 'website_ids ' => $ categoriesArray [ $ i % count ( $ categoriesArray )][ 1 ] ,
102
+ 'website_ids ' => $ websitesArray ,
122
103
'customer_group_ids ' => [
123
104
0 => '0 ' ,
124
105
1 => '1 ' ,
0 commit comments