Skip to content

Commit

Permalink
Merge pull request #45 from magento-folks/bugs
Browse files Browse the repository at this point in the history
[Folks] Bugfix
  • Loading branch information
Korshenko, Olexii(okorshenko) committed Oct 28, 2015
2 parents be268e8 + 0c3afac commit c42d2cf
Show file tree
Hide file tree
Showing 35 changed files with 351 additions and 112 deletions.
7 changes: 6 additions & 1 deletion app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,12 @@ protected function initializeProductData(array $productData, $createNew)
if ($createNew) {
$product = $this->productFactory->create();
if ($this->storeManager->hasSingleStore()) {
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsite()->getId()]);
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsiteId()]);
} elseif (isset($productData['store_id'])
&& !empty($productData['store_id'])
&& $this->storeManager->getStore($productData['store_id'])
) {
$product->setWebsiteIds([$this->storeManager->getStore($productData['store_id'])->getWebsiteId()]);
}
} else {
unset($this->instances[$productData['sku']]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,38 @@ class Product extends AbstractPlugin
/**
* Reindex on product save
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
* @param \Magento\Catalog\Model\ResourceModel\Product $productResource
* @param \Closure $proceed
* @param \Magento\Framework\Model\AbstractModel $product
* @return \Magento\Catalog\Model\ResourceModel\Product
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterSave(\Magento\Catalog\Model\Product $product)
{
public function aroundSave(
\Magento\Catalog\Model\ResourceModel\Product $productResource,
\Closure $proceed,
\Magento\Framework\Model\AbstractModel $product
) {
$result = $proceed($product);
$this->reindexRow($product->getId());
return $product;
return $result;
}

/**
* Reindex on product delete
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
* @param \Magento\Catalog\Model\ResourceModel\Product $productResource
* @param \Closure $proceed
* @param \Magento\Framework\Model\AbstractModel $product
* @return \Magento\Catalog\Model\ResourceModel\Product
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterDelete(\Magento\Catalog\Model\Product $product)
{
public function aroundDelete(
\Magento\Catalog\Model\ResourceModel\Product $productResource,
\Closure $proceed,
\Magento\Framework\Model\AbstractModel $product
) {
$result = $proceed($product);
$this->reindexRow($product->getId());
return $product;
return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ class ProductTest extends \PHPUnit_Framework_TestCase
protected $indexerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\ResourceModel\Product
*/
protected $subjectMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product
*/
protected $productMock;

/**
* @var \Closure
*/
protected $proceed;

/**
* @var \Magento\Framework\Indexer\IndexerRegistry|\PHPUnit_Framework_MockObject_MockObject
*/
Expand All @@ -32,8 +42,8 @@ class ProductTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->subjectMock = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);

$this->productMock = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
$this->subjectMock = $this->getMock('Magento\Catalog\Model\ResourceModel\Product', [], [], '', false);
$this->indexerMock = $this->getMockForAbstractClass(
'Magento\Framework\Indexer\IndexerInterface',
[],
Expand All @@ -43,7 +53,6 @@ protected function setUp()
true,
['getId', 'getState', '__wakeup']
);

$this->indexerRegistryMock = $this->getMock(
'Magento\Framework\Indexer\IndexerRegistry',
['get'],
Expand All @@ -52,6 +61,10 @@ protected function setUp()
false
);

$this->proceed = function () {
return $this->subjectMock;
};

$this->model = new Product($this->indexerRegistryMock);
}

Expand All @@ -61,9 +74,12 @@ public function testAfterSaveNonScheduled()
$this->indexerMock->expects($this->once())->method('reindexRow')->with(1);
$this->prepareIndexer();

$this->subjectMock->expects($this->once())->method('getId')->will($this->returnValue(1));
$this->productMock->expects($this->once())->method('getId')->will($this->returnValue(1));

$this->assertEquals($this->subjectMock, $this->model->afterSave($this->subjectMock));
$this->assertEquals(
$this->subjectMock,
$this->model->aroundSave($this->subjectMock, $this->proceed, $this->productMock)
);
}

public function testAfterSaveScheduled()
Expand All @@ -72,9 +88,12 @@ public function testAfterSaveScheduled()
$this->indexerMock->expects($this->never())->method('reindexRow');
$this->prepareIndexer();

$this->subjectMock->expects($this->once())->method('getId')->will($this->returnValue(1));
$this->productMock->expects($this->once())->method('getId')->will($this->returnValue(1));

