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

Implement Credit-Voucher Feature #1429

Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/behat_ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
CORESHOP_TEST: 1
PIMCORE_TEST_DB_DSN: "mysql://root:root@localhost/coreshop_test"
PANTHER_EXTERNAL_BASE_URI: "http://localhost:9080/app_test.php"
PANTHER_CHROME_DRIVER_BINARY: "bin/chromedriver-bin/chromedriver_linux64"
services:
mysql:
image: mysql:5.7
Expand All @@ -32,7 +33,7 @@ jobs:
- uses: actions/checkout@v2
- uses: nanasess/setup-chromedriver@master
with:
chromedriver-version: '80.0.3987.106'
chromedriver-version: '83.0.4103.14'

- name: Install PHP
uses: shivammathur/setup-php@v2
Expand Down
4 changes: 4 additions & 0 deletions bin/chromedriver-bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Chromedriver Binaries

Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/downloads
See [notes.txt](notes.txt).
Binary file added bin/chromedriver-bin/chromedriver.exe
Binary file not shown.
Binary file added bin/chromedriver-bin/chromedriver_linux64
Binary file not shown.
Binary file added bin/chromedriver-bin/chromedriver_mac64
Binary file not shown.
18 changes: 18 additions & 0 deletions bin/chromedriver-bin/notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---------ChromeDriver 83.0.4103.39 (2020-05-05)---------
Supports Chrome version 83
Resolved issue 1778: Deprecate launchApp from ChromeDriver [Pri-2]
Resolved issue 2520: InitSession can wait forever when Chrome is unresponsive [Pri-3]
Resolved issue 3120: Headless mode download from new tab [Pri-2]
Resolved issue 3234: Confirm semicolon found before substring [Pri-3]
Resolved issue 3240: ExecuteGetElementRect does not check returned status from GET_SIZE [Pri-2]
Resolved issue 3331: The get_cookies() method is returning 'expiry' keys of type double, but should be int64 in w3c mode [Pri-2]
Resolved issue 3332: Retry timeout logged as severe [Pri-2]
Resolved issue 3339: Chromedriver exited unexpectedly with code null, signal SIGTRAP [Pri-2]
Resolved issue 3351: Improve Security Considerations message [Pri-2]
Resolved issue 3352: Support SendKeys for color elements [Pri-2]
Resolved issue 3353: Wait for Pending Navigation continues after frame context destroyed [Pri-2]
Resolved issue 3375: Chromedriver v80 hangs on getPageSource on some sites [Pri-1]
Resolved issue 3383: ChromeDriver 80+ on Windows seems to exit or stall on certain element or click commands [Pri-1]
Resolved issue 3399: Remove wasThrown check [Pri-3]
Resolved issue 3421: chromedriver 81. Driver returns Cyrillic text without styles [Pri-2]
Resolved issue 3422: GetElementText breaks with prototype 1.6.0.3 and chromedriver 81 [Pri-]
20 changes: 20 additions & 0 deletions bin/chromedriver-bin/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Author: Kévin Dunglas <dunglas@gmail.com>
# Download the last version of ChromeDriver binaries

latest=$(curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE)

echo "Downloading ChromeDriver version ${latest}..."

declare -a binaries=("chromedriver_linux64" "chromedriver_mac64" "chromedriver_win32")
for name in "${binaries[@]}"
do
curl -s https://chromedriver.storage.googleapis.com/${latest}/${name}.zip -O
unzip -q -o ${name}.zip
rm ${name}.zip
if [[ -f "chromedriver" ]]; then
mv chromedriver ${name}
fi
done
curl -s https://chromedriver.storage.googleapis.com/${latest}/notes.txt -O
echo "Done."
52 changes: 52 additions & 0 deletions features/domain/cart/rules/voucher_credit_action.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@domain @cart
Feature: Adding a new cart rule
In order to give the customer credit
based on the cart, we add a new credit voucher rule

Background:
Given the site operates on a store in "Austria"
And the site has a currency "Euro" with iso "EUR"
And I am in country "Austria"
And the site has a tax rate "AT" with "20%" rate
And the site has a tax rule group "AT"
And the tax rule group has a tax rule for country "Austria" with tax rate "AT"
And the site has a product "Shoe" priced at 10000
And the product has the tax rule group "AT"
And I add the product "Shoe" to my cart

