Skip to content

Commit

Permalink
Merge pull request #25 from Setono/misc-fixes
Browse files Browse the repository at this point in the history
[BC] Float discount & other fixes
  • Loading branch information
igormukhingmailcom authored Sep 10, 2020
2 parents c803504 + e7194df commit 9298c93
Show file tree
Hide file tree
Showing 58 changed files with 628 additions and 605 deletions.
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ You have requested a non-existent parameter "setono_sylius_catalog_promotion.mod
### Add config

```yaml
# config/packages/_sylius.yaml
# config/packages/setono_sylius_catalog_promotion.yaml
imports:
- { resource: "@SetonoSyliusCatalogPromotionPlugin/Resources/config/app/config.yaml" }
# Uncomment if you want to add some catalog promotion fixtures to default suite
# - { resource: "@SetonoSyliusCatalogPromotionPlugin/Resources/config/app/fixtures.yaml" }
```

### Add routing

```yaml
# config/routes.yaml
# config/routes/setono_sylius_catalog_promotion.yaml
setono_sylius_catalog_promotion_admin:
resource: "@SetonoSyliusCatalogPromotionPlugin/Resources/config/admin_routing.yaml"
prefix: /admin
Expand All @@ -66,13 +68,18 @@ declare(strict_types=1);
namespace App\Entity;
use Setono\SyliusCatalogPromotionPlugin\Model\ChannelPricingInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\ChannelPricingTrait;
use Doctrine\ORM\Mapping as ORM;
use Setono\SyliusCatalogPromotionPlugin\Model\ChannelPricingInterface as CatalogPromotionChannelPricingInterface;
use Setono\SyliusCatalogPromotionPlugin\Model\ChannelPricingTrait as CatalogPromotionChannelPricingTrait;
use Sylius\Component\Core\Model\ChannelPricing as BaseChannelPricing;
class ChannelPricing extends BaseChannelPricing implements ChannelPricingInterface
/**
* @ORM\Table(name="sylius_channel_pricing")
* @ORM\Entity()
*/
class ChannelPricing extends BaseChannelPricing implements CatalogPromotionChannelPricingInterface
{
use ChannelPricingTrait;
use CatalogPromotionChannelPricingTrait;
}
```

Expand All @@ -84,13 +91,13 @@ declare(strict_types=1);
namespace App\Repository;
use Setono\SyliusCatalogPromotionPlugin\Doctrine\ORM\ChannelPricingRepositoryTrait;
use Setono\SyliusCatalogPromotionPlugin\Repository\ChannelPricingRepositoryInterface;
use Setono\SyliusCatalogPromotionPlugin\Doctrine\ORM\ChannelPricingRepositoryTrait as CatalogPromotionChannelPricingRepositoryTrait;
use Setono\SyliusCatalogPromotionPlugin\Repository\ChannelPricingRepositoryInterface as CatalogPromotionChannelPricingRepositoryInterface;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
class ChannelPricingRepository extends EntityRepository implements ChannelPricingRepositoryInterface
class ChannelPricingRepository extends EntityRepository implements CatalogPromotionChannelPricingRepositoryInterface
{
use ChannelPricingRepositoryTrait;
use CatalogPromotionChannelPricingRepositoryTrait;
}
```

Expand All @@ -102,13 +109,13 @@ declare(strict_types=1);
namespace App\Repository;
use Setono\SyliusCatalogPromotionPlugin\Doctrine\ORM\ProductRepositoryTrait;
use Setono\SyliusCatalogPromotionPlugin\Repository\ProductRepositoryInterface;
use Setono\SyliusCatalogPromotionPlugin\Doctrine\ORM\ProductRepositoryTrait as CatalogPromotionProductRepositoryTrait;
use Setono\SyliusCatalogPromotionPlugin\Repository\ProductRepositoryInterface as CatalogPromotionProductRepositoryInterface;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository as BaseProductRepository;
class ProductRepository extends BaseProductRepository implements ProductRepositoryInterface
class ProductRepository extends BaseProductRepository implements CatalogPromotionProductRepositoryInterface
{
use ProductRepositoryTrait;
use CatalogPromotionProductRepositoryTrait;
}
```

