-
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 magento/2.4-develop into magento-pangolin/MQE-2271-2.4-dev
- Loading branch information
Showing
34 changed files
with
1,107 additions
and
102 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
app/code/Magento/Bundle/Model/Product/BundleOptionDataProvider.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,144 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Bundle\Model\Product; | ||
|
||
use Magento\Bundle\Helper\Catalog\Product\Configuration; | ||
use Magento\Bundle\Model\Option; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface; | ||
use Magento\Framework\Pricing\Helper\Data; | ||
use Magento\Framework\Serialize\SerializerInterface; | ||
|
||
/** | ||
* Data provider for bundled product options | ||
*/ | ||
class BundleOptionDataProvider | ||
{ | ||
/** | ||
* @var Data | ||
*/ | ||
private $pricingHelper; | ||
|
||
/** | ||
* @var SerializerInterface | ||
*/ | ||
private $serializer; | ||
|
||
/** | ||
* @var Configuration | ||
*/ | ||
private $configuration; | ||
|
||
/** | ||
* @param Data $pricingHelper | ||
* @param SerializerInterface $serializer | ||
* @param Configuration $configuration | ||
*/ | ||
public function __construct( | ||
Data $pricingHelper, | ||
SerializerInterface $serializer, | ||
Configuration $configuration | ||
) { | ||
$this->pricingHelper = $pricingHelper; | ||
$this->serializer = $serializer; | ||
$this->configuration = $configuration; | ||
} | ||
|
||
/** | ||
* Extract data for a bundled item | ||
* | ||
* @param ItemInterface $item | ||
* | ||
* @return array | ||
*/ | ||
public function getData(ItemInterface $item): array | ||
{ | ||
$options = []; | ||
$product = $item->getProduct(); | ||
$optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids'); | ||
$bundleOptionsIds = $optionsQuoteItemOption | ||
? $this->serializer->unserialize($optionsQuoteItemOption->getValue()) | ||
: []; | ||
|
||
/** @var Type $typeInstance */ | ||
$typeInstance = $product->getTypeInstance(); | ||
|
||
if ($bundleOptionsIds) { | ||
$selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids'); | ||
$optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product); | ||
$bundleSelectionIds = $this->serializer->unserialize($selectionsQuoteItemOption->getValue()); | ||
|
||
if (!empty($bundleSelectionIds)) { | ||
$selectionsCollection = $typeInstance->getSelectionsByIds($bundleSelectionIds, $product); | ||
$bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true); | ||
|
||
$options = $this->buildBundleOptions($bundleOptions, $item); | ||
} | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
/** | ||
* Build bundle product options based on current selection | ||
* | ||
* @param Option[] $bundleOptions | ||
* @param ItemInterface $item | ||
* | ||
* @return array | ||
*/ | ||
private function buildBundleOptions(array $bundleOptions, ItemInterface $item): array | ||
{ | ||
$options = []; | ||
foreach ($bundleOptions as $bundleOption) { | ||
if (!$bundleOption->getSelections()) { | ||
continue; | ||
} | ||
|
||
$options[] = [ | ||
'id' => $bundleOption->getId(), | ||
'label' => $bundleOption->getTitle(), | ||
'type' => $bundleOption->getType(), | ||
'values' => $this->buildBundleOptionValues($bundleOption->getSelections(), $item), | ||
]; | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
/** | ||
* Build bundle product option values based on current selection | ||
* | ||
* @param Product[] $selections | ||
* @param ItemInterface $item | ||
* | ||
* @return array | ||
*/ | ||
private function buildBundleOptionValues(array $selections, ItemInterface $item): array | ||
{ | ||
$product = $item->getProduct(); | ||
$values = []; | ||
|
||
foreach ($selections as $selection) { | ||
$qty = (float) $this->configuration->getSelectionQty($product, $selection->getSelectionId()); | ||
if (!$qty) { | ||
continue; | ||
} | ||
|
||
$selectionPrice = $this->configuration->getSelectionFinalPrice($item, $selection); | ||
$values[] = [ | ||
'label' => $selection->getName(), | ||
'id' => $selection->getSelectionId(), | ||
'quantity' => $qty, | ||
'price' => $this->pricingHelper->currency($selectionPrice, false, false), | ||
]; | ||
} | ||
|
||
return $values; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/code/Magento/BundleGraphQl/Model/Wishlist/BundleOptions.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,54 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\BundleGraphQl\Model\Wishlist; | ||
|
||
use Magento\Bundle\Model\Product\BundleOptionDataProvider; | ||
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
/** | ||
* Fetches the selected bundle options | ||
*/ | ||
class BundleOptions implements ResolverInterface | ||
{ | ||
/** | ||
* @var BundleOptionDataProvider | ||
*/ | ||
private $bundleOptionDataProvider; | ||
|
||
/** | ||
* @param BundleOptionDataProvider $bundleOptionDataProvider | ||
*/ | ||
public function __construct( | ||
BundleOptionDataProvider $bundleOptionDataProvider | ||
) { | ||
$this->bundleOptionDataProvider = $bundleOptionDataProvider; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!$value['itemModel'] instanceof ItemInterface) { | ||
throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [ | ||
'instance' => ItemInterface::class | ||
])); | ||
} | ||
|
||
return $this->bundleOptionDataProvider->getData($value['itemModel']); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/ChildSku.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,43 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\ConfigurableProductGraphQl\Model\Wishlist; | ||
|
||
use Magento\Catalog\Model\Product; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
/** | ||
* Fetches the simple child sku of configurable product | ||
*/ | ||
class ChildSku implements ResolverInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!$value['model'] instanceof Product) { | ||
throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [ | ||
'instance' => Product::class | ||
])); | ||
} | ||
|
||
/** @var Product $product */ | ||
$product = $value['model']; | ||
$optionProduct = $product->getCustomOption('simple_product')->getProduct(); | ||
|
||
return $optionProduct->getSku(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
app/code/Magento/ConfigurableProductGraphQl/Model/Wishlist/ConfigurableOptions.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,67 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\ConfigurableProductGraphQl\Model\Wishlist; | ||
|
||
use Magento\Catalog\Helper\Product\Configuration; | ||
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
/** | ||
* Fetches the selected configurable options | ||
*/ | ||
class ConfigurableOptions implements ResolverInterface | ||
{ | ||
/** | ||
* @var Configuration | ||
*/ | ||
private $configurationHelper; | ||
|
||
/** | ||
* @param Configuration $configurationHelper | ||
*/ | ||
public function __construct( | ||
Configuration $configurationHelper | ||
) { | ||
$this->configurationHelper = $configurationHelper; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!$value['itemModel'] instanceof ItemInterface) { | ||
throw new LocalizedException(__('"itemModel" should be a "%instance" instance', [ | ||
'instance' => ItemInterface::class | ||
])); | ||
} | ||
|
||
/** @var ItemInterface $item */ | ||
$item = $value['itemModel']; | ||
$result = []; | ||
|
||
foreach ($this->configurationHelper->getOptions($item) as $option) { | ||
$result[] = [ | ||
'id' => $option['option_id'], | ||
'option_label' => $option['label'], | ||
'value_id' => $option['option_value'], | ||
'value_label' => $option['value'], | ||
]; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
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
Oops, something went wrong.