$this->assertEquals($this->subjectMock, $this->model->afterSave($this->subjectMock));
$this->assertEquals(
$this->subjectMock,
$this->model->aroundSave($this->subjectMock, $this->proceed, $this->productMock)
);
}

public function testAfterDeleteNonScheduled()
Expand All @@ -83,9 +102,12 @@ public function testAfterDeleteNonScheduled()
$this->indexerMock->expects($this->once())->method('reindexRow')->with(1);
$this->prepareIndexer();

$this->subjectMock->expects($this->once())->method('getId')->will($this->returnValue(1));
$this->productMock->expects($this->once())->method('getId')->will($this->returnValue(1));

$this->assertEquals($this->subjectMock, $this->model->afterDelete($this->subjectMock));
$this->assertEquals(
$this->subjectMock,
$this->model->aroundDelete($this->subjectMock, $this->proceed, $this->productMock)
);
}

public function testAfterDeleteScheduled()
Expand All @@ -94,9 +116,12 @@ public function testAfterDeleteScheduled()
$this->indexerMock->expects($this->never())->method('reindexRow');
$this->prepareIndexer();

$this->subjectMock->expects($this->once())->method('getId')->will($this->returnValue(1));
$this->productMock->expects($this->once())->method('getId')->will($this->returnValue(1));

$this->assertEquals($this->subjectMock, $this->model->afterDelete($this->subjectMock));
$this->assertEquals(
$this->subjectMock,
$this->model->aroundDelete($this->subjectMock, $this->proceed, $this->productMock)
);
}

protected function prepareIndexer()
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogSearch/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Catalog\Model\Product">
<type name="Magento\Catalog\Model\ResourceModel\Product">
<plugin name="catalogsearchFulltextProduct" type="Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Product"/>
</type>
<type name="Magento\Catalog\Model\Product\Action">
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Checkout/Model/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ protected function _getProductRequest($requestInfo)
if (!$request->hasQty()) {
$request->setQty(1);
}
!$request->hasFormKey() ?: $request->unsFormKey();

return $request;
}
Expand Down
10 changes: 1 addition & 9 deletions app/code/Magento/Checkout/Model/DefaultConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ class DefaultConfigProvider implements ConfigProviderInterface
*/
private $httpContext;

/**
* @var CurrencyManager
*/
private $currencyManager;

