Skip to content

Commit

Permalink
Merge pull request #88 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[South] Bug fixes
  • Loading branch information
Kolesov, Ievgen(ikolesov) committed Nov 1, 2015
2 parents e8ff866 + 8098789 commit 8e3ca1f
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/code/Magento/CustomerImportExport/etc/import.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
<entity name="customer_composite" label="Customers and Addresses (single file)" model="Magento\CustomerImportExport\Model\Import\CustomerComposite" behaviorModel="Magento\ImportExport\Model\Source\Import\Behavior\Basic" />
<entity name="customer" label="Customers Main File" model="Magento\CustomerImportExport\Model\Import\Customer" behaviorModel="Magento\ImportExport\Model\Source\Import\Behavior\Custom" />
<entity name="customer_address" label="Customer Addresses" model="Magento\CustomerImportExport\Model\Import\Address" behaviorModel="Magento\ImportExport\Model\Source\Import\Behavior\Custom" />
<relatedIndexer entity="customer" name="customer_grid" />
<relatedIndexer entity="customer_address" name="customer_grid" />
<relatedIndexer entity="customer_composite" name="customer_grid" />
</config>
2 changes: 2 additions & 0 deletions app/code/Magento/ImportExport/Files/Sample/customer.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
email,_website,_store,confirmation,created_at,created_in,disable_auto_group_change,dob,firstname,gender,group_id,lastname,middlename,password_hash,prefix,reward_update_notification,reward_warning_notification,rp_token,rp_token_created_at,store_id,suffix,taxvat,updated_at,website_id,password
[email protected],base,default,,"2015-10-30 12:49:47","Default Store View",0,,Jon,,1,Doe,,d708be3fe0fe0120840e8b13c8faae97424252c6374227ff59c05814f1aecd79:mgLqkqgTwLPLlCljzvF8hp67fNOOvOZb:1,,,,07e71459c137f4da15292134ff459cba,"2015-10-30 12:49:48",1,,,"2015-10-30 12:49:48",1,
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_website,_email,_entity_id,city,company,country_id,fax,firstname,lastname,middlename,postcode,prefix,region,region_id,street,suffix,telephone,vat_id,vat_is_valid,vat_request_date,vat_request_id,vat_request_success,_address_default_billing_,_address_default_shipping_
base,[email protected],1,"New York",,US,,Jon,Doe,,10044,,"New York",43,"Main Street 1",,123456789,,,,,,1,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_email,_website,_finance_website,store_credit,reward_points
[email protected],base,base,10.0000,100
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Reader extends \Magento\Framework\Config\Reader\Filesystem
protected $_idAttributes = [
'/config/entity' => 'name',
'/config/entityType' => ['entity', 'name'],
'/config/relatedIndexers' => ['entity', 'name'],
'/config/relatedIndexer' => ['entity', 'name'],
];

/**
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Quote/Model/Quote/Address/Total/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ public function collect(
$total->setBaseTotalAmount($this->getCode(), $rate->getPrice());
$shippingDescription = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();
$address->setShippingDescription(trim($shippingDescription, ' -'));
$total->setShippingAmount($rate->getPrice());
$total->setShippingDescription($address->getShippingDescription());
break;
}
}
Expand All @@ -184,6 +186,7 @@ public function collect(
* @param \Magento\Quote\Model\Quote $quote
* @param \Magento\Quote\Model\Quote\Address\Total $total
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
{
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Quote/Model/Quote/TotalsCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public function collect(\Magento\Quote\Model\Quote $quote)
foreach ($quote->getAllAddresses() as $address) {
$addressTotal = $this->collectAddressTotals($quote, $address);

$total->setShippingAmount($addressTotal->getShippingAmount());
$total->setBaseShippingAmount($addressTotal->getBaseShippingAmount());
$total->setShippingDescription($addressTotal->getShippingDescription());

$total->setSubtotal((float)$total->getSubtotal() + $addressTotal->getSubtotal());
$total->setBaseSubtotal((float)$total->getBaseSubtotal() + $addressTotal->getBaseSubtotal());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,124 @@ class ShippingTest extends \PHPUnit_Framework_TestCase
*/
protected $shippingModel;

/** @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject */
protected $quote;

/** @var \Magento\Quote\Model\Quote\Address\Total|\PHPUnit_Framework_MockObject_MockObject */
protected $total;

/** @var \Magento\Quote\Api\Data\ShippingAssignmentInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $shippingAssignment;

/** @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject */
protected $address;

/** @var \Magento\Quote\Api\Data\ShippingInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $shipping;

/** @var \Magento\Quote\Model\Quote\Address\FreeShippingInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $freeShipping;

/** @var \Magento\Quote\Api\Data\CartItemInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $cartItem;

/** @var \Magento\Quote\Model\Quote\Address\Rate|\PHPUnit_Framework_MockObject_MockObject */
protected $rate;

/** @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject */
protected $store;

