Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.3-develop' into 2.3-develop-gr…
Browse files Browse the repository at this point in the history
…aphql-PR-yogesh-5
  • Loading branch information
naydav committed Mar 26, 2019
2 parents 14d5c3d + 4f6c78e commit 2643424
Show file tree
Hide file tree
Showing 67 changed files with 1,910 additions and 307 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,25 +282,23 @@ public function getGridIdsJson()
if (!$this->getUseSelectAll()) {
return '';
}
/** @var \Magento\Framework\Data\Collection $allIdsCollection */
$allIdsCollection = clone $this->getParentBlock()->getCollection();

if ($this->getMassactionIdField()) {
$massActionIdField = $this->getMassactionIdField();
/** @var \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $collection */
$collection = clone $this->getParentBlock()->getCollection();

if ($collection instanceof AbstractDb) {
$idsSelect = clone $collection->getSelect();
$idsSelect->reset(\Magento\Framework\DB\Select::ORDER);
$idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
$idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
$idsSelect->reset(\Magento\Framework\DB\Select::COLUMNS);
$idsSelect->columns($this->getMassactionIdField(), 'main_table');
$idList = $collection->getConnection()->fetchCol($idsSelect);
} else {
$massActionIdField = $this->getParentBlock()->getMassactionIdField();
$idList = $collection->setPageSize(0)->getColumnValues($this->getMassactionIdField());
}

if ($allIdsCollection instanceof AbstractDb) {
$allIdsCollection->getSelect()->limit();
$allIdsCollection->clear();
}

$gridIds = $allIdsCollection->setPageSize(0)->getColumnValues($massActionIdField);
if (!empty($gridIds)) {
return join(",", $gridIds);
}
return '';
return implode(',', $idList);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,62 +269,6 @@ public function testGetGridIdsJsonWithoutUseSelectAll()
$this->assertEmpty($this->_block->getGridIdsJson());
}

/**
* @param array $items
* @param string $result
*
* @dataProvider dataProviderGetGridIdsJsonWithUseSelectAll
*/
public function testGetGridIdsJsonWithUseSelectAll(array $items, $result)
{
$this->_block->setUseSelectAll(true);

if ($this->_block->getMassactionIdField()) {
$massActionIdField = $this->_block->getMassactionIdField();
} else {
$massActionIdField = $this->_block->getParentBlock()->getMassactionIdField();
}

$collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
->disableOriginalConstructor()
->getMock();

$this->_gridMock->expects($this->once())
->method('getCollection')
->willReturn($collectionMock);
$collectionMock->expects($this->once())
->method('setPageSize')
->with(0)
->willReturnSelf();
$collectionMock->expects($this->once())
->method('getColumnValues')
->with($massActionIdField)
->willReturn($items);

$this->assertEquals($result, $this->_block->getGridIdsJson());
}

/**
* @return array
*/
public function dataProviderGetGridIdsJsonWithUseSelectAll()
{
return [
[
[],
'',
],
[
[1],
'1',
],
[
[1, 2, 3],
'1,2,3',
],
];
}

/**
* @param string $itemId
* @param array|\Magento\Framework\DataObject $item
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Model\Products;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator;
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
use Magento\UrlRewrite\Model\UrlPersistInterface;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;

/**
* Save/Delete UrlRewrites by Product ID's and visibility
*/
class AdaptUrlRewritesToVisibilityAttribute
{
/**
* @var CollectionFactory
*/
private $productCollectionFactory;

/**
* @var ProductUrlRewriteGenerator
*/
private $urlRewriteGenerator;

/**
* @var UrlPersistInterface
*/
private $urlPersist;

/**
* @var ProductUrlPathGenerator
*/
private $urlPathGenerator;

/**
* @param CollectionFactory $collectionFactory
* @param ProductUrlRewriteGenerator $urlRewriteGenerator
* @param UrlPersistInterface $urlPersist
* @param ProductUrlPathGenerator|null $urlPathGenerator
*/
public function __construct(
CollectionFactory $collectionFactory,
ProductUrlRewriteGenerator $urlRewriteGenerator,
UrlPersistInterface $urlPersist,
ProductUrlPathGenerator $urlPathGenerator
) {
$this->productCollectionFactory = $collectionFactory;
$this->urlRewriteGenerator = $urlRewriteGenerator;
$this->urlPersist = $urlPersist;
$this->urlPathGenerator = $urlPathGenerator;
}

/**
* Process Url Rewrites according to the products visibility attribute
*
* @param array $productIds
* @param int $visibility
* @throws UrlAlreadyExistsException
*/
public function execute(array $productIds, int $visibility): void
{
$products = $this->getProductsByIds($productIds);

/** @var Product $product */
foreach ($products as $product) {
if ($visibility == Visibility::VISIBILITY_NOT_VISIBLE) {
$this->urlPersist->deleteByData(
[
UrlRewrite::ENTITY_ID => $product->getId(),
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
]
);
} elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) {
$product->setVisibility($visibility);
$productUrlPath = $this->urlPathGenerator->getUrlPath($product);
$productUrlRewrite = $this->urlRewriteGenerator->generate($product);
$product->unsUrlPath();
$product->setUrlPath($productUrlPath);

try {
$this->urlPersist->replace($productUrlRewrite);
} catch (UrlAlreadyExistsException $e) {
throw new UrlAlreadyExistsException(
__(
'Can not change the visibility of the product with SKU equals "%1". '
. 'URL key "%2" for specified store already exists.',
$product->getSku(),
$product->getUrlKey()
),
$e,
$e->getCode(),
$e->getUrls()
);
}
}
}
}