/**
* @var QuoteRepository
*/
Expand Down Expand Up @@ -174,7 +169,6 @@ class DefaultConfigProvider implements ConfigProviderInterface
* @param CustomerSession $customerSession
* @param CustomerUrlManager $customerUrlManager
* @param HttpContext $httpContext
* @param CurrencyManager $currencyManager
* @param QuoteRepository $quoteRepository
* @param QuoteItemRepository $quoteItemRepository
* @param ShippingMethodManager $shippingMethodManager
Expand Down Expand Up @@ -205,7 +199,6 @@ public function __construct(
CustomerSession $customerSession,
CustomerUrlManager $customerUrlManager,
HttpContext $httpContext,
CurrencyManager $currencyManager,
QuoteRepository $quoteRepository,
QuoteItemRepository $quoteItemRepository,
ShippingMethodManager $shippingMethodManager,
Expand Down Expand Up @@ -233,7 +226,6 @@ public function __construct(
$this->customerSession = $customerSession;
$this->customerUrlManager = $customerUrlManager;
$this->httpContext = $httpContext;
$this->currencyManager = $currencyManager;
$this->quoteRepository = $quoteRepository;
$this->quoteItemRepository = $quoteItemRepository;
$this->shippingMethodManager = $shippingMethodManager;
Expand Down Expand Up @@ -282,7 +274,7 @@ public function getConfig()
);
$output['basePriceFormat'] = $this->localeFormat->getPriceFormat(
null,
$this->currencyManager->getDefaultCurrency()
$this->checkoutSession->getQuote()->getBaseCurrencyCode()
);
$output['postCodes'] = $this->postCodesConfig->getPostCodes();
$output['imageData'] = $this->imageProvider->getImages($quoteId);
Expand Down
32 changes: 29 additions & 3 deletions app/code/Magento/Checkout/view/frontend/web/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ define([
'Magento_Customer/js/customer-data',
'Magento_Ui/js/modal/alert',
'Magento_Ui/js/modal/confirm',
'Magento_Customer/js/customer-data',
"jquery/ui",
"mage/decorate"
], function($, authenticationPopup, customerData, alert, confirm){
], function($, authenticationPopup, customerData, alert, confirm, customerData){

$.widget('mage.sidebar', {
options: {
Expand All @@ -21,8 +22,19 @@ define([
},
scrollHeight: 0,

_create: function() {
/**
* Create sidebar.
* @private
*/
_create: function () {
var self = this;

this._initContent();
customerData.get('cart').subscribe(function () {
$(self.options.targetElement).trigger('contentUpdated');
self._calcHeight();
self._isOverflowed();
});
},

_initContent: function() {
Expand Down Expand Up @@ -67,6 +79,9 @@ define([
event.stopPropagation();
self._updateItemQty($(event.currentTarget));
};
events['focusout ' + this.options.item.qty] = function(event) {
self._validateQty($(event.currentTarget));
};

this._on(this.element, events);
this._calcHeight();
Expand Down Expand Up @@ -95,7 +110,6 @@ define([
if (this._isValidQty(itemQty, elem.val())) {
$('#update-cart-item-' + itemId).show('fade', 300);
} else if (elem.val() == 0) {
elem.val(itemQty);
this._hideItemButton(elem);
} else {
this._hideItemButton(elem);
Expand All @@ -115,6 +129,18 @@ define([
&& (changed - 0 > 0);
},

/**
* @param {Object} elem
* @private
*/
_validateQty: function(elem) {
var itemQty = elem.data('item-qty');

if (!this._isValidQty(itemQty, elem.val())) {
elem.val(itemQty);
}
},

_hideItemButton: function(elem) {
var itemId = elem.data('cart-item');
$('#update-cart-item-' + itemId).hide('fade', 300);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ define(
} else {
this.source.set('params.invalid', false);
this.source.trigger(this.dataScopePrefix + '.data.validate');
if (this.source.get(this.dataScopePrefix + '.custom_attributes')) {
this.source.trigger(this.dataScopePrefix + '.custom_attributes.data.validate');
};

if (!this.source.get('params.invalid')) {
var addressData = this.source.get(this.dataScopePrefix),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ define([
this.isLoading(addToCartCalls > 0);
sidebarInitialized = false;
initSidebar();

/**TODO: Extra options support. Should be refactored after MAGETWO-43159. */
setInterval(function(){
minicart.trigger('contentUpdated');
}, 500);

}, this);
$('[data-block="minicart"]').on('contentLoading', function(event) {
addToCartCalls++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ define(
}
},

validateShippingInformation: function() {
validateShippingInformation: function () {
var shippingAddress,
addressData,
loginFormSelector = 'form[data-role=email-with-possible-login]',
Expand All @@ -224,6 +224,9 @@ define(
if (this.isFormInline) {
this.source.set('params.invalid', false);
this.source.trigger('shippingAddress.data.validate');
if (this.source.get('shippingAddress.custom_attributes')) {
this.source.trigger('shippingAddress.custom_attributes.data.validate');
};
if (this.source.get('params.invalid')
|| !quote.shippingMethod().method_code
|| !quote.shippingMethod().carrier_code
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Eav/Model/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ protected function _saveAttribute($object, $attribute, $value)
'value' => $this->_prepareValueForSave($value, $attribute),
];

if (!$this->getEntityTable()) {
if (!$this->getEntityTable() || $this->getEntityTable() == \Magento\Eav\Model\Entity::DEFAULT_ENTITY_TABLE) {
$data['entity_type_id'] = $object->getEntityTypeId();
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Eav/Model/Entity/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function beforeSave()
)
) {
throw new LocalizedException(
__('An attribute code must be fewer than %1 characters.', self::ATTRIBUTE_CODE_MAX_LENGTH)
__('An attribute code must not be more than %1 characters.', self::ATTRIBUTE_CODE_MAX_LENGTH)
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Eav/Setup/EavSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ private function _validateAttributeData($data)
)
) {
throw new LocalizedException(
__('An attribute code must be fewer than %1 characters.', $attributeCodeMaxLength)
__('An attribute code must not be more than %1 characters.', $attributeCodeMaxLength)
);
}

Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Payment/view/frontend/web/transparent.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ define([
.off('click')
.on('click', $.proxy(this._placeOrderHandler, this));
}

this.element.validation();
$('[data-container="' + this.options.gateway + '-cc-number"]').on('focusout', function () {
$(this).valid();
});
},

/**
Expand Down
Loading

0 comments on commit c42d2cf

Please sign in to comment.