-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #957 from dpfaffenbauer/wholesale-calculator
[WholesaleCalculator] introduce purchasable wholesale calculator
- Loading branch information
Showing
23 changed files
with
710 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/CoreShop/Bundle/CoreBundle/Migrations/Version20190425105238.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/CoreShop/Bundle/CoreBundle/Migrations/Version20190425111940.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.