Skip to content

Commit

Permalink
Merge pull request #34 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[SOUTH] Bugfixes
  • Loading branch information
Korshenko, Olexii(okorshenko) committed Oct 23, 2015
2 parents 481bc3b + d74c186 commit 00d0fe9
Show file tree
Hide file tree
Showing 23 changed files with 474 additions and 114 deletions.
23 changes: 20 additions & 3 deletions app/code/Magento/Bundle/Model/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ public function getTotalBundleItemsPrice($product, $qty = null)
{
$price = 0.0;
if ($product->hasCustomOptions()) {
$customOption = $product->getCustomOption('bundle_selection_ids');
if ($customOption) {
$selectionIds = unserialize($customOption->getValue());
$selectionIds = $this->getBundleSelectionIds($product);
if ($selectionIds) {
$selections = $product->getTypeInstance()->getSelectionsByIds($selectionIds, $product);
$selections->addTierPriceData();
$this->_eventManager->dispatch(
Expand All @@ -145,6 +144,24 @@ public function getTotalBundleItemsPrice($product, $qty = null)
return $price;
}

/**
* Retrieve array of bundle selection IDs
*
* @param \Magento\Catalog\Model\Product $product
* @return array
*/
protected function getBundleSelectionIds(\Magento\Catalog\Model\Product $product)
{
$customOption = $product->getCustomOption('bundle_selection_ids');
if ($customOption) {
$selectionIds = unserialize($customOption->getValue());
if (!empty($selectionIds) && is_array($selectionIds)) {
return $selectionIds;
}
}
return [];
}

/**
* Get product final price
*
Expand Down
117 changes: 117 additions & 0 deletions app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,121 @@ public function calculateSpecialPrice()
[10, 100, 1, true, 10],
];
}

public function testGetTotalBundleItemsPriceWithNoCustomOptions()
{
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
->disableOriginalConstructor()
->getMock();

$productMock->expects($this->once())
->method('hasCustomOptions')
->willReturn(false);

$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
}

/**
* @param string|null $value
* @dataProvider dataProviderWithEmptyOptions
*/
public function testGetTotalBundleItemsPriceWithEmptyOptions($value)
{
$dataObjectMock = $this->getMockBuilder('Magento\Framework\DataObject')
->setMethods(['getValue'])
->disableOriginalConstructor()
->getMock();

$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
->disableOriginalConstructor()
->getMock();

$productMock->expects($this->once())
->method('hasCustomOptions')
->willReturn(true);
$productMock->expects($this->once())
->method('getCustomOption')
->with('bundle_selection_ids')
->willReturn($dataObjectMock);

$dataObjectMock->expects($this->once())
->method('getValue')
->willReturn($value);

$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
}

/**
* @return array
*/
public function dataProviderWithEmptyOptions()
{
return [
['a:0:{}'],
[''],
[null],
];
}

public function testGetTotalBundleItemsPriceWithNoItems()
{
$storeId = 1;

$dataObjectMock = $this->getMockBuilder('Magento\Framework\DataObject')
->setMethods(['getValue'])
->disableOriginalConstructor()
->getMock();

$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
->disableOriginalConstructor()
->getMock();

$productTypeMock = $this->getMockBuilder('Magento\Bundle\Model\Product\Type')
->disableOriginalConstructor()
->getMock();

$selectionsMock = $this->getMockBuilder('Magento\Bundle\Model\ResourceModel\Selection\Collection')
->disableOriginalConstructor()
->getMock();

$productMock->expects($this->once())
->method('hasCustomOptions')
->willReturn(true);
$productMock->expects($this->once())
->method('getCustomOption')
->with('bundle_selection_ids')
->willReturn($dataObjectMock);
$productMock->expects($this->once())
->method('getTypeInstance')
->willReturn($productTypeMock);
$productMock->expects($this->once())
->method('getStoreId')
->willReturn($storeId);

$dataObjectMock->expects($this->once())
->method('getValue')
->willReturn('a:1:{i:0;s:1:"1";}');

$productTypeMock->expects($this->once())
->method('getSelectionsByIds')
->with([1], $productMock)
->willReturn($selectionsMock);

$selectionsMock->expects($this->once())
->method('addTierPriceData')
->willReturnSelf();
$selectionsMock->expects($this->once())
->method('getItems')
->willReturn([]);

$this->eventManagerMock->expects($this->once())
->method('dispatch')
->with(
'prepare_catalog_product_collection_prices',
['collection' => $selectionsMock, 'store_id' => $storeId]
)
->willReturnSelf();

$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,6 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
*/
protected $_priceDataFieldFilters = [];

/**
* Map of price fields
*
* @var array
*/
protected $_map = [
'fields' => [
'price' => 'price_index.price',
'final_price' => 'price_index.final_price',
'min_price' => 'price_index.min_price',
'max_price' => 'price_index.max_price',
'tier_price' => 'price_index.tier_price',
'special_price' => 'price_index.special_price',
],
];

/**
* Price expression sql
*
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/Customer/Model/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,13 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
$customer->setStoreId($storeId);
}

// Update 'created_in' value with actual store name
if ($customer->getId() === null) {
$storeName = $this->storeManager->getStore($customer->getStoreId())
->getName();
$customer->setCreatedIn($storeName);
}

$customerAddresses = $customer->getAddresses() ?: [];
$customer->setAddresses(null);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function testCreateAccountWithPasswordHashWithCustomerWithoutStoreId()
->method('getDefaultStore')
->willReturn($store);
$customer = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')->getMock();
$customer->expects($this->once())
$customer->expects($this->atLeastOnce())
->method('getId')
->willReturn($customerId);
$customer->expects($this->once())
Expand Down Expand Up @@ -341,7 +341,7 @@ public function testCreateAccountWithPasswordHashWithLocalizedException()
->method('getDefaultStore')
->willReturn($store);
$customer = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')->getMock();
$customer->expects($this->once())
$customer->expects($this->atLeastOnce())
->method('getId')
->willReturn($customerId);
$customer->expects($this->once())
Expand Down Expand Up @@ -478,6 +478,61 @@ public function testCreateAccountWithPasswordHashWithAddressException()
$this->accountManagement->createAccountWithPasswordHash($customer, $hash);
}

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
*/
public function testCreateAccountWithPasswordHashWithNewCustomerAndLocalizedException()
{
$storeId = 1;
$storeName = 'store_name';
$hash = '4nj54lkj5jfi03j49f8bgujfgsd';

$customerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')
->getMockForAbstractClass();

$customerMock->expects($this->atLeastOnce())
->method('getId')
->willReturn(null);
$customerMock->expects($this->atLeastOnce())
->method('getStoreId')
->willReturn($storeId);
$customerMock->expects($this->once())
->method('setCreatedIn')
->with($storeName)
->willReturnSelf();
$customerMock->expects($this->once())
->method('getAddresses')
->willReturn([]);
$customerMock->expects($this->once())
->method('setAddresses')
->with(null)
->willReturnSelf();

$storeMock = $this->getMockBuilder('Magento\Store\Model\Store')
->disableOriginalConstructor()
->getMock();

$storeMock->expects($this->once())
->method('getName')
->willReturn($storeName);

$this->storeManager->expects($this->once())
->method('getStore')
->with($storeId)
->willReturn($storeMock);

$exception = new \Magento\Framework\Exception\LocalizedException(
new \Magento\Framework\Phrase('Exception message')
);
$this->customerRepository
->expects($this->once())
->method('save')
->with($customerMock, $hash)
->willThrowException($exception);

$this->accountManagement->createAccountWithPasswordHash($customerMock, $hash);
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
Expand Down
51 changes: 30 additions & 21 deletions app/code/Magento/CustomerImportExport/Model/Import/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\CustomerImportExport\Model\Import;

use Magento\Customer\Api\Data\CustomerInterface;
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;

/**
Expand Down Expand Up @@ -135,25 +136,25 @@ class Customer extends AbstractCustomer
/**
* Customer fields in file
*/
public $customerFields = [
'group_id',
'store_id',
'updated_at',
'created_at',
'created_in',
'prefix',
'firstname',
'middlename',
'lastname',
'suffix',
'dob',
protected $customerFields = [
CustomerInterface::GROUP_ID,
CustomerInterface::STORE_ID,
CustomerInterface::UPDATED_AT,
CustomerInterface::CREATED_AT,
CustomerInterface::CREATED_IN,
CustomerInterface::PREFIX,
CustomerInterface::FIRSTNAME,
CustomerInterface::MIDDLENAME,
CustomerInterface::LASTNAME,
CustomerInterface::SUFFIX,
CustomerInterface::DOB,
'password_hash',
'taxvat',
'confirmation',
'gender',
CustomerInterface::TAXVAT,
CustomerInterface::CONFIRMATION,
CustomerInterface::GENDER,
'rp_token',
'rp_token_created_at',
];
];

/**
* @param \Magento\Framework\Stdlib\StringUtils $string
Expand Down Expand Up @@ -237,11 +238,6 @@ public function __construct(

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

$this->validColumnNames = array_merge(
$this->validColumnNames,
$this->customerFields
);

$this->_customerModel = $customerFactory->create();
/** @var $customerResource \Magento\Customer\Model\ResourceModel\Customer */
$customerResource = $this->_customerModel->getResource();
Expand Down Expand Up @@ -562,4 +558,17 @@ public function getEntityTable()
{
return $this->_entityTable;
}

/**
* @inheritDoc
*/
public function getValidColumnNames()
{
$this->validColumnNames = array_merge(
$this->validColumnNames,
$this->customerFields
);

return $this->validColumnNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,6 @@ public function __construct(
}
$this->_initAddressAttributes();

$this->validColumnNames = array_merge(
$this->validColumnNames,
$this->_customerAttributes,
$this->_addressAttributes,
$this->_customerEntity->customerFields
);

// next customer id
if (isset($data['next_customer_id'])) {
$this->_nextCustomerId = $data['next_customer_id'];
Expand Down Expand Up @@ -489,4 +482,19 @@ protected function _prepareRowForDb(array $rowData)

return parent::_prepareRowForDb($rowData);
}

/**
* @inheritDoc
*/
public function getValidColumnNames()
{
$this->validColumnNames = array_merge(
$this->validColumnNames,
$this->_customerAttributes,
$this->_addressAttributes,
$this->_customerEntity->getValidColumnNames()
);

return $this->validColumnNames;
}
}
Loading

0 comments on commit 00d0fe9

Please sign in to comment.