Expand All @@ -120,20 +127,21 @@ declare(strict_types=1);
namespace App\Repository;
use Setono\SyliusCatalogPromotionPlugin\Doctrine\ORM\ProductVariantRepositoryTrait;
use Setono\SyliusCatalogPromotionPlugin\Repository\ProductVariantRepositoryInterface;
use Setono\SyliusCatalogPromotionPlugin\Doctrine\ORM\ProductVariantRepositoryTrait as CatalogPromotionProductVariantRepositoryTrait;
use Setono\SyliusCatalogPromotionPlugin\Repository\ProductVariantRepositoryInterface as CatalogPromotionProductVariantRepositoryInterface;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductVariantRepository as BaseProductVariantRepository;
class ProductVariantRepository extends BaseProductVariantRepository implements ProductVariantRepositoryInterface
class ProductVariantRepository extends BaseProductVariantRepository implements CatalogPromotionProductVariantRepositoryInterface
{
use ProductVariantRepositoryTrait;
use CatalogPromotionProductVariantRepositoryTrait;
}
```

#### Update config with extended classes
In your `config/packages/_sylius.yaml` file update the configured classes:

```yaml
# config/packages/_sylius.yaml
sylius_core:
resources:
channel_pricing:
Expand Down
16 changes: 16 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# UPGRADE NOTES

## From 0.1 to 0.2

1. Update database schema

```bash
bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate
```

And make sure you have something like this in it:

