Skip to content

Commit

Permalink
Customise Product as packable or not
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed May 15, 2024
1 parent afe157e commit 8e5a513
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Entity/Product/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@
use Sylius\Component\Core\Model\Product as BaseProduct;
use Sylius\Component\Product\Model\ProductTranslationInterface;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_product")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_product')]
class Product extends BaseProduct
{
#[ORM\Column(type: 'boolean', options: ['default' => false])]
private bool $packable = false;

public function isPackable(): bool
{
return $this->packable;
}

public function setPackable(bool $packable): void
{
$this->packable = $packable;
}

protected function createTranslation(): ProductTranslationInterface
{
return new ProductTranslation();
Expand Down
25 changes: 25 additions & 0 deletions src/Form/Extension/ProductTypeExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Form\Extension;

use Sylius\Bundle\ProductBundle\Form\Type\ProductType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\FormBuilderInterface;

final class ProductTypeExtension extends AbstractTypeExtension
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('packable', CheckboxType::class)
;
}

public static function getExtendedTypes(): iterable
{
yield ProductType::class;
}
}
31 changes: 31 additions & 0 deletions src/Migrations/Version20240508114451.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240508114451 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 ADD packable TINYINT(1) DEFAULT 0 NOT 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 DROP packable');
}
}
69 changes: 69 additions & 0 deletions templates/bundles/SyliusAdminBundle/Product/Tab/_details.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% from '@SyliusAdmin/Macro/translationForm.html.twig' import translationFormWithSlug %}

<div class="ui active tab" data-tab="details">
<h3 class="ui top attached header">{{ 'sylius.ui.details'|trans }}</h3>

<div class="ui attached segment">
{{ form_errors(form) }}

<div class="ui two column stackable grid">
<div class="column">
<div class="ui segment">
{{ form_row(form.code) }}
{{ form_row(form.enabled) }}
{% if product.simple %}
{{ form_row(form.variant.shippingRequired) }}
{% else %}
{{ form_row(form.options, {'remote_url': path('sylius_admin_ajax_product_options_by_phrase'), 'load_edit_url': path('sylius_admin_ajax_find_product_options')}) }}
{{ form_row(form.variantSelectionMethod) }}
{% endif %}

{# Nothing to see here. #}
<div class="ui hidden element">
{% if product.simple %}
{{ form_row(form.variant.translations) }}
{{ form_row(form.variantSelectionMethod) }}
{% endif %}
</div>
</div>
</div>
<div class="column">
{{ form_row(form.channels) }}
{{ form_row(form.packable) }}
</div>
</div>
{% if product.simple %}
<div class="ui one column stackable grid">
<div class="column">
<h4 class="ui dividing header">{{ 'sylius.ui.pricing'|trans }}</h4>
{% include "@SyliusAdmin/Product/_channel_pricing.html.twig" with { product: product, variantForm: form.variant } only %}
</div>
</div>
{% endif %}
<div class="ui hidden divider"></div>
{{ translationFormWithSlug(form.translations, '@SyliusAdmin/Product/_slugField.html.twig', product) }}
{% if product.simple %}
<div class="ui hidden divider"></div>
<div class="ui two column stackable grid">
<div class="column">
<h4 class="ui top attached header">{{ 'sylius.ui.shipping'|trans }}</h4>
<div class="ui attached segment">
{{ form_row(form.variant.shippingCategory) }}
{{ form_row(form.variant.width) }}
{{ form_row(form.variant.height) }}
{{ form_row(form.variant.depth) }}
{{ form_row(form.variant.weight) }}
</div>
</div>
<div class="column">
<h4 class="ui top attached header">{{ 'sylius.ui.taxes'|trans }}</h4>
<div class="ui attached segment">
{{ form_row(form.variant.taxCategory) }}
</div>
</div>
</div>
{% endif %}

{{ sylius_template_event(['sylius.admin.product.' ~ action ~ '.tab_details', 'sylius.admin.product.tab_details'], {'form': form}) }}
</div>
</div>

0 comments on commit 8e5a513

Please sign in to comment.