Skip to content

Commit

Permalink
Merge pull request #957 from dpfaffenbauer/wholesale-calculator
Browse files Browse the repository at this point in the history
[WholesaleCalculator] introduce purchasable wholesale calculator
  • Loading branch information
dpfaffenbauer authored Apr 25, 2019
2 parents 81c0aa7 + 5233dde commit 14fc942
Show file tree
Hide file tree
Showing 23 changed files with 710 additions and 96 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG-2.1.x.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Within 2.1

## 2.1.0
- Introduced WholesalePrice Calculators, this deprecates the "wholesalePrice" property in the Product Class and adds the "wholesaleBuyingPrice" Property with a currency attached. We've added a migration for that, but since we need a currency now, we just assume the buying currency as the defaults store currency. If you have a different one, create a custom migration that changes it.

- `CoreShop\Component\StorageList\StorageListModifierInterface` got completely refactored and works a bit different now. Since deciding what StorageListItem belongs to what product, can be a bit more complicated, we decided to introduce a BC break.
- `CoreShop\Component\StorageList\StorageListModifierInterface` added `addToList` function
- `CoreShop\Component\StorageList\StorageListModifierInterface` removed `remove` to `removeFromList`
Expand All @@ -23,4 +25,4 @@
- Introduced Store Unit:
- Please add `product_unit` to permission table.
- Remove `storePrice` field from all product classes
- If you don't use the `Store Price` element in your classes besides the `storePrice` field, you should delete the `coreshop_product_store_price` table after migration.
- If you don't use the `Store Price` element in your classes besides the `storePrice` field, you should delete the `coreshop_product_store_price` table after migration.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\CoreBundle\Migrations;

use CoreShop\Component\Pimcore\DataObject\ClassUpdate;
use Doctrine\DBAL\Schema\Schema;
use Pimcore\Migrations\Migration\AbstractPimcoreMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class Version20190425105238 extends AbstractPimcoreMigration implements ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$orderItemClass = $this->container->getParameter('coreshop.model.order_item.pimcore_class_name');
$quoteItemClass = $this->container->getParameter('coreshop.model.quote_item.pimcore_class_name');

$field = [
'fieldtype' => 'coreShopMoney',
'width' => '',
'defaultValue' => null,
'minValue' => null,
'maxValue' => null,
'name' => 'baseItemWholesalePrice',
'title' => 'Base Item Wholesale Price',
'tooltip' => '',
'mandatory' => false,
'noteditable' => true,
'index' => false,
'locked' => false,
'style' => '',
'permissions' => null,
'datatype' => 'data',
'relationType' => false,
'invisible' => false,
'visibleGridView' => false,
'visibleSearch' => false
];

foreach ([$orderItemClass, $quoteItemClass] as $class) {
$classUpdater = new ClassUpdate($class);

if (!$classUpdater->hasField('baseItemWholesalePrice')) {
$classUpdater->insertFieldBefore('baseItemPriceNet', $field);

$classUpdater->save();
}
}
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\CoreBundle\Migrations;

use CoreShop\Component\Pimcore\DataObject\ClassUpdate;
use Doctrine\DBAL\Schema\Schema;
use Pimcore\Cache;
use Pimcore\Migrations\Migration\AbstractPimcoreMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class Version20190425111940 extends AbstractPimcoreMigration implements ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$productClass = $this->container->getParameter('coreshop.model.product.pimcore_class_name');
$productRepo = $this->container->get('coreshop.repository.product');

$classId = $productRepo->getClassId();

$updater = new ClassUpdate($productClass);

if (!$updater->hasField('wholesaleBuyingPrice')) {
$updater->insertFieldAfter('wholesalePrice', [
'fieldtype' => 'coreShopMoneyCurrency',
'width' => '',
'phpdocType' => 'CoreShop\\Component\\Currency\\Model\\Money',
'minValue' => NULL,
'maxValue' => NULL,
'name' => 'wholesaleBuyingPrice',
'title' => 'Wholesale Buying Price',
'tooltip' => '',
'mandatory' => false,
'noteditable' => false,
'index' => false,
'locked' => NULL,
'style' => '',
'permissions' => NULL,
'datatype' => 'data',
'relationType' => false,
'invisible' => false,
'visibleGridView' => false,
'visibleSearch' => false,
]);
$updater->save();
}

