<?php
namespace App\Command;
use App\Entity\Gos\ProductVariant;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class VariantsMakeGiftableCommand extends Command
{
private $em;
private $countriesRequired = ['chile', 'peru', 'mexico', 'paraguay', 'argentina', 'uruguay', 'panama', 'ecuador', 'spain', 'colombia'];
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
parent::__construct();
}
protected function configure(): void
{
$this
->setName('variants:make-giftable')
->setDescription('Makes active UniqSkills product variants giftable');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->comment('Making product variants giftable...');
$result = $this->makeVariantsGiftable();
$io->success("Success! ${result} product variants made giftable");
return Command::SUCCESS;
}
private function makeVariantsGiftable(): int
{
$productVariants = $this->em->getRepository(ProductVariant::class)
->findAllEligibleToMakeGiftable($this->countriesRequired);
foreach ($productVariants as $productVariant)
{
if ($productVariant->isActive())
{
$productVariant->setIsGiftable(true);
}
}
$this->em->flush();
return count($productVariants);
}
}