Skip to content

Commit b5b9791

Browse files
author
Petrov Yehven
authored
Merge pull request #10 from orocommerce/commerce-1.0.0-beta.3
Commerce 1.0.0 beta.3
2 parents 061272d + da23784 commit b5b9791

File tree

13 files changed

+130
-65
lines changed

13 files changed

+130
-65
lines changed

Diff for: src/OroB2B/Bundle/PricingBundle/Layout/DataProvider/FrontendProductPricesProvider.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
99

10+
use OroB2B\Bundle\PricingBundle\Entity\CombinedProductPrice;
1011
use OroB2B\Bundle\PricingBundle\Entity\ProductPrice;
1112
use OroB2B\Bundle\PricingBundle\Entity\Repository\ProductPriceRepository;
1213
use OroB2B\Bundle\PricingBundle\Model\PriceListRequestHandler;
@@ -78,20 +79,19 @@ public function getData(ContextInterface $context)
7879
]
7980
);
8081
if (count($prices)) {
81-
$unitPrecisions = current($prices)->getProduct()->getUnitPrecisions();
82+
$unitPrecisions = $product->getUnitPrecisions();
8283

8384
$unitsToSell = [];
8485
foreach ($unitPrecisions as $unitPrecision) {
85-
if ($unitPrecision->isSell()) {
86-
$unitsToSell[] = $unitPrecision->getUnit();
87-
}
86+
$unitsToSell[$unitPrecision->getUnit()->getCode()] = $unitPrecision->isSell();
8887
}
8988

90-
foreach ($prices as $key => $combinedProductPrice) {
91-
if (!in_array($combinedProductPrice->getUnit(), $unitsToSell)) {
92-
unset($prices[$key]);
89+
$prices = array_filter(
90+
$prices,
91+
function (CombinedProductPrice $price) use ($unitsToSell) {
92+
return !empty($unitsToSell[$price->getProductUnitCode()]);
9393
}
94-
}
94+
);
9595
}
9696

9797
$this->data[$productId] = $prices;

Diff for: src/OroB2B/Bundle/PricingBundle/Migrations/Schema/v1_3/OroB2BPricingBundle.php

-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ protected function addOrob2BCmbPriceListToAccForeignKeys(Schema $schema)
284284
['id'],
285285
['onUpdate' => null, 'onDelete' => 'CASCADE']
286286
);
287-
288287
}
289288

290289
/**

Diff for: src/OroB2B/Bundle/PricingBundle/Migrations/Schema/v1_3/PostMigrationUpdates.php

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function up(Schema $schema, QueryBag $queries)
3030

3131
/**
3232
* @param Schema $schema
33+
* @param QueryBag $queries
3334
* @throws \Doctrine\DBAL\Schema\SchemaException
3435
*/
3536
protected function updatePriceListTable(Schema $schema, QueryBag $queries)
@@ -46,6 +47,7 @@ protected function updatePriceListTable(Schema $schema, QueryBag $queries)
4647

4748
/**
4849
* @param Schema $schema
50+
* @param QueryBag $queries
4951
* @throws \Doctrine\DBAL\Schema\SchemaException
5052
*/
5153
protected function updatePriceListCombinedTable(Schema $schema, QueryBag $queries)

Diff for: src/OroB2B/Bundle/PricingBundle/Tests/Unit/Layout/DataProvider/FrontendProductPricesProviderTest.php

+31-35
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;
99

10+
use OroB2B\Bundle\PricingBundle\Entity\CombinedProductPrice;
1011
use OroB2B\Bundle\PricingBundle\Layout\DataProvider\FrontendProductPricesProvider;
1112
use OroB2B\Bundle\PricingBundle\Model\PriceListRequestHandler;
1213
use OroB2B\Bundle\PricingBundle\Manager\UserCurrencyManager;
14+
use OroB2B\Bundle\ProductBundle\Entity\Product;
15+
use OroB2B\Bundle\ProductBundle\Entity\ProductUnit;
16+
use OroB2B\Bundle\ProductBundle\Entity\ProductUnitPrecision;
1317

