Skip to content

Commit

Permalink
Merge pull request magento#7491 from magento-gl/L3_Arrows_PR_20220301
Browse files Browse the repository at this point in the history
L3 arrows pr 20220301
  • Loading branch information
viktym authored Mar 22, 2022
2 parents 06be96e + c3a7ad9 commit bbaa528
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ define([

return;
}

// if script already loaded by other library
if (window.YT) {
videoRegister.register('youtube', true);
$(window).trigger('youtubeapiready');

return;
}
videoRegister.register('youtube');

element = document.createElement('script');
Expand Down
26 changes: 26 additions & 0 deletions app/code/Magento/Search/ViewModel/AdditionalSearchFormData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Search\ViewModel;

use Magento\Framework\View\Element\Block\ArgumentInterface;

/**
* View model for search additional form params
*/
class AdditionalSearchFormData implements ArgumentInterface
{
/**
* Return search query params
*
* @return array
*/
public function getFormData(): array
{
return [];
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Search/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml">
<arguments>
<argument name="configProvider" xsi:type="object">Magento\Search\ViewModel\ConfigProvider</argument>
<argument name="additionalSearchFormData" xsi:type="object">Magento\Search\ViewModel\AdditionalSearchFormData</argument>
</arguments>
</block>
</referenceContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
/** @var $escaper \Magento\Framework\Escaper */
/** @var $configProvider \Magento\Search\ViewModel\ConfigProvider */
$configProvider = $block->getData('configProvider');
/** @var $versionManager \Magento\Search\ViewModel\AdditionalSearchFormData */
$additionalSearchFormData = $block->getData('additionalSearchFormData');
/** @var $helper \Magento\Search\Helper\Data */
$helper = $configProvider->getSearchHelperData();
$allowedSuggestion = $configProvider->isSuggestionsAllowed();
Expand All @@ -20,6 +22,12 @@ $quickSearchUrl = $allowedSuggestion ? $escaper->escapeUrl($helper->getSuggestUr
<div class="block block-content">
<form class="form minisearch" id="search_mini_form"
action="<?= $escaper->escapeUrl($helper->getResultUrl()) ?>" method="get">
<?php if (!empty($queryParams = $additionalSearchFormData->getFormData())): ?>
<?php foreach ($queryParams as $param): ?>
<input type="hidden" name="<?= $escaper->escapeHtmlAttr($param['name']) ?>"
value="<?= $escaper->escapeHtmlAttr($param['value']) ?>"/>
<?php endforeach; ?>
<?php endif; ?>
<div class="field search">
<label class="label" for="search" data-role="minisearch-label">
<span><?= $escaper->escapeHtml(__('Search')) ?></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ConfigurableProduct extends AbstractPrice
/**
* Price type final.
*/
const PRICE_CODE = 'final_price';
public const PRICE_CODE = 'final_price';

/**
* @var ItemInterface
Expand Down Expand Up @@ -58,7 +58,28 @@ public function getConfiguredRegularAmount(): \Magento\Framework\Pricing\Amount\
public function getValue()
{
$price = $this->getProduct()->getPriceInfo()->getPrice(self::PRICE_CODE)->getValue();

/** @var \Magento\Catalog\Model\Product $product */
$product = parent::getProduct();
/** @var \Magento\Wishlist\Model\Item\Option $configurableCustomOption */
$configurableCustomOption = $product->getCustomOption('option_ids');
$customPrice = 0;
if ($configurableCustomOption && $configurableCustomOption->getValue()) {
$item = $this->item;
$configurableProduct = $configurableCustomOption->getProduct();
foreach (explode(',', $configurableCustomOption->getValue()) as $optionId) {
$option = $configurableProduct->getOptionById($optionId);
if ($option) {
$itemOption = $item->getOptionByCode('option_' . $option->getId());
/** @var $group \Magento\Catalog\Model\Product\Option\Type\DefaultType */
$group = $option->groupFactory($option->getType())
->setOption($option);
$customPrice += $group->getOptionPrice($itemOption->getValue(), $price);
}
}
}
if ($customPrice) {
$price = $price + $customPrice;
}
return max(0, $price);
}

Expand All @@ -78,6 +99,7 @@ public function getProduct()
{
/** @var \Magento\Catalog\Model\Product $product */
$product = parent::getProduct();

/** @var \Magento\Wishlist\Model\Item\Option $customOption */
$customOption = $product->getCustomOption('simple_product');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
namespace Magento\Wishlist\Test\Unit\Pricing\ConfiguredPrice;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
use Magento\Catalog\Model\Product\Option\Type\DefaultType;
use Magento\Catalog\Model\Product\Option as ProductOption;
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
Expand All @@ -19,6 +23,9 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ConfigurableProductTest extends TestCase
{
/**
Expand Down Expand Up @@ -72,9 +79,16 @@ protected function setUp(): void
);
}

public function testGetValue()
/**
* @param array $options
*
* @dataProvider setOptionsDataProvider
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function testGetValue(array $options, $optionIds)
{
$priceValue = 10;
$customPrice = 100;

$priceMock = $this->getMockBuilder(PriceInterface::class)
->getMockForAbstractClass();
Expand All @@ -100,14 +114,66 @@ public function testGetValue()
$wishlistItemOptionMock = $this->getMockBuilder(Option::class)
->disableOriginalConstructor()
->getMock();
$wishlistItemOptionMock->expects($this->once())
->method('getProduct')
->willReturn($productMock);
$wishlistItemOptionMock->expects($this->exactly(2))
->method('getProduct')->willReturn($productMock);

$this->saleableItem->expects($this->once())
$this->saleableItem->expects($this->any())
->method('getCustomOption')
->with('simple_product')
->willReturn($wishlistItemOptionMock);
->withConsecutive(['simple_product'], ['option_ids'])
->willReturnOnConsecutiveCalls($wishlistItemOptionMock, $wishlistItemOptionMock);

$wishlistItemOptionMock->expects($this->any())
->method('getValue')->willReturn($optionIds);

$wishlistItemOptionMock->expects($this->exactly(2))
->method('getProduct')->willReturn($productMock);

$productOptionMock = $this->getMockBuilder(ProductOption::class)
->disableOriginalConstructor()
->getMock();

$defaultTypeMock = $this->getMockBuilder(DefaultType::class)
->disableOriginalConstructor()
->getMock();

$productOptionMock->expects($this->any())
->method('getId')
->willReturn($options['option_id']);
$productOptionMock->expects($this->any())
->method('getType')
->willReturn($options['type']);

$productOptionMock->expects($this->any())
->method('groupFactory')
->with($options['type'])
->willReturn($defaultTypeMock);
$productMock->expects($this->any())
->method('getOptionById')
->with($options['option_id'])->willReturn($productOptionMock);
$defaultTypeMock->expects($this->any())
->method('setOption')
->with($productOptionMock)
->willReturnSelf();

$itemMock = $this->getMockForAbstractClass(ItemInterface::class);
$this->model->setItem($itemMock);

$optionInterfaceMock = $this->getMockForAbstractClass(OptionInterface::class);

$itemMock->expects($this->any())
->method('getOptionByCode')
->with('option_'.$options['option_id'])
->willReturn($optionInterfaceMock);

$optionInterfaceMock->expects($this->any())
->method('getValue')
->willReturn($productOptionMock);

$defaultTypeMock->expects($this->any())
->method('getOptionPrice')
->with($productOptionMock, $priceValue)
->willReturn($customPrice);
$priceValue += $customPrice;

$this->assertEquals($priceValue, $this->model->getValue());
}
Expand All @@ -122,10 +188,10 @@ public function testGetValueWithNoCustomOption()
->method('getValue')
->willReturn($priceValue);

$this->saleableItem->expects($this->once())
$this->saleableItem->expects($this->any())
->method('getCustomOption')
->with('simple_product')
->willReturn(null);
->withConsecutive(['simple_product'], ['option_ids'])
->willReturnOnConsecutiveCalls(null, null);

$this->saleableItem->expects($this->once())
->method('getPriceInfo')
Expand All @@ -138,4 +204,36 @@ public function testGetValueWithNoCustomOption()

$this->assertEquals(100, $this->model->getValue());
}

public function setOptionsDataProvider(): array
{
return ['options' =>
[
[
'option_id' => '1',
'product_id' => '2091',
'type' => 'checkbox',
'is_require' => '1',
'default_title' => 'check',
'title' => 'check',
'default_price' => null,
'default_price_type' => null,
'price' => null,
'price_type' => null
], '1',
[
'option_id' => '2',
'product_id' => '2091',
'type' => 'field',
'is_require' => '1',
'default_title' => 'field',
'title' => 'field',
'default_price' => '100.000000',
'default_price_type' => 'fixed',
'price' => '100.000000',
'price_type' => 'fixed'
], '2'
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,18 @@ public function testEscapeSearchText(string $searchValue, string $expectedOutput
/** @var Result $searchResultBlock */
$searchResultBlock = $this->layout->createBlock(Result::class);
/** @var Template $searchBlock */
$searchQueryParams = $this->getMockBuilder(\Magento\Search\ViewModel\AdditionalSearchFormData::class)
->disableOriginalConstructor()
->setMethods(['getFormData'])
->getMock();
$searchQueryParams->expects($this->any())
->method('getFormData')
->willReturn([]);
$searchBlock = $this->layout->createBlock(Template::class);
$searchBlock->setData(['configProvider' => $this->configProvider]);
$searchBlock->setData([
'configProvider' => $this->configProvider,
'additionalSearchFormData' => $searchQueryParams,
]);
$searchBlock->setTemplate('Magento_Search::form.mini.phtml');
/** @var RequestInterface $request */
$request = $this->objectManager->get(RequestInterface::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,16 @@ protected function setAcceptType()
{
$this->acceptType = 'html';

$rawAcceptType = $this->request->getHeader('Accept');
if (strpos($rawAcceptType, 'json') !== false) {
$this->acceptType = 'json';
} elseif (strpos($rawAcceptType, 'html') !== false) {
$this->acceptType = 'html';
} elseif (strpos($rawAcceptType, 'xml') !== false) {
$this->acceptType = 'xml';
$acceptTypes = $this->getSortedAcceptHeader();
foreach ($acceptTypes as $acceptType) {
if (strpos($acceptType, 'json') !== false) {
$this->acceptType = 'json';
} elseif (strpos($acceptType, 'html') !== false) {
$this->acceptType = 'html';
} elseif (strpos($acceptType, 'xml') !== false) {
$this->acceptType = 'xml';
}
break;
}
}

Expand Down Expand Up @@ -408,4 +411,32 @@ public function getUiComponentFactory()
{
return $this->uiComponentFactory;
}

/**
* Returns sorted accept header based on q value
*
* @return array
*/
private function getSortedAcceptHeader()
{
$acceptTypes = [];
$acceptHeader = $this->request->getHeader('Accept');
$contentTypes = explode(',', $acceptHeader);
foreach ($contentTypes as $contentType) {
// the default quality is 1.
$q = 1;
// check if there is a different quality
if (strpos($contentType, ';q=') !== false) {
list($contentType, $q) = explode(';q=', $contentType);
}

if (array_key_exists($q, $acceptTypes)) {
$acceptTypes[$q] = $acceptTypes[$q] . ',' . $contentType;
} else {
$acceptTypes[$q] = $contentType;
}
}
krsort($acceptTypes);
return array_values($acceptTypes);
}
}
Loading

0 comments on commit bbaa528

Please sign in to comment.