Skip to content

Commit e8bc24c

Browse files
committed
ACP2E-1175: [GraphQL] addProductsToWishlist with custom options returns error "Call to a member function getPriceType() on null"
1 parent 4f7e598 commit e8bc24c

File tree

5 files changed

+102
-87
lines changed

5 files changed

+102
-87
lines changed

app/code/Magento/Catalog/Model/Product/Option/Type/Select.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,8 @@ public function validateUserValue($values)
9090
$option = $this->getOption();
9191
$value = $this->getUserValue();
9292

93-
if (empty($value) && $option->getIsRequire() && !$this->getSkipCheckRequiredOption()) {
94-
$this->setIsValid(false);
95-
throw new LocalizedException(
96-
__("The product's required option(s) weren't entered. Make sure the options are entered and try again.")
97-
);
98-
}
99-
if (!$this->_isSingleSelection()) {
100-
if (is_string($value)) {
101-
$value = explode(',', $value);
102-
}
103-
$valuesCollection = $option->getOptionValuesByOptionId($value, $this->getProduct()->getStoreId())->load();
104-
$valueCount = is_array($value) ? count($value) : 0;
105-
if ($valuesCollection->count() != $valueCount) {
93+
if (empty($value)) {
94+
if ($option->getIsRequire() && !$this->getSkipCheckRequiredOption()) {
10695
$this->setIsValid(false);
10796
throw new LocalizedException(
10897
__(
@@ -111,6 +100,21 @@ public function validateUserValue($values)
111100
)
112101
);
113102
}
103+
} else {
104+
if (!$this->_isSingleSelection()) {
105+
if (is_string($value)) {
106+
$value = explode(',', $value);
107+
}
108+
$valuesCollection = $option->getOptionValuesByOptionId($value, $this->getProduct()->getStoreId());
109+
$valueCount = is_array($value) ? count($value) : 0;
110+
if ($valuesCollection->count() != $valueCount) {
111+
$this->setIsValid(false);
112+
throw new LocalizedException($this->_getWrongConfigurationMessage());
113+
}
114+
} elseif (!$option->getValueById($value)) {
115+
$this->setIsValid(false);
116+
throw new LocalizedException($this->_getWrongConfigurationMessage());
117+
}
114118
}
115119
return $this;
116120
}

app/code/Magento/QuoteGraphQl/Model/CartItem/DataProvider/CustomizableOptionValue/Dropdown.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,31 @@ public function getData(
5959
->setOption($option)
6060
->setConfigurationItemOption($selectedOption);
6161

62+
$selectedOptionValues = [];
6263
$selectedValue = $selectedOption->getValue();
6364
$optionValue = $option->getValueById($selectedValue);
64-
$optionPriceType = (string)$optionValue->getPriceType();
65-
$priceValueUnits = $this->priceUnitLabel->getData($optionPriceType);
65+
if ($optionValue) {
66+
$optionPriceType = (string)$optionValue->getPriceType();
67+
$priceValueUnits = $this->priceUnitLabel->getData($optionPriceType);
6668

67-
$optionDetails = [
68-
self::OPTION_TYPE,
69-
$option->getOptionId(),
70-
$optionValue->getOptionTypeId()
71-
];
69+
$optionDetails = [
70+
self::OPTION_TYPE,
71+
$option->getOptionId(),
72+
$optionValue->getOptionTypeId()
73+
];
7274

73-
$selectedOptionValueData = [
74-
'id' => $selectedOption->getId(),
75-
'customizable_option_value_uid' => $this->uidEncoder->encode((string) implode('/', $optionDetails)),
76-
'label' => $optionTypeRenderer->getFormattedOptionValue($selectedValue),
77-
'value' => $selectedValue,
78-
'price' => [
79-
'type' => strtoupper($optionPriceType),
80-
'units' => $priceValueUnits,
81-
'value' => $optionValue->getPrice(),
82-
]
83-
];
84-
return [$selectedOptionValueData];
75+
$selectedOptionValues[] = [
76+
'id' => $selectedOption->getId(),
77+
'customizable_option_value_uid' => $this->uidEncoder->encode((string)implode('/', $optionDetails)),
78+
'label' => $optionTypeRenderer->getFormattedOptionValue($selectedValue),
79+
'value' => $selectedValue,
80+
'price' => [
81+
'type' => strtoupper($optionPriceType),
82+
'units' => $priceValueUnits,
83+
'value' => $optionValue->getPrice(),
84+
]
85+
];
86+
}
87+
return $selectedOptionValues;
8588
}
8689
}