Scenario: Add a new voucher credit rule with 20 euro
Given adding a cart price rule named "credit"
And the cart rule is active
And the cart rule is a voucher rule with code "asdf"
And the voucher code "asdf" is a credit voucher with credit "2000" in currency "EUR"
And the cart rule has a action voucher credit
And I apply the voucher code "asdf" to my cart
Then the cart discount should be "-2000" including tax
Then the cart discount should be "-1666" excluding tax
Then the cart total should be "8334" excluding tax
Then the cart total should be "10000" including tax

Scenario: Add a new voucher credit rule with 200 euro
Given adding a cart price rule named "credit"
And the cart rule is active
And the cart rule is a voucher rule with code "asdf"
And the voucher code "asdf" is a credit voucher with credit "20000" in currency "EUR"
And the cart rule has a action voucher credit
And I apply the voucher code "asdf" to my cart
Then the cart discount should be "-12000" including tax
Then the cart discount should be "-10000" excluding tax
Then the cart total should be "0" excluding tax
Then the cart total should be "0" including tax

Scenario: Add a new voucher credit rule with 200 euro and an already used credit
Given adding a cart price rule named "credit"
And the cart rule is active
And the cart rule is a voucher rule with code "asdf"
And the voucher code "asdf" is a credit voucher with credit "20000" in currency "EUR" and credit used "10000"
And the cart rule has a action voucher credit
And I apply the voucher code "asdf" to my cart
Then the cart discount should be "-10000" including tax
Then the cart discount should be "-8333" excluding tax
Then the cart total should be "1667" excluding tax
Then the cart total should be "2000" including tax

36 changes: 36 additions & 0 deletions src/CoreShop/Behat/Context/Setup/CartPriceRuleContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use CoreShop\Bundle\OrderBundle\Form\Type\Rule\Condition\AmountConfigurationType;
use CoreShop\Bundle\OrderBundle\Form\Type\Rule\Condition\TimespanConfigurationType;
use CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistryInterface;
use CoreShop\Bundle\RuleBundle\Form\Type\Rule\EmptyConfigurationFormType;
use CoreShop\Component\Address\Model\ZoneInterface;
use CoreShop\Component\Core\Model\OrderInterface;
use CoreShop\Component\Core\Model\CategoryInterface;
Expand Down Expand Up @@ -469,6 +470,41 @@ public function theCartPriceRuleHasASurchargeAmountAction(CartPriceRuleInterface
]));
}

/**
* @Given /^the (cart rule "[^"]+") has a action voucher credit$/
* @Given /^the (cart rule) has a action voucher credit$/
*/
public function theCartPriceRuleHasAVoucherCreditAction(CartPriceRuleInterface $rule)
{
$this->addAction($rule, $this->createActionWithForm('voucherCredit'));
}

/**
* @Given /^the voucher code "([^"]+)" is a credit voucher with credit "([^"]+)" in (currency "[^"]+")$/
* @Given /^the voucher code "([^"]+)" is a credit voucher with credit "([^"]+)" in (currency "[^"]+") and credit used "([^"]+)"$/
*/
public function theVoucherCodeIsACreditCodeWithCreditInCurrency($voucherCode, int $credit, CurrencyInterface $currency, int $used = null)
{
$voucherCode = $this->cartPriceRuleVoucherRepository->findByCode($voucherCode);

/**
* @var $voucherCode CartPriceRuleVoucherCodeInterface
* @var $cartPriceRule CartPriceRuleInterface
*/
Assert::isInstanceOf($voucherCode, CartPriceRuleVoucherCodeInterface::class);

$voucherCode->setIsCreditCode(true);
$voucherCode->setCreditAvailable($credit);
$voucherCode->setCreditCurrency($currency);

if (null !== $used) {
$voucherCode->setCreditUsed($used);
}

$this->objectManager->persist($voucherCode);
$this->objectManager->flush();
}