1418
class FrontendProductPricesProviderTest extends \PHPUnit_Framework_TestCase
1519
{
@@ -68,13 +72,13 @@ public function testGetDataWithEmptyContext()
6872

6973
public function testGetData()
7074
{
71-
$prices = [1 => 'test', 2 => 'test2'];
7275
$priceListId = 23;
7376
$priceList = $this->getEntity('OroB2B\Bundle\PricingBundle\Entity\PriceList', ['id' => $priceListId]);
7477
$productId = 24;
75-
$product = $this->getMockBuilder('OroB2B\Bundle\ProductBundle\Entity\Product')
76-
->disableOriginalConstructor()
77-
->getMock();
78+
/** @var Product|\PHPUnit_Framework_MockObject_MockObject $product */
79+
$product = $this->getMockBuilder('OroB2B\Bundle\ProductBundle\Entity\Product')
80+
->disableOriginalConstructor()
81+
->getMock();
7882

7983
$product->expects($this->once())
8084
->method('getId')
@@ -84,13 +88,13 @@ public function testGetData()
8488
$unitPrecisions[] = $this->createUnitPrecision('set', false);
8589

8690
$product->expects($this->once())
87-
->method('getUnitPrecisions')
88-
->willReturn($unitPrecisions);
91+
->method('getUnitPrecisions')
92+
->willReturn($unitPrecisions);
8993

9094
$productPrice1 = $this->createProductPrice('each', $product);
9195
$productPrice2 = $this->createProductPrice('set', $product);
9296
$prices = [$productPrice1, $productPrice2];
93-
97+
9498
$priceSorting = ['unit' => 'ASC', 'currency' => 'DESC', 'quantity' => 'ASC'];
9599
$context = new LayoutContext();
96100
$context->data()->set('product', null, $product);
@@ -117,29 +121,20 @@ public function testGetData()
117121
->willReturn('EUR');
118122

119123
$actual = $this->provider->getData($context);
120-
$this->assertEquals(1, count($actual));
124+
$this->assertCount(1, $actual);
121125
$this->assertEquals('each', current($actual)->getUnit());
122126
}
123127

124128
/**
125129
* @param string $unitCode
126-
* @param boolen $sell
127-
* @return productUnitPresion
130+
* @param boolean $sell
131+
* @return ProductUnitPrecision
128132
*/
129133
private function createUnitPrecision($unitCode, $sell)
130134
{
131-
$p = $this->getMockBuilder('OroB2B\Bundle\ProductBundle\Entity\ProductUnionPrecision')
132-
->setMethods(array('isSell', 'getUnit'))
133-
->disableOriginalConstructor()
134-
->getMock();
135-
136-
$p->expects($this->once())
137-
->method('isSell')
138-
->willReturn($sell);
139-
140-
$p->expects($this->any())
141-
->method('getUnit')
142-
->willReturn($unitCode);
135+
$p = new ProductUnitPrecision();
136+
$p->setSell($sell);
137+
$p->setUnit($this->getUnit($unitCode));
143138

144139
return $p;
145140
}
@@ -151,21 +146,22 @@ private function createUnitPrecision($unitCode, $sell)
151146
*/
152147
private function createProductPrice($unit, $product)
153148
{
154-
$p = $this->getMockBuilder(
155-
'OroB2B\Bundle\PricingBundle\Entity\CombinedProductPrice',
156-
array('getUnit', 'getProduct')
157-
)
158-
->disableOriginalConstructor()
159-
->getMock();
149+
$p = new CombinedProductPrice();
150+
$p->setProduct($product);
151+
$p->setUnit($this->getUnit($unit));
160152

161-
$p->expects($this->any())
162-
->method('getProduct')
163-
->willReturn($product);
153+
return $p;
154+
}
164155

165-
$p->expects($this->any())
166-
->method('getUnit')
167-
->willReturn($unit);
156+
/**
157+
* @param string $unitCode
158+
* @return ProductUnit
159+
*/
160+
private function getUnit($unitCode)
161+
{
162+
$unit = new ProductUnit();
163+
$unit->setCode($unitCode);
168164

169-
return $p;
165+
return $unit;
170166
}
171167
}

Diff for: src/OroB2B/Bundle/ProductBundle/Entity/ProductUnitPrecision.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ProductUnitPrecision implements ProductUnitHolderInterface
9696
/**
9797
* @var bool
9898
*
99-
* @ORM\Column(name="sell",type="boolean",nullable=true)
99+
* @ORM\Column(name="sell",type="boolean",nullable=false)
100100
* @ConfigField(
101101
* defaultValues={
102102
* "importexport"={
@@ -105,7 +105,7 @@ class ProductUnitPrecision implements ProductUnitHolderInterface
105105
* }
106106
* )
107107
*/
108-
protected $sell;
108+
protected $sell = true;
109109

