-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from monsieurbiz/feature/product-preparation-d…
…elay Add preparation delay in product variants
- Loading branch information
Showing
14 changed files
with
330 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Shipping Slot plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusShippingSlotPlugin\Entity; | ||
|
||
use Sylius\Component\Core\Model\ProductVariantInterface as SyliusProductVariantInterface; | ||
|
||
interface ProductVariantInterface extends SyliusProductVariantInterface | ||
{ | ||
public function getPreparationDelay(): ?int; | ||
|
||
public function setPreparationDelay(?int $preparationDelay): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Shipping Slot plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusShippingSlotPlugin\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
trait ProductVariantTrait | ||
{ | ||
/** | ||
* @ORM\Column(name="preparation_delay", type="integer", nullable=true) | ||
*/ | ||
private ?int $preparationDelay = null; | ||
|
||
public function getPreparationDelay(): ?int | ||
{ | ||
return $this->preparationDelay; | ||
} | ||
|
||
public function setPreparationDelay(?int $preparationDelay): void | ||
{ | ||
$this->preparationDelay = $preparationDelay; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Shipping Slot plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusShippingSlotPlugin\Fixture; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use MonsieurBiz\SyliusShippingSlotPlugin\Entity\ProductVariantInterface; | ||
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture; | ||
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface; | ||
use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
|
||
final class ProductVariantShippingSlotFixture extends AbstractFixture implements FixtureInterface | ||
{ | ||
private ProductVariantRepositoryInterface $productVariantRepository; | ||
private EntityManagerInterface $productVariantManager; | ||
|
||
public function __construct( | ||
ProductVariantRepositoryInterface $productVariantRepository, | ||
EntityManagerInterface $productVariantManager | ||
) { | ||
$this->productVariantRepository = $productVariantRepository; | ||
$this->productVariantManager = $productVariantManager; | ||
} | ||
|
||
/** | ||
* @param array $options | ||
*/ | ||
public function load(array $options): void | ||
{ | ||
foreach ($options['product_variants'] ?? [] as $option) { | ||
/** @var ProductVariantInterface $productVariant */ | ||
if (null === ($productVariant = $this->productVariantRepository->findOneBy(['code' => $option['code'] ?? '']))) { | ||
continue; | ||
} | ||
|
||
$productVariant->setPreparationDelay($option['preparationDelay'] ?? null); | ||
$this->productVariantManager->persist($productVariant); | ||
} | ||
|
||
$this->productVariantManager->flush(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'monsieurbiz_shipping_slot_product_variant'; | ||
} | ||
|
||
/** | ||
* @param ArrayNodeDefinition $optionsNode | ||
*/ | ||
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void | ||
{ | ||
/** @phpstan-ignore-next-line */ | ||
$optionsNode | ||
->children() | ||
->arrayNode('product_variants') | ||
->arrayPrototype() | ||
->children() | ||
->scalarNode('code')->cannotBeEmpty()->end() | ||
->integerNode('preparationDelay')->end() | ||
->end() | ||
->end() | ||
->end() | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Shipping Slot plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusShippingSlotPlugin\Form\Extension; | ||
|
||
use Sylius\Bundle\ProductBundle\Form\Type\ProductVariantType; | ||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\Extension\Core\Type\IntegerType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class ProductVariantTypeExtension extends AbstractTypeExtension | ||
{ | ||
public static function getExtendedTypes(): iterable | ||
{ | ||
return [ProductVariantType::class]; | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('preparationDelay', IntegerType::class, [ | ||
'required' => false, | ||
'label' => 'monsieurbiz_shipping_slot.ui.form.preparation_delay', | ||
'constraints' => [ | ||
new Assert\PositiveOrZero(), | ||
], | ||
]) | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Shipping Slot plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusShippingSlotPlugin\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20210813115752 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE sylius_product_variant ADD preparation_delay INT DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE sylius_product_variant DROP preparation_delay'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/Resources/views/Admin/Form/Product/preparation_delay.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% if form.vars.value is defined and form.vars.value.simple %} | ||
<div class="ui segment"> | ||
<h4 class="ui dividing header">{{ 'monsieurbiz_shipping_slot.ui.shipping_slot_config'|trans }}</h4> | ||
<div id="shipping_slot_config"> | ||
{{ form_row(form.variant.preparationDelay) }} | ||
</div> | ||
</div> | ||
{% endif %} |
7 changes: 7 additions & 0 deletions
7
src/Resources/views/Admin/Form/ProductVariant/preparation_delay.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
<div class="ui segment"> | ||
<h4 class="ui dividing header">{{ 'monsieurbiz_shipping_slot.ui.shipping_slot_config'|trans }}</h4> | ||
<div id="shipping_slot_config"> | ||
{{ form_row(form.preparationDelay) }} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.