/**
* @param CartPriceRuleInterface $rule
* @param ConditionInterface $condition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ protected function expandDotNotationKeys(array $array)

while (count($array)) {
$value = reset($array);
$key = key($array);
$key = (string)key($array);
unset($array[$key]);

if (strpos($key, '.') !== false) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace CoreShop\Bundle\CoreBundle\Migrations;

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

class Version20200617120130 extends AbstractPimcoreMigration implements ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->addSql('
ALTER TABLE coreshop_cart_price_rule_voucher_code ADD creditUsed INT NOT NULL, ADD isCreditCode TINYINT(1) NOT NULL;
ALTER TABLE coreshop_payment ADD client_email VARCHAR(255) DEFAULT NULL, ADD client_id VARCHAR(255) DEFAULT NULL, CHANGE total_amount total_amount INT DEFAULT NULL;
ALTER TABLE coreshop_cart_price_rule_voucher_code ADD creditAvailable INT NOT NULL, ADD currencyId INT DEFAULT NULL;
ALTER TABLE coreshop_cart_price_rule_voucher_code ADD CONSTRAINT FK_4AF500A991000B8A FOREIGN KEY (currencyId) REFERENCES coreshop_currency (id) ON DELETE SET NULL;
CREATE INDEX IDX_4AF500A991000B8A ON coreshop_cart_price_rule_voucher_code (currencyId);
');

$this->container->get('pimcore.cache.core.handler')->clearTag('doctrine_pimcore_cache');
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ services:
tags:
- { name: coreshop.cart_price_rule.action, type: discountAmount, form-type: CoreShop\Bundle\OrderBundle\Form\Type\Rule\Action\DiscountAmountConfigurationType }

coreshop.cart_price_rule.action.voucher_credit:
class: CoreShop\Component\Core\Cart\Rule\Action\VoucherCreditActionProcessor
arguments:
- '@CoreShop\Component\Currency\Converter\CurrencyConverterInterface'
- '@coreshop.cart_price_rule.cart_rule_applier'
- '@coreshop.repository.cart_price_rule_voucher_code'
tags:
- { name: coreshop.cart_price_rule.action, type: voucherCredit }

coreshop.cart_price_rule.action.surcharge_amount:
class: CoreShop\Component\Core\Cart\Rule\Action\SurchargeAmountActionProcessor
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ body.pimcore_version_6 .coreshop_nav_icon_customer_to_company_assign_to_existing
background: url(../img/free-shipping.svg) center center no-repeat !important;
}

.coreshop_rule_icon_action_voucherCredit {
background: url(../img/voucher.svg) center center no-repeat !important;
}

.coreshop_rule_icon_condition_currencies {
background: url(../img/currencies.svg) center center no-repeat !important;
}
Expand Down Expand Up @@ -200,4 +204,4 @@ body.pimcore_version_6 .coreshop_nav_icon_customer_to_company_assign_to_existing
.x-btn.coreshop-transparent-btn {
background: transparent;
border: transparent;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ coreshop_condition_zones: 'Zones'
coreshop_condition_categories: 'Categories'
coreshop_condition_recursive: 'Include all Subcategories'
coreshop_action_giftProduct: 'Gift Product'
coreshop_action_voucherCredit: 'Voucher Credit'
coreshop_zones: 'Zones'
coreshop_suffix: 'Suffix'
coreshop_prefix: 'Prefix'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ CoreShop\Component\Order\Model\CartPriceRuleVoucherCode:
uses:
column: uses
type: integer
creditUsed:
column: creditUsed
type: integer
creditAvailable:
column: creditAvailable
type: integer
isCreditCode:
column: isCreditCode
type: boolean
creationDate:
type: datetime
gedmo:
Expand All @@ -36,6 +45,12 @@ CoreShop\Component\Order\Model\CartPriceRuleVoucherCode:
inversedBy: voucherCodes
joinColumn:
name: cartPriceRuleId
creditCurrency:
targetEntity: CoreShop\Component\Currency\Model\CurrencyInterface
joinColumn:
name: currencyId
referencedColumnName: id
onDelete: 'SET NULL'
uniqueConstraints:
code:
columns: [code]
columns: [code]
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ protected function expandDotNotationKeys(array $array)

while (count($array)) {
$value = reset($array);
$key = key($array);
$key = (string)key($array);
unset($array[$key]);

if (strpos($key, '.') !== false) {
Expand Down
Loading