Skip to content

Commit

Permalink
merge magento/2.4-develop into magento-honey-badgers/MC-23303
Browse files Browse the repository at this point in the history
  • Loading branch information
magento-mts-svc authored Feb 4, 2020
2 parents f4b4fa2 + 606c3e8 commit 31d51e8
Show file tree
Hide file tree
Showing 52 changed files with 1,469 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ define([
*/
onError: function () {
self.showError($t('Payment ' + self.getTitle() + ' can\'t be initialized'));
self.reInitPayPal();
}
}, self.paypalButtonSelector);
},
Expand Down
32 changes: 26 additions & 6 deletions app/code/Magento/Catalog/Block/Ui/ProductViewCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
namespace Magento\Catalog\Block\Ui;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\ProductRenderFactory;
use Magento\Catalog\Model\ProductRepository;
use Magento\Catalog\Ui\DataProvider\Product\ProductRenderCollectorComposite;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\EntityManager\Hydrator;
use Magento\Framework\Registry;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\Url;
use Magento\Framework\View\Element\Template;
use Magento\Store\Model\Store;
use Magento\Catalog\Model\ProductRenderFactory;
use Magento\Catalog\Model\ProductRepository;
use Magento\Framework\EntityManager\Hydrator;
use Magento\Store\Model\StoreManager;

/**
Expand All @@ -25,6 +27,7 @@
*
* @api
* @since 101.1.0
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ProductViewCounter extends Template
{
Expand Down Expand Up @@ -68,6 +71,13 @@ class ProductViewCounter extends Template
*/
private $registry;

/**
* Core store config
*
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @param Template\Context $context
* @param ProductRepository $productRepository
Expand All @@ -78,6 +88,8 @@ class ProductViewCounter extends Template
* @param SerializerInterface $serialize
* @param Url $url
* @param Registry $registry
* @param ScopeConfigInterface|null $scopeConfig
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Template\Context $context,
Expand All @@ -88,7 +100,8 @@ public function __construct(
Hydrator $hydrator,
SerializerInterface $serialize,
Url $url,
Registry $registry
Registry $registry,
?ScopeConfigInterface $scopeConfig = null
) {
parent::__construct($context);
$this->productRepository = $productRepository;
Expand All @@ -99,6 +112,7 @@ public function __construct(
$this->serialize = $serialize;
$this->url = $url;
$this->registry = $registry;
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
}

/**
Expand All @@ -116,14 +130,19 @@ public function getCurrentProductData()
{
/** @var ProductInterface $product */
$product = $this->registry->registry('product');
$productsScope = $this->scopeConfig->getValue(
'catalog/recently_products/scope',
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE
);
/** @var Store $store */
$store = $this->storeManager->getStore();

if (!$product || !$product->getId()) {
return $this->serialize->serialize([
'items' => [],
'store' => $store->getId(),
'currency' => $store->getCurrentCurrency()->getCode()
'currency' => $store->getCurrentCurrency()->getCode(),
'productCurrentScope' => $productsScope
]);
}

Expand All @@ -140,7 +159,8 @@ public function getCurrentProductData()
$product->getId() => $data
],
'store' => $store->getId(),
'currency' => $store->getCurrentCurrency()->getCode()
'currency' => $store->getCurrentCurrency()->getCode(),
'productCurrentScope' => $productsScope
];

return $this->serialize->serialize($currentProductData);
Expand Down
28 changes: 26 additions & 2 deletions app/code/Magento/Catalog/CustomerData/CompareProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
namespace Magento\Catalog\CustomerData;

use Magento\Customer\CustomerData\SectionSourceInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\LocalizedException;

