55 $this->product = $this->createPartialMock(
56 \
Magento\Catalog\Model\Product::class,
57 [
'getOptionById',
'__wakeup',
'getPriceInfo',
'getOptions']
60 $this->priceInfo = $this->createMock(\
Magento\Framework\Pricing\PriceInfo\Base::class);
62 $this->product->expects($this->any())
63 ->method(
'getPriceInfo')
64 ->will($this->returnValue($this->priceInfo));
66 $this->calculator = $this->createMock(\
Magento\Framework\Pricing\Adjustment\Calculator::class);
68 $this->
amount = $this->createMock(\
Magento\Framework\Pricing\Amount\Base::class);
70 $this->priceCurrencyMock = $this->createMock(\
Magento\Framework\Pricing\PriceCurrencyInterface::class);
76 $this->priceCurrencyMock
91 $optionItemMock = $this->getMockBuilder(\
Magento\Catalog\Model\Product\Option::class)
92 ->disableOriginalConstructor()
93 ->setMethods([
'getValues',
'__wakeup',
'getIsRequire',
'getId',
'getType'])
95 $optionItemMock->expects($this->any())
98 $optionItemMock->expects($this->any())
101 $optionItemMock->expects($this->any())
102 ->method(
'getIsRequire')
103 ->will($this->returnValue(
$optionData[
'is_require']));
104 $optionItemMock->expects($this->any())
105 ->method(
'getValues')
106 ->will($this->returnValue([$optionValueMax, $optionValueMin]));
120 $optionItemMock = $this->getMockBuilder(\
Magento\Catalog\Model\Product\Option::class)
121 ->disableOriginalConstructor()
132 $optionItemMock->expects($this->any())
135 $optionItemMock->expects($this->any())
138 $optionItemMock->expects($this->any())
139 ->method(
'getIsRequire')
140 ->will($this->returnValue(
$optionData[
'is_require']));
141 $optionItemMock->expects($this->any())
142 ->method(
'getValues')
143 ->will($this->returnValue(
null));
144 $optionItemMock->expects($this->any())
145 ->method(
'getPriceType')
147 $optionItemMock->expects($this->any())
162 $option1MaxPrice = 100;
163 $option1MinPrice = 10;
164 $option1Type =
'select';
167 $option2MaxPrice = 200;
168 $option2MinPrice = 20;
174 'type' => $option1Type,
175 'max_option_price' => $option1MaxPrice,
176 'min_option_price' => $option1MinPrice,
177 'is_require' =>
true,
181 'type' => $option2Type,
182 'max_option_price' => $option2MaxPrice,
183 'min_option_price' => $option2MinPrice,
184 'is_require' =>
false,
188 $singleValueOptionId = 3;
189 $singleValueOptionPrice =
'50';
190 $singleValueOptionType =
'text';
195 'id' => $singleValueOptionId,
196 'type' => $singleValueOptionType,
197 'price' => $singleValueOptionPrice,
198 'price_type' =>
'fixed',
199 'is_require' =>
true,
205 $options[] = $singleValueOptions[0];
206 $this->product->expects($this->once())
207 ->method(
'getOptions')
208 ->will($this->returnValue(
$options));
212 'option_id' => $option1Id,
213 'type' => $option1Type,
214 'min' => $option1MinPrice,
215 'max' => $option1MaxPrice,
218 'option_id' => $option2Id,
219 'type' => $option2Type,
221 'max' => $option2MaxPrice + $option2MinPrice,
224 'option_id' => $singleValueOptionId,
225 'type' => $singleValueOptionType,
226 'min' => $singleValueOptionPrice,
227 'max' => $singleValueOptionPrice,
230 $result = $this->
object->getValue();
231 $this->assertEquals($expectedResult,
$result);
237 $option1MaxPrice = 100;
238 $option1MinPrice = 10;
239 $option1Type =
'select';
242 $option2MaxPrice = 200;
243 $option2MinPrice = 20;
244 $option2Type =
'choice';
249 'type' => $option1Type,
250 'max_option_price' => $option1MaxPrice,
251 'min_option_price' => $option1MinPrice,
252 'is_require' =>
true,
256 'type' => $option2Type,
257 'max_option_price' => $option2MaxPrice,
258 'min_option_price' => $option2MinPrice,
259 'is_require' =>
false,
264 $this->product->expects($this->any())
265 ->method(
'getOptions')
266 ->will($this->returnValue(
$options));
268 $convertMinValue = $option1MinPrice / 2;
269 $convertedMaxValue = ($option2MaxPrice + $option1MaxPrice) / 2;
270 $this->priceCurrencyMock->expects($this->at(0))
271 ->method(
'convertAndRound')
272 ->with($option1MinPrice)
273 ->willReturn($convertMinValue);
274 $this->priceCurrencyMock->expects($this->at(1))
275 ->method(
'convertAndRound')
276 ->with($option2MaxPrice + $option1MaxPrice)
277 ->willReturn($convertedMaxValue);
278 $this->assertEquals($option1MinPrice / 2, $this->object->getCustomOptionRange(
true));
279 $this->assertEquals($convertedMaxValue, $this->object->getCustomOptionRange(
false));
288 $optionValueMock = $this->getMockBuilder(\
Magento\Catalog\Model\Product\Option\Value::class)
289 ->disableOriginalConstructor()
290 ->setMethods([
'getPriceType',
'getPrice',
'getId',
'__wakeup',
'getOption',
'getData'])
292 $optionValueMock->expects($this->any())
293 ->method(
'getPriceType')
294 ->will($this->returnValue(
'percent'));
295 $optionValueMock->expects($this->any())
297 ->with($this->equalTo(
true))
298 ->will($this->returnValue(
$price));
300 $optionValueMock->expects($this->any())
305 $optionMock = $this->getMockBuilder(\
Magento\Catalog\Model\Product\Option::class)
306 ->disableOriginalConstructor()
307 ->setMethods([
'getProduct'])
310 $optionValueMock->expects($this->any())->method(
'getOption')->willReturn($optionMock);
312 $optionMock->expects($this->any())->method(
'getProduct')->willReturn($this->product);
314 $priceMock = $this->getMockBuilder(\
Magento\Framework\Pricing\Price\PriceInterface::class)
315 ->disableOriginalConstructor()
316 ->setMethods([
'getValue'])
317 ->getMockForAbstractClass();
318 $priceMock->method(
'getValue')->willReturn(
$price);
320 $this->priceInfo->method(
'getPrice')->willReturn($priceMock);
322 return $optionValueMock;
333 $optionType =
'select';
334 $optionValueMock = $this->getMockBuilder(\
Magento\Catalog\Model\Product\Option\DefaultType::class)
335 ->disableOriginalConstructor()
336 ->setMethods([
'getValue'])
338 $optionMock = $this->getMockBuilder(\
Magento\Catalog\Model\Product\Option::class)
339 ->disableOriginalConstructor()
340 ->setMethods([
'getId',
'getType',
'groupFactory',
'__wakeup'])
342 $groupMock = $this->getMockBuilder(\
Magento\Catalog\Model\Product\Option\Type\Select::class)
343 ->disableOriginalConstructor()
344 ->setMethods([
'setOption',
'setConfigurationItemOption',
'getOptionPrice'])
347 $groupMock->expects($this->once())
348 ->method(
'setOption')
349 ->with($this->equalTo($optionMock))
350 ->will($this->returnSelf());
351 $groupMock->expects($this->once())
352 ->method(
'setConfigurationItemOption')
353 ->with($this->equalTo($optionValueMock))
354 ->will($this->returnSelf());
355 $groupMock->expects($this->once())
356 ->method(
'getOptionPrice')
357 ->with($this->equalTo(
$optionValue), $this->equalTo(0.))
359 $optionMock->expects($this->at(0))
361 ->will($this->returnValue($optionId1));
362 $optionMock->expects($this->once())
364 ->will($this->returnValue($optionType));
365 $optionMock->expects($this->once())
366 ->method(
'groupFactory')
367 ->with($this->equalTo($optionType))
368 ->will($this->returnValue($groupMock));
369 $optionValueMock->expects($this->once())
372 $optionIds = new \Magento\Framework\DataObject([
'value' =>
'1,2']);
376 $this->product->expects($this->at(0))
377 ->method(
'getOptionById')
378 ->with($this->equalTo($optionId1))
379 ->will($this->returnValue($optionMock));
380 $this->product->expects($this->at(1))
381 ->method(
'getOptionById')
382 ->with($this->equalTo($optionId2))
383 ->will($this->returnValue(
null));
386 $result = $this->
object->getSelectedOptions();
398 $expected = [
$id => [
$price => [
'base_amount' =>
$price,
'adjustment' => $displayValue]]];
400 $this->
amount->expects($this->once())
402 ->will($this->returnValue(120));
404 $this->calculator->expects($this->once())
405 ->method(
'getAmount')
406 ->will($this->returnValue($this->
amount));
409 $optionValueMock->expects($this->once())
411 ->will($this->returnValue(
$id));
412 $optionItemMock = $this->getMockBuilder(\
Magento\Catalog\Model\Product\Option::class)
413 ->disableOriginalConstructor()
414 ->setMethods([
'getValues',
'__wakeup'])
416 $optionItemMock->expects($this->any())
417 ->method(
'getValues')
418 ->will($this->returnValue([$optionValueMock]));
420 $this->product->expects($this->once())
421 ->method(
'getOptions')
422 ->will($this->returnValue(
$options));
423 $result = $this->
object->getOptions();
424 $this->assertEquals($expected,
$result);
425 $result = $this->
object->getOptions();
426 $this->assertEquals($expected,
$result);
getOptionValueMock($price)
if( $block->displayPriceExclTax()||$block->displayBothPrices())(__('Excl. Tax')) ?>"> <?php if ($block -> displayPriceWithWeeeDetails()): ?> <span class="cart-tax-total" data-mage-init=' Magento Weee Helper Data Magento Weee Helper Data title amount
setupOptions(array $optionsData)
testGetCustomOptionRange()
setupSingleValueOptions($optionsData)
const PRODUCT_QUANTITY_DEFAULT
const OPTION_TYPE_CHECKBOX