/**
* Get Product Models by Id's
*
* @param array $productIds
* @return array
*/
private function getProductsByIds(array $productIds): array
{
$productCollection = $this->productCollectionFactory->create();
$productCollection->addAttributeToSelect(ProductInterface::VISIBILITY);
$productCollection->addAttributeToSelect('url_key');
$productCollection->addFieldToFilter(
'entity_id',
['in' => array_unique($productIds)]
);

return $productCollection->getItems();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Observer;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogUrlRewrite\Model\Products\AdaptUrlRewritesToVisibilityAttribute;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;

/**
* Consider URL rewrites on change product visibility via mass action
*/
class ProcessUrlRewriteOnChangeProductVisibilityObserver implements ObserverInterface
{
/**
* @var AdaptUrlRewritesToVisibilityAttribute
*/
private $adaptUrlRewritesToVisibility;

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

/**
* Generate urls for UrlRewrites and save it in storage
*
* @param Observer $observer
* @return void
* @throws UrlAlreadyExistsException
*/
public function execute(Observer $observer)
{
$event = $observer->getEvent();
$attrData = $event->getAttributesData();
$productIds = $event->getProductIds();
$visibility = $attrData[ProductInterface::VISIBILITY] ?? 0;

if (!$visibility || !$productIds) {
return;
}

$this->adaptUrlRewritesToVisibility->execute($productIds, (int)$visibility);
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/CatalogUrlRewrite/etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<event name="catalog_product_save_after">
<observer name="process_url_rewrite_saving" instance="Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver"/>
</event>
<event name="catalog_product_attribute_update_before">
<observer name="process_url_rewrite_on_change_product_visibility" instance="Magento\CatalogUrlRewrite\Observer\ProcessUrlRewriteOnChangeProductVisibilityObserver"/>
</event>
<event name="catalog_category_save_before">
<observer name="category_url_path_autogeneration" instance="Magento\CatalogUrlRewrite\Observer\CategoryUrlPathAutogeneratorObserver"/>
</event>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout_overview">
<block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::multishipping_agreements.phtml"/>
<block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::additional_agreements.phtml"/>
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* See COPYING.txt for license details.
*/

// @deprecated
// @codingStandardsIgnoreFile

?>
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ public function getDirsCollection($path)
$collection = $this->getCollection($path)
->setCollectDirs(true)
->setCollectFiles(false)
->setCollectRecursively(false);
->setCollectRecursively(false)
->setOrder('basename', \Magento\Framework\Data\Collection\Filesystem::SORT_ORDER_ASC);

$conditions = $this->getConditionsForExcludeDirs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ protected function generalTestGetDirsCollection($path, $collectionArray = [], $e
->method('setCollectRecursively')
->with(false)
->willReturnSelf();
$storageCollectionMock->expects($this->once())
->method('setOrder')
->with('basename', \Magento\Framework\Data\Collection\Filesystem::SORT_ORDER_ASC)
->willReturnSelf();
$storageCollectionMock->expects($this->once())
->method('getIterator')
->willReturn(new \ArrayIterator($collectionArray));
Expand Down
6 changes: 4 additions & 2 deletions app/code/Magento/DirectoryGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ type Query {
type Currency {
base_currency_code: String
base_currency_symbol: String
default_display_currecy_code: String
default_display_currecy_symbol: String
default_display_currecy_code: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_code`.")
default_display_currency_code: String
default_display_currecy_symbol: String @deprecated(reason: "Symbol was missed. Use `default_display_currency_symbol`.")
default_display_currency_symbol: String
available_currency_codes: [String]
exchange_rates: [ExchangeRate]
}
Expand Down
8 changes: 5 additions & 3 deletions app/code/Magento/Eav/Model/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -1683,14 +1683,16 @@ public function saveAttribute(DataObject $object, $attributeCode)
$connection->beginTransaction();

try {
$select = $connection->select()->from($table, 'value_id')->where($where);
$origValueId = $connection->fetchOne($select);
$select = $connection->select()->from($table, ['value_id', 'value'])->where($where);
$origRow = $connection->fetchRow($select);
$origValueId = $origRow['value_id'] ?? false;
$origValue = $origRow['value'] ?? null;

if ($origValueId === false && $newValue !== null) {
$this->_insertAttribute($object, $attribute, $newValue);
} elseif ($origValueId !== false && $newValue !== null) {
$this->_updateAttribute($object, $attribute, $origValueId, $newValue);
} elseif ($origValueId !== false && $newValue === null) {
} elseif ($origValueId !== false && $newValue === null && $origValue !== null) {
$connection->delete($table, $where);
}
$this->_processAttributeValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public function build(
array $queryResult,
DataProviderInterface $dataProvider
) {
$buckets = $queryResult['aggregations'][$bucket->getName()]['buckets'] ?? [];
$values = [];
foreach ($queryResult['aggregations'][$bucket->getName()]['buckets'] as $resultBucket) {
foreach ($buckets as $resultBucket) {
$values[$resultBucket['key']] = [
'value' => $resultBucket['key'],
'count' => $resultBucket['doc_count'],
];
}

return $values;
}
}
Loading

0 comments on commit 2643424

Please sign in to comment.