Skip to content

Commit

Permalink
ENGCOM-8511: [MFTF] Refactoring of AdminMassUpdateProductAttributesMi…
Browse files Browse the repository at this point in the history
…ssingRequiredFieldTest #31079
  • Loading branch information
gabrieldagama authored Dec 7, 2020
2 parents e10bfa4 + ec3b6f0 commit f7523fb
Show file tree
Hide file tree
Showing 167 changed files with 5,821 additions and 679 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use Magento\Bundle\Helper\Catalog\Product\Configuration;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\GraphQl\Query\Uid;
use Magento\Quote\Model\Quote\Item;
use Magento\Framework\Pricing\Helper\Data;
use Magento\Framework\Serialize\SerializerInterface;
Expand All @@ -18,6 +20,11 @@
*/
class BundleOptionDataProvider
{
/**
* Option type name
*/
private const OPTION_TYPE = 'bundle';

/**
* @var Data
*/
Expand All @@ -33,19 +40,26 @@ class BundleOptionDataProvider
*/
private $configuration;

/** @var Uid */
private $uidEncoder;

/**
* @param Data $pricingHelper
* @param SerializerInterface $serializer
* @param Configuration $configuration
* @param Uid|null $uidEncoder
*/
public function __construct(
Data $pricingHelper,
SerializerInterface $serializer,
Configuration $configuration
Configuration $configuration,
Uid $uidEncoder = null
) {
$this->pricingHelper = $pricingHelper;
$this->serializer = $serializer;
$this->configuration = $configuration;
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()
->get(Uid::class);
}

/**
Expand Down Expand Up @@ -103,6 +117,7 @@ private function buildBundleOptions(array $bundleOptions, Item $item): array

$options[] = [
'id' => $bundleOption->getId(),
'uid' => $this->uidEncoder->encode(self::OPTION_TYPE . '/' . $bundleOption->getId()),
'label' => $bundleOption->getTitle(),
'type' => $bundleOption->getType(),
'values' => $this->buildBundleOptionValues($bundleOption->getSelections(), $item),
Expand Down Expand Up @@ -131,9 +146,15 @@ private function buildBundleOptionValues(array $selections, Item $item): array
}

$selectionPrice = $this->configuration->getSelectionFinalPrice($item, $selection);

$optionDetails = [
self::OPTION_TYPE,
$selection->getData('option_id'),
$selection->getData('selection_id'),
(int) $selection->getData('selection_qty')
];
$values[] = [
'id' => $selection->getSelectionId(),
'uid' => $this->uidEncoder->encode(implode('/', $optionDetails)),
'label' => $selection->getName(),
'quantity' => $qty,
'price' => $this->pricingHelper->currency($selectionPrice, false, false),
Expand Down
16 changes: 14 additions & 2 deletions app/code/Magento/BundleGraphQl/Model/Resolver/Links/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use Magento\Bundle\Model\Selection;
use Magento\Bundle\Model\ResourceModel\Selection\CollectionFactory;
use Magento\Bundle\Model\ResourceModel\Selection\Collection as LinkCollection;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\GraphQl\Query\EnumLookup;
use Magento\Framework\GraphQl\Query\Uid;

/**
* Collection to fetch link data at resolution time.
Expand Down Expand Up @@ -42,14 +44,23 @@ class Collection
*/
private $links = [];

/** @var Uid */
private $uidEncoder;

/**
* @param CollectionFactory $linkCollectionFactory
* @param EnumLookup $enumLookup
* @param Uid|null $uidEncoder
*/
public function __construct(CollectionFactory $linkCollectionFactory, EnumLookup $enumLookup)
{
public function __construct(
CollectionFactory $linkCollectionFactory,
EnumLookup $enumLookup,
Uid $uidEncoder = null
) {
$this->linkCollectionFactory = $linkCollectionFactory;
$this->enumLookup = $enumLookup;
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()
->get(Uid::class);
}

/**
Expand Down Expand Up @@ -117,6 +128,7 @@ private function fetch() : array
'price' => $link->getSelectionPriceValue(),
'position' => $link->getPosition(),
'id' => $link->getSelectionId(),
'uid' => $this->uidEncoder->encode((string) $link->getSelectionId()),
'qty' => (float)$link->getSelectionQty(),
'quantity' => (float)$link->getSelectionQty(),
'is_default' => (bool)$link->getIsDefault(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Query\Uid;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
Expand All @@ -23,6 +24,17 @@ class BundleItemOptionUid implements ResolverInterface
*/
private const OPTION_TYPE = 'bundle';

/** @var Uid */
private $uidEncoder;

/**
* @param Uid $uidEncoder
*/
public function __construct(Uid $uidEncoder)
{
$this->uidEncoder = $uidEncoder;
}

/**
* Create a option uid for entered option in "<option-type>/<option-id>/<option-value-id>/<quantity>" format
*
Expand Down Expand Up @@ -62,7 +74,6 @@ public function resolve(

$content = implode('/', $optionDetails);

// phpcs:ignore Magento2.Functions.DiscouragedFunction
return base64_encode($content);
return $this->uidEncoder->encode($content);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
*/
declare(strict_types=1);


namespace Magento\BundleGraphQl\Model\Resolver\Options;

use Magento\Bundle\Model\OptionFactory;
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\GraphQl\Query\Uid;
use Magento\Store\Model\StoreManagerInterface;

/**
* Collection to fetch bundle option data at resolution time.
*/
class Collection
{
/**
* Option type name
*/
private const OPTION_TYPE = 'bundle';

/**
* @var OptionFactory
*/
Expand All @@ -42,19 +48,26 @@ class Collection
*/
private $optionMap = [];

/** @var Uid */
private $uidEncoder;

/**
* @param OptionFactory $bundleOptionFactory
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
* @param StoreManagerInterface $storeManager
* @param Uid|null $uidEncoder
*/
public function __construct(
OptionFactory $bundleOptionFactory,
JoinProcessorInterface $extensionAttributesJoinProcessor,
StoreManagerInterface $storeManager
StoreManagerInterface $storeManager,
Uid $uidEncoder = null
) {
$this->bundleOptionFactory = $bundleOptionFactory;
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
$this->storeManager = $storeManager;
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()
->get(Uid::class);
}

/**
Expand Down Expand Up @@ -101,7 +114,7 @@ private function fetch() : array
$linkField = $optionsCollection->getConnection()->getAutoIncrementField($productTable);
$optionsCollection->getSelect()->join(
['cpe' => $productTable],
'cpe.'.$linkField.' = main_table.parent_id',
'cpe.' . $linkField . ' = main_table.parent_id',
[]
)->where(
"cpe.entity_id IN (?)",
Expand All @@ -124,6 +137,8 @@ private function fetch() : array
= $option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle();
$this->optionMap[$option->getParentId()][$option->getId()]['sku']
= $this->skuMap[$option->getParentId()]['sku'];
$this->optionMap[$option->getParentId()][$option->getId()]['uid']
= $this->uidEncoder->encode(self::OPTION_TYPE . '/' . $option->getOptionId());
}

return $this->optionMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Query\Uid;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Sales\Api\Data\InvoiceItemInterface;
Expand All @@ -23,6 +24,11 @@
*/
class BundleOptions implements ResolverInterface
{
/**
* Option type name
*/
private const OPTION_TYPE = 'bundle';

/**
* Serializer
*
Expand All @@ -35,16 +41,22 @@ class BundleOptions implements ResolverInterface
*/
private $valueFactory;

/** @var Uid */
private $uidEncoder;

/**
* @param ValueFactory $valueFactory
* @param Json $serializer
* @param Uid $uidEncoder
*/
public function __construct(
ValueFactory $valueFactory,
Json $serializer
Json $serializer,
Uid $uidEncoder
) {
$this->valueFactory = $valueFactory;
$this->serializer = $serializer;
$this->uidEncoder = $uidEncoder;
}

/**
Expand Down Expand Up @@ -89,7 +101,9 @@ private function getBundleOptions(
foreach ($options['bundle_options'] ?? [] as $bundleOptionId => $bundleOption) {
$bundleOptions[$bundleOptionId]['label'] = $bundleOption['label'] ?? '';
$bundleOptions[$bundleOptionId]['id'] = isset($bundleOption['option_id']) ?
base64_encode($bundleOption['option_id']) : null;
$this->uidEncoder->encode((string) $bundleOption['option_id']) : null;
$bundleOptions[$bundleOptionId]['uid'] = isset($bundleOption['option_id']) ?
$this->uidEncoder->encode(self::OPTION_TYPE . '/' . $bundleOption['option_id']) : null;
if (isset($bundleOption['option_id'])) {
$bundleOptions[$bundleOptionId]['values'] = $this->formatBundleOptionItems(
$item,
Expand Down Expand Up @@ -127,8 +141,20 @@ private function formatBundleOptionItems(
// Value Id is missing from parent, so we have to match the child to parent option
if (isset($bundleChildAttributes['option_id'])
&& $bundleChildAttributes['option_id'] == $bundleOptionId) {

$options = $childOrderItemOptions['info_buyRequest']
['bundle_option'][$bundleChildAttributes['option_id']];

$optionDetails = [
self::OPTION_TYPE,
$bundleChildAttributes['option_id'],
implode(',', $options),
(int) $childOrderItemOptions['info_buyRequest']['qty']
];

$optionItems[$childrenOrderItem->getItemId()] = [
'id' => base64_encode($childrenOrderItem->getItemId()),
'id' => $this->uidEncoder->encode((string) $childrenOrderItem->getItemId()),
'uid' => $this->uidEncoder->encode(implode('/', $optionDetails)),
'product_name' => $childrenOrderItem->getName(),
'product_sku' => $childrenOrderItem->getSku(),
'quantity' => $bundleChildAttributes['qty'],
Expand Down
19 changes: 12 additions & 7 deletions app/code/Magento/BundleGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,24 @@ type BundleCartItem implements CartItemInterface {
}

type SelectedBundleOption {
id: Int!
id: Int! @deprecated(reason: "Use `uid` instead")
uid: ID! @doc(description: "The unique ID for a `SelectedBundleOption` object")
label: String!
type: String!
values: [SelectedBundleOptionValue!]!
}

type SelectedBundleOptionValue {
id: Int!
id: Int! @doc(description: "Use `uid` instead")
uid: ID! @doc(description: "The unique ID for a `SelectedBundleOptionValue` object")
label: String!
quantity: Float!
price: Float!
}

type BundleItem @doc(description: "BundleItem defines an individual item in a bundle product.") {
option_id: Int @doc(description: "An ID assigned to each type of item in a bundle product.")
option_id: Int @deprecated(reason: "Use `uid` instead") @doc(description: "An ID assigned to each type of item in a bundle product.")
uid: ID @doc(description: "The unique ID for a `BundleItem` object.")
title: String @doc(description: "The display name of the item.")
required: Boolean @doc(description: "Indicates whether the item must be included in the bundle.")
type: String @doc(description: "The input type that the customer uses to select the item. Examples include radio button and checkbox.")
Expand All @@ -56,7 +59,7 @@ type BundleItem @doc(description: "BundleItem defines an individual item in a bu
}

type BundleItemOption @doc(description: "BundleItemOption defines characteristics and options for a specific bundle item.") {
id: Int @doc(description: "The ID assigned to the bundled item option.")
id: Int @deprecated(reason: "Use `uid` instead") @doc(description: "The ID assigned to the bundled item option.")
label: String @doc(description: "The text that identifies the bundled item option.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\Label")
qty: Float @deprecated(reason: "The `qty` is deprecated. Use `quantity` instead.") @doc(description: "Indicates the quantity of this specific bundle item.")
quantity: Float @doc(description: "Indicates the quantity of this specific bundle item.")
Expand All @@ -66,7 +69,7 @@ type BundleItemOption @doc(description: "BundleItemOption defines characteristic
price_type: PriceTypeEnum @doc(description: "One of FIXED, PERCENT, or DYNAMIC.")
can_change_quantity: Boolean @doc(description: "Indicates whether the customer can change the number of items for this option.")
product: ProductInterface @doc(description: "Contains details about this product option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product")
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\BundleItemOptionUid") # A Base64 string that encodes option details.
uid: ID! @doc(description: "The unique ID for a `BundleItemOption` object.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\BundleItemOptionUid")
}

type BundleProduct implements ProductInterface, PhysicalProductInterface, CustomizableProductInterface @doc(description: "BundleProduct defines basic features of a bundle product and contains multiple BundleItems.") {
Expand Down Expand Up @@ -105,13 +108,15 @@ type BundleCreditMemoItem implements CreditMemoItemInterface {
}

type ItemSelectedBundleOption @doc(description: "A list of options of the selected bundle product") {
id: ID! @doc(description: "The unique identifier of the option")
id: ID! @deprecated(reason: "Use `uid` instead") @doc(description: "The unique ID for a `ItemSelectedBundleOption` object")
uid: ID! @doc(description: "The unique ID for a `ItemSelectedBundleOption` object")
label: String! @doc(description: "The label of the option")
values: [ItemSelectedBundleOptionValue] @doc(description: "A list of products that represent the values of the parent option")
}

type ItemSelectedBundleOptionValue @doc(description: "A list of values for the selected bundle product") {
id: ID! @doc(description: "The unique identifier of the value")
id: ID! @deprecated(reason: "Use `uid` instead") @doc(description: "The unique ID for a `ItemSelectedBundleOptionValue` object")
uid: ID! @doc(description: "The unique ID for a `ItemSelectedBundleOptionValue` object")
product_name: String! @doc(description: "The name of the child bundle product")
product_sku: String! @doc(description: "The SKU of the child bundle product")
quantity: Float! @doc(description: "Indicates how many of this bundle product were ordered")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\Catalog\Controller\Product\Compare;

use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\ResourceModel\Product\Compare\Item\Collection;
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
use Magento\Framework\Exception\NoSuchEntityException;

Expand Down
24 changes: 24 additions & 0 deletions app/code/Magento/Catalog/Model/CompareList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Catalog\Model;

use Magento\Framework\Model\AbstractModel;

class CompareList extends AbstractModel
{
/**
* Initialize resource
*
* @return void
*/
protected function _construct()
{
$this->_init(ResourceModel\Product\Compare\CompareList::class);
}
}
Loading

0 comments on commit f7523fb

Please sign in to comment.