Skip to content

Commit

Permalink
Adding attribute configuration for Entities (#77)
Browse files Browse the repository at this point in the history
* Attributes

* Don't remove XML mappings
  • Loading branch information
mamazu authored Dec 29, 2023
1 parent d781106 commit 5fd8b30
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Entity/TierPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,40 @@

namespace Brille24\SyliusTierPricePlugin\Entity;

use Brille24\SyliusTierPricePlugin\Repository\TierPriceRepository;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\UniqueConstraint;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Customer\Model\CustomerGroupInterface;

#[Entity(repositoryClass:TierPriceRepository::class)]

Check failure on line 27 in src/Entity/TierPrice.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.11.2, PHP 8.1, Symfony 5.4.*, MySQL 8.0

Parameter $repositoryClass of attribute class Doctrine\ORM\Mapping\Entity constructor expects class-string<Doctrine\ORM\EntityRepository<T of object>>|null, 'Brille24\\SyliusTierPricePlugin\\Repository\\TierPriceRepository' given.

Check failure on line 27 in src/Entity/TierPrice.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.11.2, PHP 8.1, Symfony 5.4.*, MySQL 8.0

Parameter $repositoryClass of attribute class Doctrine\ORM\Mapping\Entity constructor expects class-string<Doctrine\ORM\EntityRepository<T of object>>|null, 'Brille24\\SyliusTierPricePlugin\\Repository\\TierPriceRepository' given.

Check failure on line 27 in src/Entity/TierPrice.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.11.2, PHP 8.1, Symfony 5.4.*, MySQL 8.0

Parameter $repositoryClass of attribute class Doctrine\ORM\Mapping\Entity constructor expects class-string<Doctrine\ORM\EntityRepository<T of object>>|null, 'Brille24\\SyliusTierPricePlugin\\Repository\\TierPriceRepository' given.

Check failure on line 27 in src/Entity/TierPrice.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.11.2, PHP 8.1, Symfony 5.4.*, MySQL 8.0

Parameter $repositoryClass of attribute class Doctrine\ORM\Mapping\Entity constructor expects class-string<Doctrine\ORM\EntityRepository<T of object>>|null, 'Brille24\\SyliusTierPricePlugin\\Repository\\TierPriceRepository' given.
#[Table(name: 'brille24_tierprice')]
#[UniqueConstraint(name: 'no_duplicate_prices', columns: ['qty','channel_id','product_variant_id','customer_group_id'])]
class TierPrice implements TierPriceInterface
{
/** @var int */
#[Id, Column(type: 'integer')]
private $id;

#[ManyToOne(targetEntity: ChannelInterface::class)]
private ?ChannelInterface $channel = null;

#[ManyToOne(targetEntity: ProductVariantInterface::class, inversedBy: 'tierPrices')]
private ProductVariantInterface $productVariant;

#[ManyToOne(targetEntity: CustomerGroupInterface::class, inversedBy: 'customerGroup')]
private ?CustomerGroupInterface $customerGroup = null;

public function __construct(private int $qty = 0, private int $price = 0)
{
public function __construct(
#[Column(type: 'integer')]
private int $qty = 0,
#[Column(type: 'integer')]
private int $price = 0
) {
}

public function getId(): ?int
Expand Down
5 changes: 5 additions & 0 deletions src/Traits/TierPriceableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
namespace Brille24\SyliusTierPricePlugin\Traits;

use Brille24\SyliusTierPricePlugin\Entity\ProductVariant;
use Brille24\SyliusTierPricePlugin\Entity\TierPrice;
use Brille24\SyliusTierPricePlugin\Entity\TierPriceInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OrderBy;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
Expand All @@ -37,6 +40,8 @@ public function initTierPriceableTrait(): void
}

/** @var ArrayCollection<int, TierPriceInterface> */
#[OneToMany(TierPrice::class, mappedBy: "productVariant", orphanRemoval: true, cascade: ['all'])]
#[OrderBy(['customerGroup' => 'ASC', 'qty' => 'ASC'])]
protected $tierPrices;

/**
Expand Down

0 comments on commit 5fd8b30

Please sign in to comment.