Skip to content

Commit 6aa90d0

Browse files
author
Tang, Yu(ytang1)
committed
Merge pull request #635 from magento-fearless-kiwis/develop
[FearlessKiwis] Sprint 55: Bug fixes
2 parents 6bb4e4c + e945297 commit 6aa90d0

File tree

18 files changed

+364
-85
lines changed

18 files changed

+364
-85
lines changed

app/code/Magento/Tax/Pricing/Render/Adjustment.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class Adjustment extends AbstractAdjustment
2323

2424
/**
2525
* @param Template\Context $context
26-
* @param \Magento\Tax\Helper\Data $helper
2726
* @param PriceCurrencyInterface $priceCurrency
27+
* @param \Magento\Tax\Helper\Data $helper
2828
* @param array $data
2929
*/
3030
public function __construct(
@@ -69,7 +69,6 @@ protected function apply()
6969
*/
7070
public function getAdjustmentCode()
7171
{
72-
//@TODO We can build two model using DI, not code. What about passing it in constructor?
7372
return \Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE;
7473
}
7574

@@ -86,14 +85,14 @@ public function displayBothPrices()
8685
/**
8786
* Obtain display amount excluding tax
8887
*
88+
* @param array $exclude
8989
* @param bool $includeContainer
9090
* @return string
9191
*/
92-
public function getDisplayAmountExclTax($includeContainer = false)
92+
public function getDisplayAmountExclTax($exclude = null, $includeContainer = false)
9393
{
94-
// todo use 'excludeWith' method instead hard-coded list here
9594
return $this->formatCurrency(
96-
$this->getRawAmount(['tax', 'weee']),
95+
$this->getRawAmount($exclude),
9796
$includeContainer
9897
);
9998
}
@@ -104,11 +103,26 @@ public function getDisplayAmountExclTax($includeContainer = false)
104103
* @param array $exclude
105104
* @return float
106105
*/
107-
public function getRawAmount($exclude = ['tax', 'weee'])
106+
public function getRawAmount($exclude = null)
108107
{
108+
//If exclude is not supplied, use the default
109+
if ($exclude === null) {
110+
$exclude = $this->getDefaultExclusions();
111+
}
112+
109113
return $this->amountRender->getAmount()->getValue($exclude);
110114
}
111115

116+
/**
117+
* Returns the list of default exclusions
118+
*
119+
* @return array
120+
*/
121+
public function getDefaultExclusions()
122+
{
123+
return [$this->getAdjustmentCode()];
124+
}
125+
112126
/**
113127
* Obtain display amount
114128
*

app/code/Magento/Tax/Setup/InstallData.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ public function __construct(TaxSetupFactory $taxSetupFactory)
3838
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
3939
{
4040
/** @var TaxSetup $taxSetup */
41-
$taxSetup = $this->taxSetupFactory->create(['setup' => $setup]);
41+
$taxSetup = $this->taxSetupFactory->create(['resourceName' => 'tax_setup', 'setup' => $setup]);
4242

4343
/**
4444
* Add tax_class_id attribute to the 'eav_attribute' table
4545
*/
46-
$catalogInstaller = $taxSetup->getCatalogSetup(['resourceName' => 'catalog_setup', 'setup' => $setup]);
47-
$catalogInstaller->addAttribute(
46+
$taxSetup->addAttribute(
4847
\Magento\Catalog\Model\Product::ENTITY,
4948
'tax_class_id',
5049
[
@@ -66,7 +65,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
6665
'filterable' => false,
6766
'comparable' => false,
6867
'visible_on_front' => false,
69-
'visible_in_advanced_search' => true,
68+
'visible_in_advanced_search' => false,
7069
'used_in_product_listing' => true,
7170
'unique' => false,
7271
'apply_to' => implode(',', $taxSetup->getTaxableItems()),

app/code/Magento/Tax/Setup/InstallSchema.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,5 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
405405
);
406406

407407
$setup->endSetup();
408-
409408
}
410409
}

app/code/Magento/Tax/Setup/TaxSetup.php

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,18 @@
66
namespace Magento\Tax\Setup;
77

88
use Magento\Catalog\Model\ProductTypes\ConfigInterface;
9-
use Magento\Catalog\Setup\CategorySetup;
10-
use Magento\Catalog\Setup\CategorySetupFactory;
11-
use Magento\Eav\Model\Entity\Setup\Context;
12-
use Magento\Eav\Model\Resource\Entity\Attribute\Group\CollectionFactory;
13-
use Magento\Framework\App\CacheInterface;
14-
use Magento\Framework\App\Config\ScopeConfigInterface;
159
use Magento\Framework\Setup\ModuleDataSetupInterface;
16-
use Magento\Sales\Setup\SalesSetup;
10+
use Magento\Sales\Setup\SalesSetupFactory;
1711

1812
/**
1913
* Tax Setup Resource Model
2014
*/
21-
class TaxSetup extends SalesSetup
15+
class TaxSetup
2216
{
2317
/**
24-
* Category setup factory
25-
*
26-
* @var CategorySetupFactory
18+
* @var \Magento\Sales\Setup\SalesSetup
2719
*/
28-
protected $_setupFactory;
20+
protected $salesSetup;
2921

3022
/**
3123
* Product type config
@@ -38,44 +30,55 @@ class TaxSetup extends SalesSetup
3830
* Init
3931
*
4032
* @param ModuleDataSetupInterface $setup
41-
* @param Context $context
42-
* @param CacheInterface $cache
43-
* @param CollectionFactory $attrGroupCollectionFactory
44-
* @param ScopeConfigInterface $config
45-
* @param CategorySetupFactory $setupFactory
33+
* @param SalesSetupFactory $salesSetupFactory
4634
* @param ConfigInterface $productTypeConfig
4735
*/
4836
public function __construct(
4937
ModuleDataSetupInterface $setup,
50-
Context $context,
51-
CacheInterface $cache,
52-
CollectionFactory $attrGroupCollectionFactory,
53-
ScopeConfigInterface $config,
54-
CategorySetupFactory $setupFactory,
38+
SalesSetupFactory $salesSetupFactory,
5539
ConfigInterface $productTypeConfig
5640
) {
57-
$this->_setupFactory = $setupFactory;
41+
$this->salesSetup = $salesSetupFactory->create(['resourceName' => 'tax_setup', 'setup' => $setup]);
5842
$this->productTypeConfig = $productTypeConfig;
5943
}
6044

6145
/**
62-
* Gets catalog setup
46+
* Get taxable product types
6347
*
64-
* @param array $data
65-
* @return CategorySetup
48+
* @return array
6649
*/
67-
public function getCatalogSetup(array $data = [])
50+
public function getTaxableItems()
6851
{
69-
return $this->_setupFactory->create($data);
52+
return $this->productTypeConfig->filter('taxable');
7053
}
7154

7255
/**
73-
* Get taxable product types
56+
* Add entity attribute.
7457
*
75-
* @return array
58+
* @param int|string $entityTypeId
59+
* @param string $code
60+
* @param array $attr
61+
* @return $this
7662
*/
77-
public function getTaxableItems()
63+
public function addAttribute($entityTypeId, $code, array $attr)
7864
{
79-
return $this->productTypeConfig->filter('taxable');
65+
//Delegate
66+
return $this->salesSetup->addAttribute($entityTypeId, $code, $attr);
67+
}
68+
69+
/**
70+
* Update Attribute data and Attribute additional data.
71+
*
72+
* @param int|string $entityTypeId
73+
* @param int|string $id
74+
* @param string $field
75+
* @param mixed $value
76+
* @param int $sortOrder
77+
* @return $this
78+
*/
79+
public function updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null)
80+
{
81+
//Delegate
82+
return $this->salesSetup->updateAttribute($entityTypeId, $id, $field, $value, $sortOrder);
8083
}
8184
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Tax\Setup;
8+
9+
use Magento\Framework\Setup\UpgradeDataInterface;
10+
use Magento\Framework\Setup\ModuleContextInterface;
11+
use Magento\Framework\Setup\ModuleDataSetupInterface;
12+
13+
/**
14+
* @codeCoverageIgnore
15+
*/
16+
class UpgradeData implements UpgradeDataInterface
17+
{
18+
/**
19+
* Tax setup factory
20+
*
21+
* @var TaxSetupFactory
22+
*/
23+
private $taxSetupFactory;
24+
25+
/**
26+
* Init
27+
*
28+
* @param TaxSetupFactory $taxSetupFactory
29+
*/
30+
public function __construct(TaxSetupFactory $taxSetupFactory)
31+
{
32+
$this->taxSetupFactory = $taxSetupFactory;
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
39+
{
40+
/** @var TaxSetup $taxSetup */
41+
$taxSetup = $this->taxSetupFactory->create(['resourceName' => 'tax_setup', 'setup' => $setup]);
42+
43+
$setup->startSetup();
44+
45+
if (version_compare($context->getVersion(), '2.0.1', '<')) {
46+
//Update the tax_class_id attribute in the 'catalog_eav_attribute' table
47+
$taxSetup->updateAttribute(
48+
\Magento\Catalog\Model\Product::ENTITY,
49+
'tax_class_id',
50+
'is_visible_in_advanced_search',
51+
false
52+
);
53+
}
54+
55+
$setup->endSetup();
56+
}
57+
}

app/code/Magento/Tax/Test/Unit/Pricing/Render/AdjustmentTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ public function testGetAdjustmentCode()
9191
$this->assertEquals(\Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE, $this->model->getAdjustmentCode());
9292
}
9393

94+
/**
95+
* Test for method getDefaultExclusions
96+
*/
97+
public function testGetDefaultExclusions()
98+
{
99+
$defaultExclusions = $this->model->getDefaultExclusions();
100+
$this->assertNotEmpty($defaultExclusions, 'Expected to have at least one default exclusion');
101+
$this->assertContains($this->model->getAdjustmentCode(), $defaultExclusions);
102+
}
103+
94104
/**
95105
* Test for method displayBothPrices
96106
*/

app/code/Magento/Tax/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
9-
<module name="Magento_Tax" setup_version="2.0.0">
9+
<module name="Magento_Tax" setup_version="2.0.1">
1010
<sequence>
1111
<module name="Magento_Catalog"/>
1212
<module name="Magento_Customer"/>

app/code/Magento/Tax/view/base/templates/pricing/adjustment.phtml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
<?php /** @var \Magento\Tax\Pricing\Render\Adjustment $block */ ?>
1212

13-
<?php
14-
//getAdjustmentCode
15-
?>
16-
1713
<?php if ($block->displayBothPrices()): ?>
1814
<span id="<?php /* @escapeNotVerified */ echo $block->buildIdWithPrefix('price-excluding-tax-') ?>"
1915
data-label="<?php echo $block->escapeHtml(__('Excl. Tax')); ?>"

app/code/Magento/Weee/Block/Item/Price/Renderer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function displayPriceWithWeeeDetails()
6161
if (!$displayWeeeDetails) {
6262
return false;
6363
}
64-
if ($this->weeeHelper->getAppliedAmount($this->getItem()) <= 0) {
64+
if ($this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem()) <= 0) {
6565
return false;
6666
}
6767

@@ -182,7 +182,7 @@ public function getUnitDisplayPriceExclTax()
182182
}
183183

