Skip to content

Commit

Permalink
Add channel to promotion form
Browse files Browse the repository at this point in the history
  • Loading branch information
kooliahmd committed Aug 17, 2017
1 parent 24afc34 commit 1142b31
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
26 changes: 23 additions & 3 deletions src/Entity/Promotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Sylius\Component\Resource\Model\CodeAwareInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Model\TimestampableTrait;
use Sylius\Component\Channel\Model\ChannelInterface;

class Promotion implements ResourceInterface, CodeAwareInterface
{
Expand Down Expand Up @@ -99,15 +100,34 @@ public function getEndsAt()
return $this->endsAt;
}

/**
* @return \Sylius\Component\Core\Model\ChannelPricingInterface[]
*/

public function getChannels()
{
return $this->channels;
}


public function addChannel(ChannelInterface $channel)
{
if (!$this->hasChannel($channel)) {
$this->channels->add($channel);
}
}


public function removeChannel(ChannelInterface $channel)
{
if ($this->hasChannel($channel)) {
$this->channels->removeElement($channel);
}
}


public function hasChannel(ChannelInterface $channel)
{
return $this->channels->contains($channel);
}

/**
* @return mixed
*/
Expand Down
6 changes: 6 additions & 0 deletions src/Form/Type/PromotionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType;

final class PromotionType extends AbstractResourceType
{
Expand Down Expand Up @@ -53,6 +54,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'label' => 'sylius.form.promotion.actions',
'button_add_label' => 'sylius.form.promotion.add_action',
])
->add('channels', ChannelChoiceType::class, [
'multiple' => true,
'expanded' => true,
'label' => 'sylius.form.promotion.channels',
])
->addEventSubscriber(new AddCodeFormSubscriber());

}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
<div class="column">
{{ form_row(form.priority) }}
{#{{ form_row(form.channels) }}#}
{{ form_row(form.channels) }}
</div>
</div>
<h4 class="ui dividing header">{{ 'sylius.ui.start_date'|trans }} & {{ 'sylius.ui.end_date'|trans }}</h4>
Expand Down

0 comments on commit 1142b31

Please sign in to comment.