110110
public function __clone()
111111
{

Diff for: src/OroB2B/Bundle/ProductBundle/ImportExport/DataConverter/ProductDataConverter.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,22 @@ public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
3030
protected function getBackendHeader()
3131
{
3232
$backendHeader = parent::getBackendHeader();
33-
33+
3434
// According to business logic Product should have Primary and Additional unit precisions.
3535
// But Product Entity has primaryUnitPrecision property and unitPrecisions property which
3636
// is collection of all unit precisions. AdditionalUnitPrecisions is calculated by excluding
3737
// PrimaryUnitPrecision from all UnitPrecisions. This fix was done in order to display
3838
// correct column headers during Products Export.
3939
foreach ($backendHeader as $k => &$v) {
40-
$arr = explode(":", $v);
41-
if ($arr[0] == "unitPrecisions" && $arr[1] == "0") {
42-
unset($backendHeader[$k]);
43-
} elseif ($arr[0] == "unitPrecisions") {
44-
$arr[0] = "additionalUnitPrecisions";
45-
$arr[1] = $arr[1] - 1;
46-
$v = implode(":", $arr);
40+
$arr = explode(':', $v);
41+
if ($arr[0] === 'unitPrecisions') {
42+
if ((int)$arr[1] === 0) {
43+
unset($backendHeader[$k]);
44+
} else {
45+
$arr[0] = 'additionalUnitPrecisions';
46+
--$arr[1];
47+
$v = implode(':', $arr);
48+
}
4749
}
4850
}
4951
unset($v);

Diff for: src/OroB2B/Bundle/ProductBundle/ImportExport/Normalizer/ProductNormalizer.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ public function setProductClass($productClass)
3838
}
3939

4040
/**
41+
* @param Product $object
42+
*
4143
* {@inheritdoc}
4244
*/
4345
public function normalize($object, $format = null, array $context = [])
4446
{
4547
$data = parent::normalize($object, $format, $context);
4648

47-
if (array_key_exists('unitPrecisions', $data)) {
49+
if (array_key_exists('unitPrecisions', $data) && is_array($data['unitPrecisions'])) {
4850
foreach ($data['unitPrecisions'] as $v) {
49-
if ($v['unit']['code'] != $object->getPrimaryUnitPrecision()->getUnit()->getCode()) {
51+
if ($v['unit']['code'] !== $object->getPrimaryUnitPrecision()->getUnit()->getCode()) {
5052
$data['additionalUnitPrecisions'][] = $v;
5153
}
5254
}
@@ -69,6 +71,10 @@ public function denormalize($data, $class, $format = null, array $context = [])
6971
if (array_key_exists('additionalUnitPrecisions', $data)) {
7072
$data['unitPrecisions'] = $data['additionalUnitPrecisions'];
7173
unset($data['additionalUnitPrecisions']);
74+
foreach ($data['unitPrecisions'] as &$unitPrecisionData) {
75+
$unitPrecisionData['sell'] = !empty($unitPrecisionData['sell']);
76+
}
77+
unset($unitPrecisionData);
7278
}
7379

7480
/**

Diff for: src/OroB2B/Bundle/ProductBundle/Migrations/Schema/OroB2BProductBundleInstaller.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ protected function createOroB2BProductUnitPrecisionTable(Schema $schema)
157157
$table->addColumn('unit_code', 'string', ['notnull' => false, 'length' => 255]);
158158
$table->addColumn('unit_precision', 'integer', []);
159159
$table->addColumn('conversion_rate', 'float', ['notnull' => false]);
160-
$table->addColumn('sell', 'boolean', ['notnull' => false]);
160+
$table->addColumn('sell', 'boolean', ['notnull' => true]);
161161
$table->setPrimaryKey(['id']);
162162
$table->addUniqueIndex(['product_id', 'unit_code'], 'product_unit_precision__product_id__unit_code__uidx');
163163
}

Diff for: src/OroB2B/Bundle/ProductBundle/Migrations/Schema/v1_4/OroB2BProductBundle.php

+20-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
66
use Symfony\Component\DependencyInjection\ContainerInterface;
77

8+
use Doctrine\DBAL\Types\Type;
89
use Doctrine\DBAL\Schema\Schema;
910

1011
use Oro\Bundle\AttachmentBundle\Migration\Extension\AttachmentExtension;
1112
use Oro\Bundle\AttachmentBundle\Migration\Extension\AttachmentExtensionAwareInterface;
1213
use Oro\Bundle\MigrationBundle\Migration\Extension\RenameExtension;
1314
use Oro\Bundle\MigrationBundle\Migration\Extension\RenameExtensionAwareInterface;
15+
use Oro\Bundle\MigrationBundle\Migration\ParametrizedSqlMigrationQuery;
1416
use Oro\Bundle\MigrationBundle\Migration\Migration;
1517
use Oro\Bundle\MigrationBundle\Migration\OrderedMigrationInterface;
1618
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
@@ -94,7 +96,7 @@ public function up(Schema $schema, QueryBag $queries)
9496
'oro_fallback_localization_val',
9597
['localized_value_id']
9698
);
97-
$this->updateOroB2BProductUnitPrecisionTable($schema);
99+
$this->updateOroB2BProductUnitPrecisionTable($schema, $queries);
98100
$this->updateOroB2BProductTable($schema);
99101
$this->addOroB2BProductForeignKeys($schema);
100102

@@ -132,12 +134,27 @@ protected function createConstraint(Schema $schema, QueryBag $queries, $tableNam
132134
* Update orob2b_product_unit_precision table
133135
*
134136
* @param Schema $schema
137+
* @param QueryBag $queries
135138
*/
136-
protected function updateOroB2BProductUnitPrecisionTable(Schema $schema)
139+
protected function updateOroB2BProductUnitPrecisionTable(Schema $schema, QueryBag $queries)
137140
{
138141
$table = $schema->getTable(self::PRODUCT_UNIT_PRECISION_TABLE_NAME);
139142
$table->addColumn('conversion_rate', 'float', ['notnull' => false]);
140143
$table->addColumn('sell', 'boolean', ['notnull' => false]);
144+
145+
$queries->addQuery(
146+
new ParametrizedSqlMigrationQuery(
147+
'UPDATE orob2b_product_unit_precision SET conversion_rate = :conversion_rate, sell = :sell',
148+
[
149+
'conversion_rate' => 1.0,
150+
'sell' => true,
151+
],
152+
[
153+
'conversion_rate' => Type::FLOAT,
154+
'sell' => Type::BOOLEAN
155+
]
156+
)
157+
);
141158
}
142159

143160
/**
@@ -289,6 +306,6 @@ protected function getImageTypesSubSelect()
289306
$selects[] = sprintf('SELECT \'%s\' as type', $imageType->getName());
290307
}
291308

292-
return join(' UNION ', $selects);
309+
return implode(' UNION ', $selects);
293310
}
294311
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace OroB2B\Bundle\ProductBundle\Migrations\Schema\v1_4;
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
7+
use Oro\Bundle\MigrationBundle\Migration\Migration;
8+
use Oro\Bundle\MigrationBundle\Migration\OrderedMigrationInterface;
9+
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
10+
11+
class PostMigrationUpdates implements Migration, OrderedMigrationInterface
12+
{
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
public function getOrder()
17+
{
18+
return 30;
19+
}
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function up(Schema $schema, QueryBag $queries)
25+
{
26+
$this->updateProductUnitPrecisionTable($schema);
27+
}
28+
29+
/**
30+
* @param Schema $schema
31+
* @throws \Doctrine\DBAL\Schema\SchemaException
32+
*/
33+
protected function updateProductUnitPrecisionTable(Schema $schema)
34+
{
35+
$table = $schema->getTable('orob2b_product_unit_precision');
36+
$table->getColumn('sell')->setNotnull(true);
37+
}
38+
}

Diff for: src/OroB2B/Bundle/ProductBundle/Migrations/Schema/v1_4/RemoveImageRelationOnProduct.php

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public function up(Schema $schema, QueryBag $queries)
5050
self::PRODUCT_IMAGE_ASSOCCIATION_NAME
5151
)
5252
);
53-
5453
}
5554

5655
/**

0 commit comments

Comments
 (0)