```
ALTER TABLE setono_sylius_catalog_promotion__promotion CHANGE discount discount NUMERIC(10, 5) DEFAULT '0' NOT NULL;
```
62 changes: 28 additions & 34 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,17 @@
"thecodingmachine/safe": "^1.1"
},
"require-dev": {
"behat/behat": "^3.7",
"behat/mink-selenium2-driver": "^1.4",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"friends-of-behat/mink": "^1.8",
"friends-of-behat/mink-browserkit-driver": "^1.4",
"friends-of-behat/mink-extension": "^2.4",
"friends-of-behat/page-object-extension": "^0.3",
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"lakion/mink-debug-extension": "^1.2.3",
"phpspec/phpspec": "^6.1",
"phpunit/phpunit": "^8.5",
"roave/security-advisories": "dev-master",
"setono/code-quality-pack": "^1.1",
"setono/sylius-behat-pack": "^0.1",
"symfony/browser-kit": "^4.4",
"symfony/debug-bundle": "^4.4 || ^5.0",
"symfony/dotenv": "^4.4 || ^5.0",
"symfony/intl": "^4.4 || ^5.0",
"symfony/web-profiler-bundle": "^4.4 || ^5.0",
"symfony/web-server-bundle": "^4.4 || ^5.0"
"symfony/web-profiler-bundle": "^4.4 || ^5.0"
},
"config": {
"sort-packages": true
Expand All @@ -56,7 +45,6 @@
},
"autoload-dev": {
"psr-4": {
"AppBundle\\": "tests/Application/src/AppBundle/",
"Tests\\Setono\\SyliusCatalogPromotionPlugin\\": "tests/"
},
"classmap": [
Expand All @@ -66,47 +54,53 @@
"prefer-stable": true,
"scripts": {
"all": [
"composer checks",
"composer tests"
"@checks",
"@tests"
],
"analyse": "vendor/bin/phpstan analyse -c phpstan.neon -l max src/",
"analyse": "vendor/bin/phpstan analyse -c phpstan.neon -l max src/ tests/Application/Entity tests/Application/Doctrine tests/Behat/",
"assets": [
"composer ensure-assets-installed",
"composer ensure-assets-compiled"
"@ensure-assets-installed",
"@ensure-assets-compiled"
],
"behat": [
"SYMFONY_ENV=test composer ensure-database-created",
"SYMFONY_ENV=test composer ensure-schema-updated",
"APP_ENV=test composer ensure-database-created",
"APP_ENV=test composer ensure-schema-updated",
"./vendor/bin/behat --tags=\"~@javascript\" --no-interaction --format=progress"
],
"check-style": "vendor/bin/ecs check src/ tests/ spec/",
"behat-js": [
"APP_ENV=test composer ensure-database-created",
"APP_ENV=test composer ensure-schema-updated",
"./vendor/bin/behat --tags=\"@javascript\" --no-interaction --format=progress"
],
"check-style": "vendor/bin/ecs check src/ tests/Application/Entity tests/Application/Doctrine tests/Behat/ spec/",
"checks": [
"composer check-style",
"composer analyse"
],
"ensure-assets-compiled": "[[ -d tests/Application/public/assets ]] || (cd tests/Application && yarn build && bin/console assets:install public -e ${SYMFONY_ENV:-'dev'})",
"ensure-assets-compiled": "[[ -d tests/Application/public/assets ]] || (cd tests/Application && yarn build && bin/console assets:install public)",
"ensure-assets-installed": "[[ -d tests/Application/node_modules ]] || (cd tests/Application && yarn install)",
"ensure-database-created": "(cd tests/Application && bin/console doctrine:database:create --if-not-exists -e ${SYMFONY_ENV:-'dev'})",
"ensure-schema-updated": "(cd tests/Application && bin/console doctrine:schema:update --force -e ${SYMFONY_ENV:-'dev'})",
"ensure-database-created": "(cd tests/Application && bin/console doctrine:database:create --if-not-exists)",
"ensure-schema-updated": "(cd tests/Application && bin/console doctrine:schema:update --force)",
"ensure-vendors-installed": "[[ -f vendor/autoload.php ]] || COMPOSER_MEMORY_LIMIT=-1 composer install",
"fix-style": "vendor/bin/ecs check src/ tests/ spec/ --fix",
"fix-style": "vendor/bin/ecs check src/ tests/Application/Entity tests/Application/Doctrine tests/Behat/ spec/ --fix",
"fixtures": [
"composer ensure-database-created",
"composer ensure-schema-updated",
"(cd tests/Application && bin/console sylius:fixtures:load --no-interaction -e ${SYMFONY_ENV:-'dev'})"
"(cd tests/Application && bin/console sylius:fixtures:load default --no-interaction)"
],
"phpspec": "vendor/bin/phpspec run",
"phpunit": "vendor/bin/phpunit",
"run": "(cd tests/Application && bin/console server:run -d public -e ${SYMFONY_ENV:-'dev'})",
"run": "(cd tests/Application && symfony server:start --port=8000)",
"tests": [
"composer phpspec",
"composer behat"
"@phpspec",
"@behat",
"@behat-js"
],
"try": [
"composer ensure-vendors-installed",
"composer assets",
"composer fixtures",
"composer run"
"@ensure-vendors-installed",
"@assets",
"@fixtures",
"@run"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Feature: Catalog promotion validation
And I name it "Christmas sale"
And I specify 120% action percent
And I try to add it
Then I should be notified that the maximum value of catalog promotion is 100%
Then I should be notified that catalog promotion discount range is 0% to 100%
And catalog promotion with name "Christmas sale" should not be added

@ui
Expand All @@ -69,5 +69,5 @@ Feature: Catalog promotion validation
And I name it "Christmas sale"
And I specify -20% action percent
And I try to add it
Then I should be notified that catalog promotion value must be at least 1%
Then I should be notified that catalog promotion discount range is 0% to 100%
And catalog promotion with name "Christmas sale" should not be added
21 changes: 12 additions & 9 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
parameters:
reportUnmatchedIgnoredErrors: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
reportUnmatchedIgnoredErrors: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

excludes_analyse:
# Makes PHPStan crash
- 'src/DependencyInjection/Configuration.php'
excludes_analyse:
# Makes PHPStan crash
- 'src/DependencyInjection/Configuration.php'

ignoreErrors:
- '#Parameter \#1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\.#'
- '#Cannot call method .+ on .+\\NodeParentInterface\|null\.#'
ignoreErrors:
- '/Parameter \#1 \$configuration of method .+\\Extension::processConfiguration\(\) expects .+\\ConfigurationInterface\, .+\\ConfigurationInterface\|null given\./'
- '/Cannot call method .+ on .+\\NodeParentInterface\|null\./'
- '/Only numeric types are allowed in \/\, int\|null given on the .+ side\./'
- '/Only numeric types are allowed in \-\, int\|null given on the .+ side\./'
- '/Casting to float .+ already float\./'
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ public function it_updates_property_when_price_has_changed(
ChannelPricingInterface $channelPricing,
EntityManagerInterface $entityManager
): void {
$arr = ['price' => true];
$event = new PreUpdateEventArgs($channelPricing->getWrappedObject(), $entityManager->getWrappedObject(), $arr);
$changeSet = ['price' => true];
$event = new PreUpdateEventArgs($channelPricing->getWrappedObject(), $entityManager->getWrappedObject(), $changeSet);

$channelPricing->getOriginalPrice()->willReturn(100);
$channelPricing->getPrice()->willReturn(80);
$channelPricing->hasDiscount()->willReturn(true);
$channelPricing->setManuallyDiscounted(true)->shouldBeCalled();

$this->preUpdate($event);
Expand All @@ -43,11 +42,10 @@ public function it_updates_property_when_original_price_has_changed(
ChannelPricingInterface $channelPricing,
EntityManagerInterface $entityManager
): void {
$arr = ['originalPrice' => true];
$event = new PreUpdateEventArgs($channelPricing->getWrappedObject(), $entityManager->getWrappedObject(), $arr);
$changeSet = ['originalPrice' => true];
$event = new PreUpdateEventArgs($channelPricing->getWrappedObject(), $entityManager->getWrappedObject(), $changeSet);

$channelPricing->getOriginalPrice()->willReturn(100);
$channelPricing->getPrice()->willReturn(80);
$channelPricing->hasDiscount()->willReturn(true);
$channelPricing->setManuallyDiscounted(true)->shouldBeCalled();

$this->preUpdate($event);
Expand All @@ -57,11 +55,10 @@ public function it_sets_property_to_false_when_prices_are_equal_although_propert
ChannelPricingInterface $channelPricing,
EntityManagerInterface $entityManager
): void {
$arr = ['originalPrice' => true];
$event = new PreUpdateEventArgs($channelPricing->getWrappedObject(), $entityManager->getWrappedObject(), $arr);
$changeSet = ['originalPrice' => true];
$event = new PreUpdateEventArgs($channelPricing->getWrappedObject(), $entityManager->getWrappedObject(), $changeSet);

$channelPricing->getOriginalPrice()->willReturn(100);
$channelPricing->getPrice()->willReturn(100);
$channelPricing->hasDiscount()->willReturn(false);
$channelPricing->setManuallyDiscounted(false)->shouldBeCalled();

$this->preUpdate($event);
Expand All @@ -71,8 +68,8 @@ public function it_does_not_update_property_when_no_properties_has_changed(
ChannelPricingInterface $channelPricing,
EntityManagerInterface $entityManager
): void {
$arr = [];
$event = new PreUpdateEventArgs($channelPricing->getWrappedObject(), $entityManager->getWrappedObject(), $arr);
$changeSet = [];
$event = new PreUpdateEventArgs($channelPricing->getWrappedObject(), $entityManager->getWrappedObject(), $changeSet);

$channelPricing->setManuallyDiscounted(Argument::any())->shouldNotBeCalled();

Expand All @@ -85,8 +82,7 @@ public function it_sets_property_to_false_when_prices_are_equal(
): void {
$event = new LifecycleEventArgs($channelPricing->getWrappedObject(), $entityManager->getWrappedObject());

$channelPricing->getOriginalPrice()->willReturn(100);
$channelPricing->getPrice()->willReturn(100);
$channelPricing->hasDiscount()->willReturn(false);
$channelPricing->setManuallyDiscounted(false)->shouldBeCalled();

$this->prePersist($event);
Expand All @@ -98,8 +94,7 @@ public function it_sets_property_to_true_when_prices_are_not_equal(
): void {
$event = new LifecycleEventArgs($channelPricing->getWrappedObject(), $entityManager->getWrappedObject());

$channelPricing->getOriginalPrice()->willReturn(100);
$channelPricing->getPrice()->willReturn(80);
$channelPricing->hasDiscount()->willReturn(true);
$channelPricing->setManuallyDiscounted(true)->shouldBeCalled();

$this->prePersist($event);
Expand Down
Loading

0 comments on commit 9298c93

Please sign in to comment.