<?phpdeclare(strict_types=1);namespace App\Entity\Product;use App\Entity\Customer\CustomerInterface;use App\Entity\ProductOptionValue;use App\Entity\Trait\TierPriceableTrait;use Brille24\SyliusTierPricePlugin\Entity\ProductVariantInterface;use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant;use Brille24\SyliusTierPricePlugin\Entity\TierPriceInterface;use Doctrine\ORM\Mapping as ORM;use Sylius\Component\Core\Model\ChannelInterface;use Sylius\Component\Product\Model\ProductVariantTranslationInterface;/** * @ORM\Entity * @ORM\Table(name="sylius_product_variant") */class ProductVariant extends BaseProductVariant implements ProductVarinatInterface, ProductVariantInterface{ use TierPriceableTrait; public function __construct() { parent::__construct(); $this->initTierPriceableTrait(); } protected function createTranslation(): ProductVariantTranslationInterface { return new ProductVariantTranslation(); } public function getMainImage() { foreach ($this->images as $key => $value) { if ($value->getType === 'main') { return $value; } } return null; } public function getTierPriceByQty(int $qty): ?TierPriceInterface { foreach ($this->getTierPrices() as $item) { if ($item->getQty() === $qty) { return $item; } } return null; } public function getMinQtyFromTierprice($channel): ?int { $min = null; foreach ($this->getTierPricesForChannel($channel) as $tierprice) { if ($tierprice->getQty() < $min || $min === null) { $min = $tierprice->getQty(); } } return $min; } public function getBreakpoints(ChannelInterface $channel, ?CustomerInterface $customer = null): array { $out = []; $tierPrices = $this->getTierPricesForChannel($channel, $customer = null); $ovs = $this->getOptionValues();// if (count($ovs) === 1) { foreach ($tierPrices as $tierPrice) { $qty = $tierPrice->getQty(); $out[$qty] = $qty; }// } if (is_array($out)) { ksort($out); } return $out; } public function getOptionValueByCode(string $code) { foreach ($this->getOptionValues() as $optionValue) { if ($optionValue->getCode() === $code) { return $optionValue; } } return null; } public function getOptionValueByOptionCode(string $code) { foreach ($this->getOptionValues() as $optionValue) { if ($optionValue->getOption()->getCode() === $code) { return $optionValue; } } return null; } public function __toString(): string { return $this->name ?? 'Variant #' . $this->getId(); // Provide a fallback }}