Skip to content

Commit

Permalink
Merge pull request #53 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[SOUTH] Bugfixes
  • Loading branch information
slavvka committed Oct 29, 2015
2 parents dc3aee6 + 4f0cfcd commit e3593ae
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 15 deletions.
5 changes: 3 additions & 2 deletions app/code/Magento/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -1086,9 +1086,10 @@ public function reindex()
$flatIndexer->reindexRow($this->getId());
}
}
$affectedProductIds = $this->getAffectedProductIds();
$productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID);
if (!$productIndexer->isScheduled() && !empty($affectedProductIds)) {
if (!$productIndexer->isScheduled()
&& (!empty($this->getAffectedProductIds()) || $this->dataHasChangedFor('is_anchor'))
) {
$productIndexer->reindexList($this->getPathIds());
}
}
Expand Down
40 changes: 30 additions & 10 deletions app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,21 +380,37 @@ public function testReindexFlatEnabled($flatScheduled, $productScheduled, $expec
public function reindexFlatDisabledTestDataProvider()
{
return [
'set 1' => [false, 1],
'set 2' => [true, 0],
[false, null, null, null, 0],
[true, null, null, null, 0],
[false, [], null, null, 0],
[false, ["1", "2"], null, null, 1],
[false, null, 1, null, 1],
[false, ["1", "2"], 0, 1, 1],
[false, null, 1, 1, 0],
];
}

/**
* @param $productScheduled
* @param $expectedProductReindexCall
* @param bool $productScheduled
* @param array $affectedIds
* @param int|string $isAnchorOrig
* @param int|string $isAnchor
* @param int $expectedProductReindexCall
*
* @dataProvider reindexFlatDisabledTestDataProvider
*/
public function testReindexFlatDisabled($productScheduled, $expectedProductReindexCall)
{
$affectedProductIds = ["1", "2"];
$this->category->setAffectedProductIds($affectedProductIds);
public function testReindexFlatDisabled(
$productScheduled,
$affectedIds,
$isAnchorOrig,
$isAnchor,
$expectedProductReindexCall
) {
$this->category->setAffectedProductIds($affectedIds);
$this->category->setData('is_anchor', $isAnchor);
$this->category->setOrigData('is_anchor', $isAnchorOrig);
$this->category->setAffectedProductIds($affectedIds);

$pathIds = ['path/1/2', 'path/2/3'];
$this->category->setData('path_ids', $pathIds);
$this->category->setId('123');
Expand All @@ -403,8 +419,12 @@ public function testReindexFlatDisabled($productScheduled, $expectedProductReind
->method('isFlatEnabled')
->will($this->returnValue(false));

$this->productIndexer->expects($this->exactly(1))->method('isScheduled')->will($this->returnValue($productScheduled));
$this->productIndexer->expects($this->exactly($expectedProductReindexCall))->method('reindexList')->with($pathIds);
$this->productIndexer->expects($this->exactly(1))
->method('isScheduled')
->willReturn($productScheduled);
$this->productIndexer->expects($this->exactly($expectedProductReindexCall))
->method('reindexList')
->with($pathIds);

$this->indexerRegistry->expects($this->at(0))
->method('get')
Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/Checkout/view/frontend/web/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ define([
customer = customerData.get('customer');

if (!customer().firstname && !cart().isGuestCheckoutAllowed) {
authenticationPopup.showModal();
if (this.options.url.isRedirectRequired) {
location.href = this.options.url.loginUrl;
} else {
authenticationPopup.showModal();
}

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ define([
"url": {
"checkout": window.checkout.checkoutUrl,
"update": window.checkout.updateItemQtyUrl,
"remove": window.checkout.removeItemUrl
"remove": window.checkout.removeItemUrl,
"loginUrl": window.checkout.customerLoginUrl,
"isRedirectRequired": window.checkout.isRedirectRequired
},
"button": {
"checkout": "#top-cart-btn-checkout",
Expand Down
37 changes: 37 additions & 0 deletions app/code/Magento/Customer/Model/Cart/ConfigPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model\Cart;

use Magento\Customer\Model\Checkout\ConfigProvider;

class ConfigPlugin
{
/**
* @var ConfigProvider
*/
protected $configProvider;

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

/**
* @param \Magento\Checkout\Block\Cart\Sidebar $subject
* @param array $result
* @return array
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetConfig(\Magento\Checkout\Block\Cart\Sidebar $subject, array $result)
{
return array_merge_recursive($result, $this->configProvider->getConfig());
}
}
73 changes: 73 additions & 0 deletions app/code/Magento/Customer/Model/Checkout/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model\Checkout;

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Customer\Model\Url;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;

class ConfigProvider implements ConfigProviderInterface
{
/**
* @var StoreManagerInterface
*/
protected $storeManager;

/**
* @var UrlInterface
*/
protected $urlBuilder;

/**
* @param UrlInterface $urlBuilder
* @param StoreManagerInterface $storeManager
*/
public function __construct(
UrlInterface $urlBuilder,
StoreManagerInterface $storeManager
) {
$this->urlBuilder = $urlBuilder;
$this->storeManager = $storeManager;
}

/**
* {@inheritdoc}
*/
public function getConfig()
{
return [
'customerLoginUrl' => $this->getLoginUrl(),
'isRedirectRequired' => $this->isRedirectRequired(),
];
}

/**
* Returns URL to login controller action
*
* @return string
*/
protected function getLoginUrl()
{
return $this->urlBuilder->getUrl(Url::ROUTE_ACCOUNT_LOGIN);
}

/**
* Whether redirect to login page is required
*
* @return bool
*/
protected function isRedirectRequired()
{
$baseUrl = $this->storeManager->getStore()->getBaseUrl();

if (strpos($this->getLoginUrl(), $baseUrl) !== false) {
return false;
}

return true;
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Customer/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@
<type name="Magento\Customer\Controller\AccountInterface">
<plugin name="customer_account" type="Magento\Customer\Controller\Plugin\Account" />
</type>
<type name="Magento\Checkout\Block\Cart\Sidebar">
<plugin name="customer_cart" type="\Magento\Customer\Model\Cart\ConfigPlugin" />
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ define([
$('[data-action="add-to-wishlist"]').each(function(index, element) {
var params = $(element).data('post');
if (!params)
params = {};
params = {'data': {}};

if (!$.isEmptyObject(dataToAdd)) {
self._removeExcessiveData(params, dataToAdd);
Expand Down

0 comments on commit e3593ae

Please sign in to comment.