184184
if ($this->getIncludeWeeeFlag()) {
185-
return $priceExclTax + $this->getItem()->getWeeeTaxAppliedAmount();
185+
return $priceExclTax + $this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem());
186186
}
187187

188188
return $priceExclTax;
@@ -224,7 +224,7 @@ public function getRowDisplayPriceExclTax()
224224
}
225225

226226
if ($this->getIncludeWeeeFlag()) {
227-
return $rowTotalExclTax + $this->getItem()->getWeeeTaxAppliedRowAmount();
227+
return $rowTotalExclTax + $this->weeeHelper->getWeeeTaxAppliedRowAmount($this->getItem());
228228
}
229229

230230
return $rowTotalExclTax;
@@ -328,7 +328,7 @@ public function getFinalUnitDisplayPriceExclTax()
328328
return $priceExclTax;
329329
}
330330

331-
return $priceExclTax + $this->getItem()->getWeeeTaxAppliedAmount();
331+
return $priceExclTax + $this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem());
332332
}
333333

334334
/**
@@ -360,7 +360,7 @@ public function getFinalRowDisplayPriceExclTax()
360360
return $rowTotalExclTax;
361361
}
362362

363-
return $rowTotalExclTax + $this->getItem()->getWeeeTaxAppliedRowAmount();
363+
return $rowTotalExclTax + $this->weeeHelper->getWeeeTaxAppliedRowAmount($this->getItem());
364364
}
365365

366366
/**
@@ -396,7 +396,7 @@ public function displayFinalPrice()
396396
return false;
397397
}
398398

399-
if (!$this->getItem()->getWeeeTaxAppliedAmount()) {
399+
if ($this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem()) <= 0) {
400400
return false;
401401
}
402402
return true;

0 commit comments

Comments
 (0)