/**
* Catalog Product Compare Widget
*/
class CompareProducts implements SectionSourceInterface
{
/**
Expand All @@ -24,23 +30,33 @@ class CompareProducts implements SectionSourceInterface
*/
private $outputHelper;

/**
* Core store config
*
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @param \Magento\Catalog\Helper\Product\Compare $helper
* @param \Magento\Catalog\Model\Product\Url $productUrl
* @param \Magento\Catalog\Helper\Output $outputHelper
* @param ScopeConfigInterface|null $scopeConfig
*/
public function __construct(
\Magento\Catalog\Helper\Product\Compare $helper,
\Magento\Catalog\Model\Product\Url $productUrl,
\Magento\Catalog\Helper\Output $outputHelper
\Magento\Catalog\Helper\Output $outputHelper,
?ScopeConfigInterface $scopeConfig = null
) {
$this->helper = $helper;
$this->productUrl = $productUrl;
$this->outputHelper = $outputHelper;
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getSectionData()
{
Expand All @@ -54,18 +70,26 @@ public function getSectionData()
}

/**
* Get the list of compared product items
*
* @return array
* @throws LocalizedException
*/
protected function getItems()
{
$items = [];
$productsScope = $this->scopeConfig->getValue(
'catalog/recently_products/scope',
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE
);
/** @var \Magento\Catalog\Model\Product $item */
foreach ($this->helper->getItemCollection() as $item) {
$items[] = [
'id' => $item->getId(),
'product_url' => $this->productUrl->getUrl($item),
'name' => $this->outputHelper->productAttribute($item, $item->getName(), 'name'),
'remove_url' => $this->helper->getPostDataRemove($item),
'productScope' => $productsScope
];
}
return $items;
Expand Down
57 changes: 47 additions & 10 deletions app/code/Magento/Catalog/Model/ResourceModel/Product/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Catalog\Model\ResourceModel\Product;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;

/**
Expand All @@ -14,6 +15,32 @@
*/
class Action extends \Magento\Catalog\Model\ResourceModel\AbstractResource
{
/**
* @var \Magento\Framework\Stdlib\DateTime\DateTime
*/
private $dateTime;

/**
* @param \Magento\Eav\Model\Entity\Context $context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Catalog\Model\Factory $modelFactory
* @param \Magento\Eav\Model\Entity\Attribute\UniqueValidationInterface $uniqueValidator
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
* @param array $data
*/
public function __construct(
\Magento\Eav\Model\Entity\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Model\Factory $modelFactory,
\Magento\Eav\Model\Entity\Attribute\UniqueValidationInterface $uniqueValidator,
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
$data = []
) {
parent::__construct($context, $storeManager, $modelFactory, $data, $uniqueValidator);

$this->dateTime = $dateTime;
}

/**
* Initialize connection
*
Expand Down Expand Up @@ -43,6 +70,7 @@ public function updateAttributes($entityIds, $attrData, $storeId)
$object = new \Magento\Framework\DataObject();
$object->setStoreId($storeId);

$attrData[ProductInterface::UPDATED_AT] = $this->dateTime->gmtDate();
$this->getConnection()->beginTransaction();
try {
foreach ($attrData as $attrCode => $value) {
Expand Down Expand Up @@ -95,7 +123,7 @@ protected function _saveAttributeValue($object, $attribute, $value)
* for default store id
* In this case we clear all not default values
*/
if ($this->_storeManager->hasSingleStore()) {
if ($this->_storeManager->hasSingleStore() && !$attribute->isStatic()) {
$storeId = $this->getDefaultStoreId();
$connection->delete(
$table,
Expand All @@ -107,17 +135,24 @@ protected function _saveAttributeValue($object, $attribute, $value)
);
}

$data = new \Magento\Framework\DataObject(
[
'attribute_id' => $attribute->getAttributeId(),
'store_id' => $storeId,
$this->getLinkField() => $entityId,
'value' => $this->_prepareValueForSave($value, $attribute),
]
);
$data = $attribute->isStatic()
? new \Magento\Framework\DataObject(
[
$this->getLinkField() => $entityId,
$attribute->getAttributeCode() => $this->_prepareValueForSave($value, $attribute),
]
)
: new \Magento\Framework\DataObject(
[
'attribute_id' => $attribute->getAttributeId(),
'store_id' => $storeId,
$this->getLinkField() => $entityId,
'value' => $this->_prepareValueForSave($value, $attribute),
]
);
$bind = $this->_prepareDataForTable($data, $table);

if ($attribute->isScopeStore()) {
if ($attribute->isScopeStore() || $attribute->isStatic()) {
/**
* Update attribute value for store
*/
Expand All @@ -143,6 +178,8 @@ protected function _saveAttributeValue($object, $attribute, $value)
}

/**
* Resolve entity id
*
* @param int $entityId
* @return int
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@

namespace Magento\Catalog\Test\Unit\Block\Ui;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\Data\ProductRenderInterface;
use Magento\Catalog\Block\Ui\ProductViewCounter;
use Magento\Catalog\Model\ProductRenderFactory;
use Magento\Catalog\Model\ProductRepository;
use Magento\Catalog\Ui\DataProvider\Product\ProductRenderCollectorComposite;
use Magento\Catalog\Model\ProductRenderFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\EntityManager\Hydrator;
use Magento\Framework\Registry;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\Url;
use Magento\Framework\View\Element\Template\Context;
use Magento\Store\Model\StoreManager;
use Magento\Store\Model\Store;
use Magento\Framework\Registry;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\Data\ProductRenderInterface;
use Magento\Catalog\Block\Ui\ProductViewCounter;
use Magento\Store\Model\StoreManager;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -70,6 +71,11 @@ class ProductViewCounterTest extends \PHPUnit\Framework\TestCase
*/
private $storeManagerMock;

/**
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $scopeConfigMock;

/**
* @var ProductRenderFactory|\PHPUnit_Framework_MockObject_MockObject
*/
Expand Down Expand Up @@ -104,6 +110,9 @@ protected function setUp()
$this->storeManagerMock = $this->getMockBuilder(StoreManager::class)
->disableOriginalConstructor()
->getMock();
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
->disableOriginalConstructor()
->getMock();

$this->productViewCounter = new ProductViewCounter(
$this->contextMock,
Expand All @@ -114,7 +123,8 @@ protected function setUp()
$this->hydratorMock,
$this->serializeMock,
$this->urlMock,
$this->registryMock
$this->registryMock,
$this->scopeConfigMock
);
}

Expand Down
Loading

0 comments on commit 31d51e8

Please sign in to comment.