Skip to content

Commit

Permalink
Merge pull request magento#150 from magento-sparta/2-0-8-backlog
Browse files Browse the repository at this point in the history
[SUPPORT] MDVA-387: Bugfix Release 2.0.8
  • Loading branch information
Oleksii Korshenko authored Jul 14, 2016
2 parents 7508f98 + bfaeaf1 commit 87b7b5f
Show file tree
Hide file tree
Showing 44 changed files with 1,687 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ public function __construct(
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$this->attributeHelper->setProductIds($collection->getAllIds());
if ($this->getRequest()->getParam('filters')) {
$collection = $this->filter->getCollection($this->collectionFactory->create());
$this->attributeHelper->setProductIds($collection->getAllIds());
}

if (!$this->_validateProducts()) {
return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\Action\Attribute;

class EditTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save */
private $object;

/** @var \Magento\Catalog\Helper\Product\Edit\Action\Attribute|\PHPUnit_Framework_MockObject_MockObject */
private $attributeHelper;

/** @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject */
private $resultRedirectFactory;

/** @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject */
private $filter;

/** @var \Magento\Backend\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject */
private $context;

/** @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject */
private $collectionFactory;

/** @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject */
private $resultPage;

/** @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject */
private $request;

protected function setUp()
{
$this->attributeHelper = $this->getMockBuilder('Magento\Catalog\Helper\Product\Edit\Action\Attribute')
->setMethods(['getProductIds', 'setProductIds'])
->disableOriginalConstructor()->getMock();

$this->resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory')
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$this->filter = $this->getMockBuilder('Magento\Ui\Component\MassAction\Filter')
->setMethods(['getCollection'])->disableOriginalConstructor()->getMock();

$this->collectionFactory = $this->getMockBuilder(
'Magento\Catalog\Model\ResourceModel\Product\CollectionFactory'
)->setMethods(['create'])->disableOriginalConstructor()->getMock();

$this->resultPage = $this->getMockBuilder('Magento\Framework\View\Result\Page')
->setMethods(['getConfig'])->disableOriginalConstructor()->getMock();

$resultPageFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory')
->setMethods(['create'])->disableOriginalConstructor()->getMock();
$resultPageFactory->expects($this->any())->method('create')->willReturn($this->resultPage);

$this->prepareContext();

$this->object = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
'Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Edit',
[
'context' => $this->context,
'attributeHelper' => $this->attributeHelper,
'filter' => $this->filter,
'resultPageFactory' => $resultPageFactory,
'collectionFactory' => $this->collectionFactory
]
);
}

private function prepareContext()
{
$this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->setMethods(['getParam', 'getParams', 'setParams'])
->disableOriginalConstructor()->getMock();

$objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
$product = $this->getMockBuilder('Magento\Catalog\Model\Product')
->setMethods(['isProductsHasSku'])
->disableOriginalConstructor()->getMock();
$product->expects($this->any())->method('isProductsHasSku')
->with([1, 2, 3])
->willReturn(true);
$objectManager->expects($this->any())->method('create')
->with('Magento\Catalog\Model\Product')
->willReturn($product);
$messageManager = $this->getMockBuilder('\Magento\Framework\Message\ManagerInterface')
->setMethods([])
->disableOriginalConstructor()->getMock();
$messageManager->expects($this->any())->method('addError')->willReturn(true);
$this->context = $this->getMockBuilder('Magento\Backend\App\Action\Context')
->setMethods(['getRequest', 'getObjectManager', 'getMessageManager', 'getResultRedirectFactory'])
->disableOriginalConstructor()->getMock();
$this->context->expects($this->any())->method('getRequest')->willReturn($this->request);
$this->context->expects($this->any())->method('getObjectManager')->willReturn($objectManager);
$this->context->expects($this->any())->method('getMessageManager')->willReturn($messageManager);
$this->context->expects($this->any())->method('getResultRedirectFactory')
->willReturn($this->resultRedirectFactory);
}

public function testExecutePageRequested()
{
$this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(['placeholder' => true]);
$this->request->expects($this->any())->method('getParams')->willReturn(
[
'namespace' => 'product_listing',
'exclude' => true,
'filters' => ['placeholder' => true]
]
);

$this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn([1, 2, 3]);
$this->attributeHelper->expects($this->any())->method('setProductIds')->with([1, 2, 3]);

$collection = $this->getMockBuilder('Magento\Catalog\Model\ResourceModel\Product\Collection')
->setMethods(['getAllIds'])
->disableOriginalConstructor()->getMock();
$collection->expects($this->any())->method('getAllIds')->willReturn([1, 2, 3]);
$this->filter->expects($this->any())->method('getCollection')->with($collection)->willReturn($collection);
$this->collectionFactory->expects($this->any())->method('create')->willReturn($collection);

$title = $this->getMockBuilder('Magento\Framework\View\Page\Title')
->setMethods(['prepend'])
->disableOriginalConstructor()->getMock();
$config = $this->getMockBuilder('Magento\Framework\View\Page\Config')
->setMethods(['getTitle'])
->disableOriginalConstructor()->getMock();
$config->expects($this->any())->method('getTitle')->willReturn($title);
$this->resultPage->expects($this->any())->method('getConfig')->willReturn($config);

$this->assertSame($this->resultPage, $this->object->execute());
}

public function testExecutePageReload()
{
$this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(null);
$this->request->expects($this->any())->method('getParams')->willReturn([]);

$this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn([1, 2, 3]);
$this->attributeHelper->expects($this->any())->method('setProductIds')->with([1, 2, 3]);

$title = $this->getMockBuilder('Magento\Framework\View\Page\Title')
->setMethods(['prepend'])
->disableOriginalConstructor()->getMock();
$config = $this->getMockBuilder('Magento\Framework\View\Page\Config')
->setMethods(['getTitle'])
->disableOriginalConstructor()->getMock();
$config->expects($this->any())->method('getTitle')->willReturn($title);
$this->resultPage->expects($this->any())->method('getConfig')->willReturn($config);

$this->assertSame($this->resultPage, $this->object->execute());
}

public function testExecutePageDirectAccess()
{
$this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(null);
$this->request->expects($this->any())->method('getParams')->willReturn([]);
$this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn(null);

$resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect')
->setMethods(['setPath'])
->disableOriginalConstructor()
->getMock();
$resultRedirect->expects($this->any())->method('setPath')
->with('catalog/product/', ['_current' => true])
->willReturnSelf();
$this->resultRedirectFactory->expects($this->any())
->method('create')
->willReturn($resultRedirect);

$this->assertSame($resultRedirect, $this->object->execute());
}
}
16 changes: 15 additions & 1 deletion app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\ImportExport\Model\Import;
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
use Magento\Catalog\Model\Product\Visibility;