app/code/Magento/QuoteGraphQl/Model/CartItem/DataProvider/CustomizableOptionValue/Multiple.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,27 @@ public function getData(
6363

6464
foreach ($optionIds as $optionId) {
6565
$optionValue = $option->getValueById($optionId);
66-
$priceValueUnits = $this->priceUnitLabel->getData($optionValue->getPriceType());
66+
if ($optionValue) {
67+
$priceValueUnits = $this->priceUnitLabel->getData($optionValue->getPriceType());
6768

68-
$optionDetails = [
69-
self::OPTION_TYPE,
70-
$option->getOptionId(),
71-
$optionValue->getOptionTypeId()
72-
];
69+
$optionDetails = [
70+
self::OPTION_TYPE,
71+
$option->getOptionId(),
72+
$optionValue->getOptionTypeId()
73+
];
7374

74-
$selectedOptionValueData[] = [
75-
'id' => $selectedOption->getId(),
76-
'customizable_option_value_uid' => $this->uidEncoder->encode((string)implode('/', $optionDetails)),
77-
'label' => $optionValue->getTitle(),
78-
'value' => $optionId,
79-
'price' => [
80-
'type' => strtoupper($optionValue->getPriceType()),
81-
'units' => $priceValueUnits,
82-
'value' => $optionValue->getPrice(),
83-
],
84-
];
75+
$selectedOptionValueData[] = [
76+
'id' => $selectedOption->getId(),
77+
'customizable_option_value_uid' => $this->uidEncoder->encode((string)implode('/', $optionDetails)),
78+
'label' => $optionValue->getTitle(),
79+
'value' => $optionId,
80+
'price' => [
81+
'type' => strtoupper($optionValue->getPriceType()),
82+
'units' => $priceValueUnits,
83+
'value' => $optionValue->getPrice(),
84+
],
85+
];
86+
}
8587
}
8688

8789
return $selectedOptionValueData;

app/code/Magento/WishlistGraphQl/Model/WishlistItem/DataProvider/CustomizableOptionValue/Dropdown.php

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,34 @@ public function getData(
5959
->setOption($option)
6060
->setConfigurationItemOption($selectedOption);
6161

62+
$selectedOptionValues = [];
6263
$selectedValue = $selectedOption->getValue();
6364
$optionValue = $option->getValueById($selectedValue);
64-
$optionPriceType = (string)$optionValue->getPriceType();
65-
$priceValueUnits = $this->priceUnitLabel->getData($optionPriceType);
65+
if ($optionValue) {
66+
$optionPriceType = (string)$optionValue->getPriceType();
67+
$priceValueUnits = $this->priceUnitLabel->getData($optionPriceType);
6668

67-
$optionDetails = [
68-
self::OPTION_TYPE,
69-
$option->getOptionId(),
70-
$optionValue->getOptionTypeId()
71-
];
69+
$optionDetails = [
70+
self::OPTION_TYPE,
71+
$option->getOptionId(),
72+
$optionValue->getOptionTypeId()
73+
];
7274

73-
$uuid = $this->uidEncoder->encode((string) implode('/', $optionDetails));
75+
$uuid = $this->uidEncoder->encode((string) implode('/', $optionDetails));
7476

75-
$selectedOptionValueData = [
76-
'id' => $selectedOption->getId(),
77-
'customizable_option_value_uid' => $uuid,
78-
'label' => $optionTypeRenderer->getFormattedOptionValue($selectedValue),
79-
'value' => $selectedValue,
80-
'price' => [
81-
'type' => strtoupper($optionPriceType),
82-
'units' => $priceValueUnits,
83-
'value' => $optionValue->getPrice(),
84-
]
85-
];
86-
return [$selectedOptionValueData];
77+
$selectedOptionValues[] = [
78+
'id' => $selectedOption->getId(),
79+
'customizable_option_value_uid' => $uuid,
80+
'label' => $optionTypeRenderer->getFormattedOptionValue($selectedValue),
81+
'value' => $selectedValue,
82+
'price' => [
83+
'type' => strtoupper($optionPriceType),
84+
'units' => $priceValueUnits,
85+
'value' => $optionValue->getPrice(),
86+
]
87+
];
88+
}
89+
90+
return $selectedOptionValues;
8791
}
8892
}

app/code/Magento/WishlistGraphQl/Model/WishlistItem/DataProvider/CustomizableOptionValue/Multiple.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,29 @@ public function getData(
5858

5959
foreach ($optionIds as $optionId) {
6060
$optionValue = $option->getValueById($optionId);
61-
$priceValueUnits = $this->priceUnitLabel->getData($optionValue->getPriceType());
61+
if ($optionValue) {
62+
$priceValueUnits = $this->priceUnitLabel->getData($optionValue->getPriceType());
6263

63-
$optionDetails = [
64-
self::OPTION_TYPE,
65-
$option->getOptionId(),
66-
$optionValue->getOptionTypeId()
67-
];
64+
$optionDetails = [
65+
self::OPTION_TYPE,
66+
$option->getOptionId(),
67+
$optionValue->getOptionTypeId()
68+
];
6869

69-
$uuid = $this->uidEncoder->encode((string)implode('/', $optionDetails));
70+
$uuid = $this->uidEncoder->encode((string)implode('/', $optionDetails));
7071

71-
$selectedOptionValueData[] = [
72-
'id' => $selectedOption->getId(),
73-
'customizable_option_value_uid' => $uuid,
74-
'label' => $optionValue->getTitle(),
75-
'value' => $optionId,
76-
'price' => [
77-
'type' => strtoupper($optionValue->getPriceType()),
78-
'units' => $priceValueUnits,
79-
'value' => $optionValue->getPrice(),
80-
],
81-
];
72+
$selectedOptionValueData[] = [
73+
'id' => $selectedOption->getId(),
74+
'customizable_option_value_uid' => $uuid,
75+
'label' => $optionValue->getTitle(),
76+
'value' => $optionId,
77+
'price' => [
78+
'type' => strtoupper($optionValue->getPriceType()),
79+
'units' => $priceValueUnits,
80+
'value' => $optionValue->getPrice(),
81+
],
82+
];
83+
}
8284
}
8385

8486
return $selectedOptionValueData;

0 commit comments

Comments
 (0)