Skip to content

Commit

Permalink
Now the database functionality works again
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Dec 9, 2024
1 parent d24e75e commit 0aeb991
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 254 deletions.
46 changes: 0 additions & 46 deletions src/EventListener/AddChannelPricingIndicesSubscriber.php

This file was deleted.

78 changes: 0 additions & 78 deletions src/EventListener/AddTimestampableIndicesSubscriber.php

This file was deleted.

21 changes: 1 addition & 20 deletions src/Model/ChannelPricingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,13 @@
namespace Setono\SyliusCatalogPromotionPlugin\Model;

use Sylius\Component\Core\Model\ChannelPricingInterface as BaseChannelPricingInterface;
use Sylius\Component\Resource\Model\TimestampableInterface;

interface ChannelPricingInterface extends BaseChannelPricingInterface, TimestampableInterface
interface ChannelPricingInterface extends BaseChannelPricingInterface
{
public function hasDiscount(): bool;

public function getDiscountAmount(): ?int;

/**
* If $asInteger is true it returns the discount rounded to the nearest whole number
*/
public function getDisplayableDiscount(bool $asInteger = false): ?float;

/**
* @return bool Returns true if this was discounted manually
*/
public function isManuallyDiscounted(): bool;

/**
* todo we need to update this via the resource controller events
*/
public function setManuallyDiscounted(bool $manuallyDiscounted): void;

public function getMultiplier(): float;

public function getBulkIdentifier(): ?string;

public function resetBulkIdentifier(): void;
}
81 changes: 1 addition & 80 deletions src/Model/ChannelPricingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,18 @@

namespace Setono\SyliusCatalogPromotionPlugin\Model;

use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Sylius\Component\Core\Model\ChannelPricing;
use Sylius\Component\Resource\Model\TimestampableTrait;

/**
* @mixin ChannelPricing
*/
trait ChannelPricingTrait
{
use TimestampableTrait;

/** @ORM\Column(type="boolean", options={"default": 0}) */
#[ORM\Column(type: 'boolean', options: ['default' => 0])]
protected bool $manuallyDiscounted = false;

/**
* @ORM\Column(type="decimal", precision=8, scale=4, options={"default": 1})
*
* @var float
*/
protected $multiplier = 1;

/** @ORM\Column(type="string", nullable=true) */
protected ?string $bulkIdentifier = null;

/**
* @ORM\Column(type="datetime", nullable=true)
*
* @Gedmo\Timestampable(on="create")
*
* @var DateTimeInterface|null
*/
protected $createdAt;

/**
* @ORM\Column(type="datetime", nullable=true)
*
* @Gedmo\Timestampable(on="update")
*
* @var DateTimeInterface|null
*/
protected $updatedAt;

public function hasDiscount(): bool
{
return null !== $this->getOriginalPrice() &&
null !== $this->getPrice() &&
$this->getOriginalPrice() > $this->getPrice()
;
}

public function getDiscountAmount(): ?int
{
if (!$this->hasDiscount()) {
return null;
}

return (int) $this->getOriginalPrice() - (int) $this->getPrice();
}

public function getDisplayableDiscount(bool $asInteger = false): ?float
{
if (!$this->hasDiscount()) {
return null;
}

$precision = $asInteger ? 0 : 2;

return round(100 - ($this->getPrice() / $this->getOriginalPrice() * 100), $precision);
}

public function isManuallyDiscounted(): bool
{
return $this->manuallyDiscounted;
Expand All @@ -84,24 +24,5 @@ public function isManuallyDiscounted(): bool
public function setManuallyDiscounted(bool $manuallyDiscounted): void
{
$this->manuallyDiscounted = $manuallyDiscounted;

// when a user is manually changing the prices, we don't want this channel pricing to be part of any bulk updates
$this->bulkIdentifier = null;
$this->multiplier = 1;
}

public function getMultiplier(): float
{
return $this->multiplier;
}

public function getBulkIdentifier(): ?string
{
return $this->bulkIdentifier;
}

public function resetBulkIdentifier(): void
{
$this->bulkIdentifier = null;
}
}
1 change: 0 additions & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<imports>
<import resource="services/event_listener.xml"/>
<import resource="services/factory.xml"/>
<import resource="services/fixture.xml"/>
<import resource="services/form.xml"/>
Expand Down
22 changes: 0 additions & 22 deletions src/Resources/config/services/event_listener.xml

This file was deleted.

4 changes: 2 additions & 2 deletions tests/Application/.env
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ APP_SECRET=EDITME
# Format described at https://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls
DATABASE_URL=mysql://[email protected]/acme_sylius_example_%kernel.environment%?serverVersion=5.7
DATABASE_URL=mysql://[email protected]/setono_sylius_catalog_promotion_%kernel.environment%?serverVersion=5.7
###< doctrine/doctrine-bundle ###

###> lexik/jwt-authentication-bundle ###
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
JWT_PASSPHRASE=acme_plugin_development
JWT_PASSPHRASE=setono_plugin_development
###< lexik/jwt-authentication-bundle ###

###> symfony/messenger ###
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Setono\SyliusCatalogPromotionPlugin\Tests\Application\Entity;
namespace Setono\SyliusCatalogPromotionPlugin\Tests\Application\Model;

use Doctrine\ORM\Mapping as ORM;
use Setono\SyliusCatalogPromotionPlugin\Model\ChannelPricingInterface as CatalogPromotionChannelPricingInterface;
Expand Down
7 changes: 7 additions & 0 deletions tests/Application/config/packages/_sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ sylius_shop:

sylius_api:
enabled: true


sylius_core:
resources:
channel_pricing:
classes:
model: Setono\SyliusCatalogPromotionPlugin\Tests\Application\Model\ChannelPricing
8 changes: 4 additions & 4 deletions tests/Application/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ doctrine:

url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_generate_proxy_classes: '%kernel.debug%'
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/Entity'
prefix: 'Setono\SyliusCatalogPromotionPlugin\Tests\Application\Entity'
dir: '%kernel.project_dir%/Model'
prefix: 'Setono\SyliusCatalogPromotionPlugin\Tests\Application\Model'
alias: App

0 comments on commit 0aeb991

Please sign in to comment.