/** @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $priceCurrency;

protected function setUp()
{
$this->freeShipping = $this->getMockForAbstractClass(
'Magento\Quote\Model\Quote\Address\FreeShippingInterface',
[],
'',
false
);
$this->priceCurrency = $this->getMockForAbstractClass(
'Magento\Framework\Pricing\PriceCurrencyInterface',
[],
'',
false
);
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->shippingModel = $objectManager->getObject('Magento\Quote\Model\Quote\Address\Total\Shipping');
$this->shippingModel = $objectManager->getObject(
'Magento\Quote\Model\Quote\Address\Total\Shipping',
[
'freeShipping' => $this->freeShipping,
'priceCurrency' => $this->priceCurrency,
]
);

$this->quote = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false);
$this->total = $this->getMock(
'Magento\Quote\Model\Quote\Address\Total',
[
'setShippingAmount',
'setBaseTotalAmount',
'setTotalAmount',
'setShippingDescription',
],
[],
'',
false
);
$this->shippingAssignment = $this->getMockForAbstractClass(
'Magento\Quote\Api\Data\ShippingAssignmentInterface',
[],
'',
false
);
$this->address = $this->getMock(
'Magento\Quote\Model\Quote\Address',
[
'setWeight',
'setFreeMethodWeight',
'getWeight',
'getFreeMethodWeight',
'setFreeShipping',
'setItemQty',
'collectShippingRates',
'getAllShippingRates',
'setShippingDescription',
'getShippingDescription',
'getFreeShipping',
],
[],
'',
false
);
$this->shipping = $this->getMockForAbstractClass('Magento\Quote\Api\Data\ShippingInterface', [], '', false);
$this->cartItem = $this->getMockForAbstractClass(
'Magento\Quote\Api\Data\CartItemInterface',
[],
'',
false,
false,
true,
[
'getFreeShipping',
'getProduct',
'getParentItem',
'getHasChildren',
'isVirtual',
'getWeight',
'getQty',
'setRowWeight',
]
);
$this->rate = $this->getMock(
'Magento\Quote\Model\Quote\Address\Rate',
['getPrice', 'getCode', 'getCarrierTitle', 'getMethodTitle'],
[],
'',
false
);
$this->store = $this->getMock('Magento\Store\Model\Store', [], [], '', false);
}

public function testFetch()
Expand All @@ -41,4 +155,100 @@ public function testFetch()
$totalMock->expects($this->once())->method('getShippingDescription')->willReturn($shippingDescription);
$this->assertEquals($expectedResult, $this->shippingModel->fetch($quoteMock, $totalMock));
}

public function testCollect()
{
$this->shippingAssignment->expects($this->exactly(3))
->method('getShipping')
->willReturn($this->shipping);
$this->shipping->expects($this->exactly(2))
->method('getAddress')
->willReturn($this->address);
$this->shipping->expects($this->once())
->method('getMethod')
->willReturn('flatrate');
$this->shippingAssignment->expects($this->atLeastOnce())
->method('getItems')
->willReturn([$this->cartItem]);
$this->freeShipping->expects($this->once())
->method('isFreeShipping')
->with($this->quote, [$this->cartItem])
->willReturn(true);
$this->address->expects($this->once())
->method('setFreeShipping')
->with(true);
$this->total->expects($this->atLeastOnce())
->method('setTotalAmount');
$this->total->expects($this->atLeastOnce())
->method('setBaseTotalAmount');
$this->cartItem->expects($this->atLeastOnce())
->method('getProduct')
->willReturnSelf();
$this->cartItem->expects($this->atLeastOnce())
->method('isVirtual')
->willReturn(false);
$this->cartItem->expects($this->once())
->method('getParentItem')
->willReturn(false);
$this->cartItem->expects($this->once())
->method('getHasChildren')
->willReturn(false);
$this->cartItem->expects($this->once())
->method('getWeight')
->willReturn(2);
$this->cartItem->expects($this->atLeastOnce())
->method('getQty')
->willReturn(2);
$this->address->expects($this->once())
->method('getFreeShipping')
->willReturn(true);
$this->cartItem->expects($this->once())
->method('setRowWeight')
->with(0);
$this->address->expects($this->once())
->method('setItemQty')
->with(2);
$this->address->expects($this->atLeastOnce())
->method('setWeight');
$this->address->expects($this->atLeastOnce())
->method('setFreeMethodWeight');
$this->address->expects($this->once())
->method('collectShippingRates');
$this->address->expects($this->once())
->method('getAllShippingRates')
->willReturn([$this->rate]);
$this->rate->expects($this->once())
->method('getCode')
->willReturn('flatrate');
$this->quote->expects($this->once())
->method('getStore')
->willReturn($this->store);
$this->rate->expects($this->atLeastOnce())
->method('getPrice')
->willReturn(5);
$this->priceCurrency->expects($this->once())
->method('convert')
->with(5, $this->store)
->willReturn(5);
$this->total->expects($this->once())
->method('setShippingAmount')
->with(5);
$this->rate->expects($this->once())
->method('getCarrierTitle')
->willReturn('Carrier title');
$this->rate->expects($this->once())
->method('getMethodTitle')
->willReturn('Method title');
$this->address->expects($this->once())
->method('setShippingDescription')
->with('Carrier title - Method title');
$this->address->expects($this->once())
->method('getShippingDescription')
->willReturn('Carrier title - Method title');
$this->total->expects($this->once())
->method('setShippingDescription')
->with('Carrier title - Method title');

$this->shippingModel->collect($this->quote, $this->shippingAssignment, $this->total);
}
}

0 comments on commit 8e3ca1f

Please sign in to comment.