/**
* Import entity product model
Expand Down Expand Up @@ -2237,7 +2238,8 @@ public function validateRow(array $rowData, $rowNum)
}
// validate custom options
$this->getOptionEntity()->validateRow($rowData, $rowNum);
if (!empty($rowData[self::URL_KEY]) || !empty($rowData[self::COL_NAME])) {

if ($this->isNeedToValidateUrlKey($rowData)) {
$urlKey = $this->getUrlKey($rowData);
$storeCodes = empty($rowData[self::COL_STORE_VIEW_CODE])
? array_flip($this->storeResolver->getStoreCodeToId())
Expand All @@ -2259,6 +2261,18 @@ public function validateRow(array $rowData, $rowNum)
return !$this->getErrorAggregator()->isRowInvalid($rowNum);
}

/**
* @param array $rowData
* @return bool
*/
private function isNeedToValidateUrlKey($rowData)
{
return (!empty($rowData[self::URL_KEY]) || !empty($rowData[self::COL_NAME]))
&& (empty($rowData['visibility'])
|| $rowData['visibility']
!== (string)Visibility::getOptionArray()[Visibility::VISIBILITY_NOT_VISIBLE]);
}

/**
* Parse attributes names and values string to array.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function generateProductUrls($websiteId, $originWebsiteId)
$collection = $this->productFactory->create()
->getCollection()
->addCategoryIds()
->addAttributeToSelect(['name', 'url_path', 'url_key'])
->addAttributeToSelect(['name', 'url_path', 'url_key', 'visibility'])
->addWebsiteFilter($websiteIds);
foreach ($collection as $product) {
/** @var \Magento\Catalog\Model\Product $product */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Magento\UrlRewrite\Model\UrlPersistInterface;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class View
{
/** @var UrlPersistInterface */
Expand Down Expand Up @@ -100,7 +103,7 @@ protected function generateProductUrls($websiteId, $originWebsiteId, $storeId)
$collection = $this->productFactory->create()
->getCollection()
->addCategoryIds()
->addAttributeToSelect(['name', 'url_path', 'url_key'])
->addAttributeToSelect(['name', 'url_path', 'url_key', 'visibility'])
->addWebsiteFilter($websiteIds);
foreach ($collection as $product) {
$product->setStoreId($storeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\CatalogUrlRewrite\Model\Product\CurrentUrlRewritesRegenerator;
use Magento\CatalogUrlRewrite\Service\V1\StoreViewService;
use Magento\Store\Model\Store;
use Magento\Catalog\Model\Product\Visibility;

class ProductUrlRewriteGenerator
{
Expand Down Expand Up @@ -75,6 +76,10 @@ public function __construct(
*/
public function generate(Product $product)
{
if ($product->getVisibility() == Visibility::VISIBILITY_NOT_VISIBLE) {
return [];
}

$this->product = $product;
$storeId = $this->product->getStoreId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Magento\UrlRewrite\Model\OptionProvider;
use Magento\UrlRewrite\Model\UrlFinderInterface;
use Magento\Framework\Event\ObserverInterface;
use Magento\Catalog\Model\Product\Visibility;

/**
* Class AfterImportDataObserver
Expand Down Expand Up @@ -93,6 +94,7 @@ class AfterImportDataObserver implements ObserverInterface
'url_key',
'url_path',
'name',
'visibility',
];

/**
Expand Down Expand Up @@ -221,6 +223,10 @@ protected function setStoreToProduct(\Magento\Catalog\Model\Product $product, ar
*/
protected function addProductToImport($product, $storeId)
{
if ($product->getVisibility() == (string)Visibility::getOptionArray()[Visibility::VISIBILITY_NOT_VISIBLE]) {
return $this;
}

if (!isset($this->products[$product->getId()])) {
$this->products[$product->getId()] = [];
}
Expand Down Expand Up @@ -321,6 +327,9 @@ protected function categoriesUrlRewriteGenerate()
foreach ($productsByStores as $storeId => $product) {
foreach ($this->categoryCache[$productId] as $categoryId) {
$category = $this->import->getCategoryProcessor()->getCategoryById($categoryId);
if ($category->getParentId() == Category::TREE_ROOT_ID) {
continue;
}
$requestPath = $this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId, $category);
$urls[] = $this->urlRewriteFactory->create()
->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ public function execute(\Magento\Framework\Event\Observer $observer)
$product = $observer->getEvent()->getProduct();

$isChangedWebsites = $product->getIsChangedWebsites();
if ($product->dataHasChangedFor('url_key') || $product->getIsChangedCategories() || $isChangedWebsites) {
if ($product->dataHasChangedFor('url_key') || $product->getIsChangedCategories() || $isChangedWebsites
|| $product->dataHasChangedFor('visibility')) {
if ($isChangedWebsites) {
$this->urlPersist->deleteByData([
UrlRewrite::ENTITY_ID => $product->getId(),
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
]);
}
if ($product->getVisibility() != Visibility::VISIBILITY_NOT_VISIBLE) {
if (!in_array($product->getOrigData('visibility'), $product->getVisibleInSiteVisibilities())) {
$this->urlPersist->replace($this->productUrlRewriteGenerator->generate($product));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function generateProductUrlRewrites(Category $category)
$collection = $this->productCollectionFactory->create()
->setStoreId($storeId)
->addIdFilter($category->getAffectedProductIds())
->addAttributeToSelect('visibility')
->addAttributeToSelect('name')
->addAttributeToSelect('url_key')
->addAttributeToSelect('url_path');
Expand Down Expand Up @@ -104,6 +105,7 @@ public function getCategoryProductsUrlRewrites(Category $category, $storeId, $sa
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
$productCollection = $category->getProductCollection()
->addAttributeToSelect('name')
->addAttributeToSelect('visibility')
->addAttributeToSelect('url_key')
->addAttributeToSelect('url_path');
$productUrls = [];
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Checkout/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'one
'items' => nl2br($items),
'total' => $total,
]
)->setScopeId(
$checkout->getStoreId()
)->setFrom(
$this->scopeConfig->getValue(
'checkout/payment_failed/identity',
Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Checkout/Test/Unit/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ public function testSendPaymentFailedEmail()
$this->returnSelf()
);

$this->_transportBuilder->expects(
$this->once()
)->method(
'setScopeId'
)->with(
8
)->will(
$this->returnSelf()
);

$this->_transportBuilder->expects(
$this->once()
)->method(
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Customer/Model/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ protected function sendEmailTemplate($customer, $template, $sender, $templatePar
$transport = $this->transportBuilder->setTemplateIdentifier($templateId)
->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])
->setTemplateVars($templateParams)
->setScopeId($storeId)
->setFrom($this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId))
->addTo($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer))
->getTransport();
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ protected function _sendEmailTemplate($template, $sender, $templateParams = [],
['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId]
)->setTemplateVars(
$templateParams
)->setScopeId(
$storeId
)->setFrom(
$this->_scopeConfig->getValue($sender, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)
)->addTo(
Expand Down
Loading

0 comments on commit 87b7b5f

Please sign in to comment.