Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WholesaleCalculator] introduce purchasable wholesale calculator #957

Merged
merged 3 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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