Skip to content

Commit 00d0fe9

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #34 from magento-south/BUGS
[SOUTH] Bugfixes
2 parents 481bc3b + d74c186 commit 00d0fe9

File tree

23 files changed

+474
-114
lines changed

23 files changed

+474
-114
lines changed

app/code/Magento/Bundle/Model/Product/Price.php

+20-3
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ public function getTotalBundleItemsPrice($product, $qty = null)
118118
{
119119
$price = 0.0;
120120
if ($product->hasCustomOptions()) {
121-
$customOption = $product->getCustomOption('bundle_selection_ids');
122-
if ($customOption) {
123-
$selectionIds = unserialize($customOption->getValue());
121+
$selectionIds = $this->getBundleSelectionIds($product);
122+
if ($selectionIds) {
124123
$selections = $product->getTypeInstance()->getSelectionsByIds($selectionIds, $product);
125124
$selections->addTierPriceData();
126125
$this->_eventManager->dispatch(
@@ -145,6 +144,24 @@ public function getTotalBundleItemsPrice($product, $qty = null)
145144
return $price;
146145
}
147146

147+
/**
148+
* Retrieve array of bundle selection IDs
149+
*
150+
* @param \Magento\Catalog\Model\Product $product
151+
* @return array
152+
*/
153+
protected function getBundleSelectionIds(\Magento\Catalog\Model\Product $product)
154+
{
155+
$customOption = $product->getCustomOption('bundle_selection_ids');
156+
if ($customOption) {
157+
$selectionIds = unserialize($customOption->getValue());
158+
if (!empty($selectionIds) && is_array($selectionIds)) {
159+
return $selectionIds;
160+
}
161+
}
162+
return [];
163+
}
164+
148165
/**
149166
* Get product final price
150167
*

app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php

+117
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,121 @@ public function calculateSpecialPrice()
146146
[10, 100, 1, true, 10],
147147
];
148148
}
149+
150+
public function testGetTotalBundleItemsPriceWithNoCustomOptions()
151+
{
152+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
153+
->disableOriginalConstructor()
154+
->getMock();
155+
156+
$productMock->expects($this->once())
157+
->method('hasCustomOptions')
158+
->willReturn(false);
159+
160+
$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
161+
}
162+
163+
/**
164+
* @param string|null $value
165+
* @dataProvider dataProviderWithEmptyOptions
166+
*/
167+
public function testGetTotalBundleItemsPriceWithEmptyOptions($value)
168+
{
169+
$dataObjectMock = $this->getMockBuilder('Magento\Framework\DataObject')
170+
->setMethods(['getValue'])
171+
->disableOriginalConstructor()
172+
->getMock();
173+
174+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
175+
->disableOriginalConstructor()
176+
->getMock();
177+
178+
$productMock->expects($this->once())
179+
->method('hasCustomOptions')
180+
->willReturn(true);
181+
$productMock->expects($this->once())
182+
->method('getCustomOption')
183+
->with('bundle_selection_ids')
184+
->willReturn($dataObjectMock);
185+
186+
$dataObjectMock->expects($this->once())
187+
->method('getValue')
188+
->willReturn($value);
189+
190+
$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
191+
}
192+
193+
/**
194+
* @return array
195+
*/
196+
public function dataProviderWithEmptyOptions()
197+
{
198+
return [
199+
['a:0:{}'],
200+
[''],
201+
[null],
202+
];
203+
}
204+
205+
public function testGetTotalBundleItemsPriceWithNoItems()
206+
{
207+
$storeId = 1;
208+
209+
$dataObjectMock = $this->getMockBuilder('Magento\Framework\DataObject')
210+
->setMethods(['getValue'])
211+
->disableOriginalConstructor()
212+
->getMock();
213+
214+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
215+
->disableOriginalConstructor()
216+
->getMock();
217+
218+
$productTypeMock = $this->getMockBuilder('Magento\Bundle\Model\Product\Type')
219+
->disableOriginalConstructor()
220+
->getMock();
221+
222+
$selectionsMock = $this->getMockBuilder('Magento\Bundle\Model\ResourceModel\Selection\Collection')
223+
->disableOriginalConstructor()
224+
->getMock();
225+
226+
$productMock->expects($this->once())
227+
->method('hasCustomOptions')
228+
->willReturn(true);
229+
$productMock->expects($this->once())
230+
->method('getCustomOption')
231+
->with('bundle_selection_ids')
232+
->willReturn($dataObjectMock);
233+
$productMock->expects($this->once())
234+
->method('getTypeInstance')
235+
->willReturn($productTypeMock);
236+
$productMock->expects($this->once())
237+
->method('getStoreId')
238+
->willReturn($storeId);
239+
240+
$dataObjectMock->expects($this->once())
241+
->method('getValue')
242+
->willReturn('a:1:{i:0;s:1:"1";}');
243+
244+
$productTypeMock->expects($this->once())
245+
->method('getSelectionsByIds')
246+
->with([1], $productMock)
247+
->willReturn($selectionsMock);
248+
249+
$selectionsMock->expects($this->once())
250+
->method('addTierPriceData')
251+
->willReturnSelf();
252+
$selectionsMock->expects($this->once())
253+
->method('getItems')
254+
->willReturn([]);
255+
256+
$this->eventManagerMock->expects($this->once())
257+
->method('dispatch')
258+
->with(
259+
'prepare_catalog_product_collection_prices',
260+
['collection' => $selectionsMock, 'store_id' => $storeId]
261+
)
262+
->willReturnSelf();
263+
264+
$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
265+
}
149266
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

-16
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,6 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
133133
*/
134134
protected $_priceDataFieldFilters = [];
135135

136-
/**
137-
* Map of price fields
138-
*
139-
* @var array
140-
*/
141-
protected $_map = [
142-
'fields' => [
143-
'price' => 'price_index.price',
144-
'final_price' => 'price_index.final_price',
145-
'min_price' => 'price_index.min_price',
146-
'max_price' => 'price_index.max_price',
147-
'tier_price' => 'price_index.tier_price',
148-
'special_price' => 'price_index.special_price',
149-
],
150-
];
151-
152136
/**
153137
* Price expression sql
154138
*

app/code/Magento/Customer/Model/AccountManagement.php

+7
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,13 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
513513
$customer->setStoreId($storeId);
514514
}
515515

516+
// Update 'created_in' value with actual store name
517+
if ($customer->getId() === null) {
518+
$storeName = $this->storeManager->getStore($customer->getStoreId())
519+
->getName();
520+
$customer->setCreatedIn($storeName);
521+
}
522+
516523
$customerAddresses = $customer->getAddresses() ?: [];
517524
$customer->setAddresses(null);
518525
try {

app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php

+57-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public function testCreateAccountWithPasswordHashWithCustomerWithoutStoreId()
265265
->method('getDefaultStore')
266266
->willReturn($store);
267267
$customer = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')->getMock();
268-
$customer->expects($this->once())
268+
$customer->expects($this->atLeastOnce())
269269
->method('getId')
270270
->willReturn($customerId);
271271
$customer->expects($this->once())
@@ -341,7 +341,7 @@ public function testCreateAccountWithPasswordHashWithLocalizedException()
341341
->method('getDefaultStore')
342342
->willReturn($store);
343343
$customer = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')->getMock();
344-
$customer->expects($this->once())
344+
$customer->expects($this->atLeastOnce())
345345
->method('getId')
346346
->willReturn($customerId);
347347
$customer->expects($this->once())
@@ -478,6 +478,61 @@ public function testCreateAccountWithPasswordHashWithAddressException()
478478
$this->accountManagement->createAccountWithPasswordHash($customer, $hash);
479479
}
480480

481+
/**
482+
* @expectedException \Magento\Framework\Exception\LocalizedException
483+
*/
484+
public function testCreateAccountWithPasswordHashWithNewCustomerAndLocalizedException()
485+
{
486+
$storeId = 1;
487+
$storeName = 'store_name';
488+
$hash = '4nj54lkj5jfi03j49f8bgujfgsd';
489+
490+
$customerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')
491+
->getMockForAbstractClass();
492+
493+
$customerMock->expects($this->atLeastOnce())
494+
->method('getId')
495+
->willReturn(null);
496+
$customerMock->expects($this->atLeastOnce())
497+
->method('getStoreId')
498+
->willReturn($storeId);
499+
$customerMock->expects($this->once())
500+
->method('setCreatedIn')
501+
->with($storeName)
502+
->willReturnSelf();
503+
$customerMock->expects($this->once())
504+
->method('getAddresses')
505+
->willReturn([]);
506+
$customerMock->expects($this->once())
507+
->method('setAddresses')
508+
->with(null)
509+
->willReturnSelf();
510+
511+
$storeMock = $this->getMockBuilder('Magento\Store\Model\Store')
512+
->disableOriginalConstructor()
513+
->getMock();
514+
515+
$storeMock->expects($this->once())
516+
->method('getName')
517+
->willReturn($storeName);
518+
519+
$this->storeManager->expects($this->once())
520+
->method('getStore')
521+
->with($storeId)
522+
->willReturn($storeMock);
523+
524+
$exception = new \Magento\Framework\Exception\LocalizedException(
525+
new \Magento\Framework\Phrase('Exception message')
526+
);
527+
$this->customerRepository
528+
->expects($this->once())
529+
->method('save')
530+
->with($customerMock, $hash)
531+
->willThrowException($exception);
532+
533+
$this->accountManagement->createAccountWithPasswordHash($customerMock, $hash);
534+
}
535+
481536
/**
482537
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
483538
*/

app/code/Magento/CustomerImportExport/Model/Import/Customer.php

+30-21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CustomerImportExport\Model\Import;
77

8+
use Magento\Customer\Api\Data\CustomerInterface;
89
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
910

1011
/**
@@ -135,25 +136,25 @@ class Customer extends AbstractCustomer
135136
/**
136137
* Customer fields in file
137138
*/
138-
public $customerFields = [
139-
'group_id',
140-
'store_id',
141-
'updated_at',
142-
'created_at',
143-
'created_in',
144-
'prefix',
145-
'firstname',
146-
'middlename',
147-
'lastname',
148-
'suffix',
149-
'dob',
139+
protected $customerFields = [
140+
CustomerInterface::GROUP_ID,
141+
CustomerInterface::STORE_ID,
142+
CustomerInterface::UPDATED_AT,
143+
CustomerInterface::CREATED_AT,
144+
CustomerInterface::CREATED_IN,
145+
CustomerInterface::PREFIX,
146+
CustomerInterface::FIRSTNAME,
147+
CustomerInterface::MIDDLENAME,
148+
CustomerInterface::LASTNAME,
149+
CustomerInterface::SUFFIX,
150+
CustomerInterface::DOB,
150151
'password_hash',
151-
'taxvat',
152-
'confirmation',
153-
'gender',
152+
CustomerInterface::TAXVAT,
153+
CustomerInterface::CONFIRMATION,
154+
CustomerInterface::GENDER,
154155
'rp_token',
155156
'rp_token_created_at',
156-
];
157+
];
157158

158159
/**
159160
* @param \Magento\Framework\Stdlib\StringUtils $string
@@ -237,11 +238,6 @@ public function __construct(
237238

238239
$this->_initStores(true)->_initAttributes();
239240

240-
$this->validColumnNames = array_merge(
241-
$this->validColumnNames,
242-
$this->customerFields
243-
);
244-
245241
$this->_customerModel = $customerFactory->create();
246242
/** @var $customerResource \Magento\Customer\Model\ResourceModel\Customer */
247243
$customerResource = $this->_customerModel->getResource();
@@ -562,4 +558,17 @@ public function getEntityTable()
562558
{
563559
return $this->_entityTable;
564560
}
561+
562+
/**
563+
* @inheritDoc
564+
*/
565+
public function getValidColumnNames()
566+
{
567+
$this->validColumnNames = array_merge(
568+
$this->validColumnNames,
569+
$this->customerFields
570+
);
571+
572+
return $this->validColumnNames;
573+
}
565574
}

app/code/Magento/CustomerImportExport/Model/Import/CustomerComposite.php

+15-7
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,6 @@ public function __construct(
224224
}
225225
$this->_initAddressAttributes();
226226

227-
$this->validColumnNames = array_merge(
228-
$this->validColumnNames,
229-
$this->_customerAttributes,
230-
$this->_addressAttributes,
231-
$this->_customerEntity->customerFields
232-
);
233-
234227
// next customer id
235228
if (isset($data['next_customer_id'])) {
236229
$this->_nextCustomerId = $data['next_customer_id'];
@@ -489,4 +482,19 @@ protected function _prepareRowForDb(array $rowData)
489482

490483
return parent::_prepareRowForDb($rowData);
491484
}
485+
486+
/**
487+
* @inheritDoc
488+
*/
489+
public function getValidColumnNames()
490+
{
491+
$this->validColumnNames = array_merge(
492+
$this->validColumnNames,
493+
$this->_customerAttributes,
494+
$this->_addressAttributes,
495+
$this->_customerEntity->getValidColumnNames()
496+
);
497+
498+
return $this->validColumnNames;
499+
}
492500
}

0 commit comments

Comments
 (0)