Skip to content

Commit e19ee2a

Browse files
committed
MCP-218: Customer Group Limitations by Websites
- Change db schema; - Repository return types changes;
1 parent 5cc28b8 commit e19ee2a

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

app/code/Magento/Customer/Api/GroupExcludedWebsiteRepositoryInterface.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\Customer\Api\Data\GroupExcludedWebsiteInterface;
1111
use Magento\Framework\Exception\LocalizedException;
12-
use Magento\Framework\Model\ResourceModel\AbstractResource;
1312

1413
/**
1514
* Customer group website repository interface for websites that are excluded from customer group.
@@ -21,24 +20,24 @@ interface GroupExcludedWebsiteRepositoryInterface
2120
* Save customer group excluded website.
2221
*
2322
* @param GroupExcludedWebsiteInterface $groupExcludedWebsite
24-
* @return AbstractResource
23+
* @return GroupExcludedWebsiteInterface
2524
* @throws LocalizedException
2625
*/
27-
public function save(GroupExcludedWebsiteInterface $groupExcludedWebsite): AbstractResource;
26+
public function save(GroupExcludedWebsiteInterface $groupExcludedWebsite): GroupExcludedWebsiteInterface;
2827

2928
/**
3029
* Retrieve customer group excluded websites by customer group id.
3130
*
3231
* @param int $customerGroupId
33-
* @return array
32+
* @return string[]
3433
* @throws LocalizedException
3534
*/
3635
public function getCustomerGroupExcludedWebsites(int $customerGroupId): array;
3736

3837
/**
3938
* Retrieve all excluded customer group websites per customer groups.
4039
*
41-
* @return array
40+
* @return int[]
4241
* @throws LocalizedException
4342
*/
4443
public function getAllExcludedWebsites(): array;
@@ -47,17 +46,17 @@ public function getAllExcludedWebsites(): array;
4746
* Delete customer group with its excluded websites.
4847
*
4948
* @param int $customerGroupId
50-
* @return AbstractResource
49+
* @return bool
5150
* @throws LocalizedException
5251
*/
53-
public function delete(int $customerGroupId): AbstractResource;
52+
public function delete(int $customerGroupId): bool;
5453

5554
/**
5655
* Delete customer group excluded website by id.
5756
*
5857
* @param int $websiteId
59-
* @return int
58+
* @return bool
6059
* @throws LocalizedException
6160
*/
62-
public function deleteByWebsite(int $websiteId): int;
61+
public function deleteByWebsite(int $websiteId): bool;
6362
}

app/code/Magento/Customer/Model/Plugin/Website/DeleteCustomerGroupExcludedWebsite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function afterDelete(
5656
$websiteId = (int)$result->getId();
5757
if (!empty($websiteId)) {
5858
$deletedRecords = $this->groupExcludedWebsiteRepository->deleteByWebsite($websiteId);
59-
if ($deletedRecords > 0) {
59+
if ($deletedRecords) {
6060
// invalidate product price index if website was deleted from customer group exclusion
6161
$priceIndexer = $this->priceIndexProcessor->getIndexer();
6262
$priceIndexer->invalidate();

app/code/Magento/Customer/Model/ResourceModel/GroupExcludedWebsiteRepository.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Customer\Api\GroupExcludedWebsiteRepositoryInterface;
1212
use Magento\Framework\Exception\CouldNotSaveException;
1313
use Magento\Framework\Exception\LocalizedException;
14-
use Magento\Framework\Model\ResourceModel\AbstractResource;
1514

1615
/**
1716
* Customer group website repository for CRUD operations with excluded websites.
@@ -35,15 +34,17 @@ public function __construct(
3534
/**
3635
* @inheritdoc
3736
*/
38-
public function save(GroupExcludedWebsiteInterface $groupExcludedWebsite): AbstractResource
37+
public function save(GroupExcludedWebsiteInterface $groupExcludedWebsite): GroupExcludedWebsiteInterface
3938
{
4039
try {
41-
return $this->groupExcludedWebsiteResourceModel->save($groupExcludedWebsite);
40+
$this->groupExcludedWebsiteResourceModel->save($groupExcludedWebsite);
4241
} catch (\Exception $e) {
4342
throw new CouldNotSaveException(
4443
__('Could not save customer group website to exclude from customer group: "%1"', $e->getMessage())
4544
);
4645
}
46+
47+
return $groupExcludedWebsite;
4748
}
4849

4950
/**
@@ -89,24 +90,26 @@ public function getAllExcludedWebsites(): array
8990
/**
9091
* @inheritdoc
9192
*/
92-
public function delete(int $customerGroupId): AbstractResource
93+
public function delete(int $customerGroupId): bool
9394
{
9495
try {
95-
return $this->groupExcludedWebsiteResourceModel->delete($customerGroupId);
96+
$this->groupExcludedWebsiteResourceModel->delete($customerGroupId);
9697
} catch (LocalizedException $e) {
9798
throw new LocalizedException(
9899
__('Could not delete customer group with its excluded websites.')
99100
);
100101
}
102+
103+
return true;
101104
}
102105

103106
/**
104107
* @inheritdoc
105108
*/
106-
public function deleteByWebsite(int $websiteId): int
109+
public function deleteByWebsite(int $websiteId): bool
107110
{
108111
try {
109-
return $this->groupExcludedWebsiteResourceModel->deleteByWebsite($websiteId);
112+
return (bool)$this->groupExcludedWebsiteResourceModel->deleteByWebsite($websiteId);
110113
} catch (LocalizedException $e) {
111114
throw new LocalizedException(
112115
__('Could not delete customer group excluded website by id.')

app/code/Magento/Customer/etc/db_schema.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,9 @@
546546
<constraint xsi:type="primary" referenceId="PRIMARY">
547547
<column name="entity_id"/>
548548
</constraint>
549-
<index referenceId="CUSTOMER_GROUP_EXCLUDED_WEBSITE_CUSTOMER_GROUP_ID" indexType="btree">
549+
<index referenceId="CUSTOMER_GROUP_EXCLUDED_WEBSITE_CUSTOMER_GROUP_ID_WEBSITE_ID" indexType="btree">
550550
<column name="customer_group_id"/>
551+
<column name="website_id"/>
551552
</index>
552553
</table>
553554
</schema>

app/code/Magento/Customer/etc/db_schema_whitelist.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@
357357
"website_id": true
358358
},
359359
"index": {
360-
"CUSTOMER_GROUP_EXCLUDED_WEBSITE_CUSTOMER_GROUP_ID": true
360+
"CUSTOMER_GROUP_EXCLUDED_WEBSITE_CUSTOMER_GROUP_ID": true,
361+
"CUSTOMER_GROUP_EXCLUDED_WEBSITE_CUSTOMER_GROUP_ID_WEBSITE_ID": true
361362
},
362363
"constraint": {
363364
"PRIMARY": true

0 commit comments

Comments
 (0)