forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from magento/2.2-develop
2.2 develop-update branch
- Loading branch information
Showing
128 changed files
with
3,159 additions
and
1,422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/AbstractHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Model\Product\Attribute\Backend\TierPrice; | ||
|
||
use Magento\Framework\EntityManager\Operation\ExtensionInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Catalog\Api\ProductAttributeRepositoryInterface; | ||
use Magento\Catalog\Api\Data\ProductInterface; | ||
use Magento\Customer\Api\GroupManagementInterface; | ||
use Magento\Framework\EntityManager\MetadataPool; | ||
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice; | ||
|
||
/** | ||
* Tier price data abstract handler. | ||
*/ | ||
abstract class AbstractHandler implements ExtensionInterface | ||
{ | ||
/** | ||
* @var \Magento\Customer\Api\GroupManagementInterface | ||
*/ | ||
protected $groupManagement; | ||
|
||
/** | ||
* @param \Magento\Customer\Api\GroupManagementInterface $groupManagement | ||
*/ | ||
public function __construct( | ||
GroupManagementInterface $groupManagement | ||
) { | ||
$this->groupManagement = $groupManagement; | ||
} | ||
|
||
/** | ||
* Get additional tier price fields. | ||
* | ||
* @return array | ||
*/ | ||
protected function getAdditionalFields(array $objectArray): array | ||
{ | ||
$percentageValue = $this->getPercentage($objectArray); | ||
|
||
return [ | ||
'value' => $percentageValue ? null : $objectArray['price'], | ||
'percentage_value' => $percentageValue ?: null, | ||
]; | ||
} | ||
|
||
/** | ||
* Check whether price has percentage value. | ||
* | ||
* @param array $priceRow | ||
* @return integer|null | ||
*/ | ||
protected function getPercentage(array $priceRow) | ||
{ | ||
return isset($priceRow['percentage_value']) && is_numeric($priceRow['percentage_value']) | ||
? (int)$priceRow['percentage_value'] | ||
: null; | ||
} | ||
|
||
/** | ||
* Prepare tier price data by provided price row data. | ||
* | ||
* @param array $data | ||
* @return array | ||
*/ | ||
protected function prepareTierPrice(array $data): array | ||
{ | ||
$useForAllGroups = (int)$data['cust_group'] === $this->groupManagement->getAllCustomersGroup()->getId(); | ||
$customerGroupId = $useForAllGroups ? 0 : $data['cust_group']; | ||
$tierPrice = array_merge( | ||
$this->getAdditionalFields($data), | ||
[ | ||
'website_id' => $data['website_id'], | ||
'all_groups' => (int)$useForAllGroups, | ||
'customer_group_id' => $customerGroupId, | ||
'value' => $data['price'] ?? null, | ||
'qty' => $this->parseQty($data['price_qty']), | ||
] | ||
); | ||
|
||
return $tierPrice; | ||
} | ||
|
||
/** | ||
* Parse quantity value into float. | ||
* | ||
* @param mixed $value | ||
* @return float|int | ||
*/ | ||
protected function parseQty($value) | ||
{ | ||
return $value * 1; | ||
} | ||
} |
Oops, something went wrong.