//Assume Standard Store Currency as wholesale Currency
$store = $this->container->get('coreshop.repository.store')->findStandard();

$this->addSql(sprintf(
'UPDATE object_query_%s SET `wholesaleBuyingPrice__value` = `wholesalePrice`, `wholesaleBuyingPrice__currency` = %s',
$classId,
$store->getCurrency()->getId()
));
$this->addSql(sprintf(
'UPDATE object_store_%s SET `wholesaleBuyingPrice__value` = `wholesalePrice`, `wholesaleBuyingPrice__currency` = %s',
$classId,
$store->getCurrency()->getId()
));

Cache::clearAll();
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ services:
tags:
- { name: coreshop.cart_processor, priority: 600 }

coreshop.cart_processor.items_wholesale:
class: CoreShop\Component\Core\Order\Processor\CartItemsWholesaleProcessor
arguments:
- '@coreshop.order.purchasable.wholesale_price_calculator'
tags:
- { name: coreshop.cart_processor, priority: 575 }

coreshop.cart_processor.shipping:
class: CoreShop\Component\Core\Order\Processor\CartShippingProcessor
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,27 +464,6 @@
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
},
{
"fieldtype": "coreShopMoney",
"width": "",
"defaultValue": null,
"minValue": null,
"maxValue": null,
"name": "itemWholesalePrice",
"title": "Item Wholesale Price",
"tooltip": "",
"mandatory": false,
"noteditable": true,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
}
],
"locked": false
Expand Down Expand Up @@ -519,6 +498,27 @@
"datatype": "layout",
"permissions": null,
"childs": [
{
"fieldtype": "coreShopMoney",
"width": "",
"defaultValue": null,
"minValue": null,
"maxValue": null,
"name": "itemWholesalePrice",
"title": "Item Wholesale Price",
"tooltip": "",
"mandatory": false,
"noteditable": true,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
},
{
"fieldtype": "coreShopMoney",
"width": "",
Expand Down Expand Up @@ -779,6 +779,27 @@
"datatype": "layout",
"permissions": null,
"childs": [
{
"fieldtype": "coreShopMoney",
"width": "",
"defaultValue": null,
"minValue": null,
"maxValue": null,
"name": "baseItemWholesalePrice",
"title": "Base Item Wholesale Price",
"tooltip": "",
"mandatory": false,
"noteditable": true,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
},
{
"fieldtype": "coreShopMoney",
"width": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,27 +464,6 @@
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
},
{
"fieldtype": "coreShopMoney",
"width": "",
"defaultValue": null,
"minValue": null,
"maxValue": null,
"name": "itemWholesalePrice",
"title": "Item Wholesale Price",
"tooltip": "",
"mandatory": false,
"noteditable": true,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
}
],
"locked": false
Expand Down Expand Up @@ -519,6 +498,27 @@
"datatype": "layout",
"permissions": null,
"childs": [
{
"fieldtype": "coreShopMoney",
"width": "",
"defaultValue": null,
"minValue": null,
"maxValue": null,
"name": "itemWholesalePrice",
"title": "Item Wholesale Price",
"tooltip": "",
"mandatory": false,
"noteditable": true,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
},
{
"fieldtype": "coreShopMoney",
"width": "",
Expand Down Expand Up @@ -779,6 +779,27 @@
"datatype": "layout",
"permissions": null,
"childs": [
{
"fieldtype": "coreShopMoney",
"width": "",
"defaultValue": null,
"minValue": null,
"maxValue": null,
"name": "baseItemWholesalePrice",
"title": "Base Item Wholesale Price",
"tooltip": "",
"mandatory": false,
"noteditable": true,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
},
{
"fieldtype": "coreShopMoney",
"width": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,27 @@
"visibleGridView": false,
"visibleSearch": false
},
{
"fieldtype": "coreShopMoneyCurrency",
"width": "",
"phpdocType": "CoreShop\\Component\\Currency\\Model\\Money",
"minValue": null,
"maxValue": null,
"name": "wholesaleBuyingPrice",
"title": "Wholesale Buying Price",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
},
{
"fieldtype": "coreShopTaxRuleGroup",
"allowEmpty": true,
Expand Down Expand Up @@ -1032,4 +1053,4 @@
"creationDate": true
}
}
}
}
Loading

0 comments on commit 14fc942

Please sign in to comment.