-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.4-develop' into Refactoring-AdminDeleteSimpleProductTest
# Conflicts: # app/code/Magento/CatalogSearch/Test/Mftf/ActionGroup/AssertStorefrontNoResultsMessageOnSearchPageActionGroup.xml
- Loading branch information
Showing
234 changed files
with
4,901 additions
and
1,198 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Bundle\Model\Quote\Item; | ||
|
||
use Magento\Bundle\Model\Product\Price; | ||
use Magento\Bundle\Model\Product\Type; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
|
||
/** | ||
* Bundle product options model | ||
*/ | ||
class Option | ||
{ | ||
/** | ||
* @var Json | ||
*/ | ||
private $serializer; | ||
|
||
/** | ||
* @param Json $serializer | ||
*/ | ||
public function __construct( | ||
Json $serializer | ||
) { | ||
$this->serializer = $serializer; | ||
} | ||
|
||
/** | ||
* Get selection options for provided bundle product | ||
* | ||
* @param Product $product | ||
* @return array | ||
*/ | ||
public function getSelectionOptions(Product $product): array | ||
{ | ||
$options = []; | ||
$bundleOptionIds = $this->getOptionValueAsArray($product, 'bundle_option_ids'); | ||
if ($bundleOptionIds) { | ||
/** @var Type $typeInstance */ | ||
$typeInstance = $product->getTypeInstance(); | ||
$optionsCollection = $typeInstance->getOptionsByIds($bundleOptionIds, $product); | ||
$selectionIds = $this->getOptionValueAsArray($product, 'bundle_selection_ids'); | ||
|
||
if ($selectionIds) { | ||
$selectionsCollection = $typeInstance->getSelectionsByIds($selectionIds, $product); | ||
$optionsCollection->appendSelections($selectionsCollection, true); | ||
|
||
foreach ($selectionsCollection as $selection) { | ||
$selectionId = $selection->getSelectionId(); | ||
$options[$selectionId][] = $this->getBundleSelectionAttributes($product, $selection); | ||
} | ||
} | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
/** | ||
* Get selection attributes for provided selection | ||
* | ||
* @param Product $product | ||
* @param Product $selection | ||
* @return array | ||
*/ | ||
private function getBundleSelectionAttributes(Product $product, Product $selection): array | ||
{ | ||
$selectionId = $selection->getSelectionId(); | ||
/** @var \Magento\Bundle\Model\Option $bundleOption */ | ||
$bundleOption = $selection->getOption(); | ||
/** @var Price $priceModel */ | ||
$priceModel = $product->getPriceModel(); | ||
$price = $priceModel->getSelectionFinalTotalPrice($product, $selection, 0, 1); | ||
$customOption = $product->getCustomOption('selection_qty_' . $selectionId); | ||
$qty = (float)($customOption ? $customOption->getValue() : 0); | ||
|
||
return [ | ||
'code' => 'bundle_selection_attributes', | ||
'value'=> $this->serializer->serialize( | ||
[ | ||
'price' => $price, | ||
'qty' => $qty, | ||
'option_label' => $bundleOption->getTitle(), | ||
'option_id' => $bundleOption->getId(), | ||
] | ||
) | ||
]; | ||
} | ||
|
||
/** | ||
* Get unserialized value of custom option | ||
* | ||
* @param Product $product | ||
* @param string $code | ||
* @return array | ||
*/ | ||
private function getOptionValueAsArray(Product $product, string $code): array | ||
{ | ||
$option = $product->getCustomOption($code); | ||
return $option && $option->getValue() | ||
? $this->serializer->unserialize($option->getValue()) | ||
: []; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/code/Magento/Bundle/Model/Quote/Item/Option/BundleSelectionAttributesComparator.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,45 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Bundle\Model\Quote\Item\Option; | ||
|
||
use Magento\Framework\DataObject; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
use Magento\Quote\Model\Quote\Item\Option\ComparatorInterface; | ||
|
||
/** | ||
* Bundle quote item option comparator | ||
*/ | ||
class BundleSelectionAttributesComparator implements ComparatorInterface | ||
{ | ||
/** | ||
* @var Json | ||
*/ | ||
private $serializer; | ||
|
||
/** | ||
* @param Json $serializer | ||
*/ | ||
public function __construct( | ||
Json $serializer | ||
) { | ||
$this->serializer = $serializer; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function compare(DataObject $option1, DataObject $option2): bool | ||
{ | ||
$value1 = $option1->getValue() ? $this->serializer->unserialize($option1->getValue()) : []; | ||
$value2 = $option2->getValue() ? $this->serializer->unserialize($option2->getValue()) : []; | ||
$option1Id = isset($value1['option_id']) ? (int) $value1['option_id'] : null; | ||
$option2Id = isset($value2['option_id']) ? (int) $value2['option_id'] : null; | ||
|
||
return $option1Id === $option2Id; | ||
} | ||
} |
Oops, something went wrong.