0

分類法に基づいて新しいプロモーション ルールを作成する必要があります。たとえば、特定の分類法を持つすべての商品 (注文全体ではなく) を 10% オフにするなどです。

ドキュメントを読み、sylius に同梱されている 2 つのルール (アイテム数と注文合計) のコードを読みました。新しいルール チェッカーの作成を開始したため (現時点では true のみが返されます)、3 つ目のプロモーション ルール (「分類法」) が利用可能になりました。次に、その構成フォーム タイプを作成しました。ここでは、どの分類群がプロモーションをトリガーするかを選択できるように、構成されているすべての分類群をリストする選択リストを作成する必要があります。そして、ここで私は立ち往生しています。TaxonomyConfigurationType.php で試したこと (エンティティマネージャーを注入しました):

class TaxonomyConfigurationType extends AbstractType
{

protected $em;

public function __construct($em)
{
    $this->em = $em;
}

/**
 * {@inheritdoc}
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('theme', 'choice',
        array(
            'mapped' => false,
            'multiple' => false,
            'empty_value' => 'Choose a taxon',
            'choices' => $this->buildThemeChoices()
        )
    );
}

public function getName()
{
    return 'ecad_promotion_rule_taxonomy_configuration';
}

protected function buildThemeChoices()  {

    $choices = array();

    /// how can I access the taxonomy repo ?
    $r = $this->em->getRepository('BoutiqueBundle:Theme');
    $entities = $r->findAll();

    foreach ($entities as $e) {
        $choices[$e->getId()] = $e->getName();
    }

    return $choices;
}
}

分類群を翻訳するために Taxon クラス (BoutiqueBundle:Theme) をオーバーライドしたため、次のエラーが発生しました。

Class "Ecad\BoutiqueBundle\Entity\Theme" sub class of "Sylius\Bundle\TaxonomiesBundle\Model\Taxon" is not a valid entity or mapped super class.

これを達成するためのリードはありますか?最後に、製品が適格かどうかを確認できるように、分類群 ID を $configuration に保存する必要があります。

もう1つ、プロモーション対象商品を1つだけ指定することは可能ですか?

ありがとう

4

2 に答える 2

0

OK、私の間違い...

興味のある方のために、分類法に基づいた新しいプロモーション ルールを用意しました (「テーマ」と呼ばれる特定の語彙を使用したい) :

class TaxonomyConfigurationType extends AbstractType
{

protected $container;

public function __construct($container)
{
    $this->container = $container;
}

/**
 * {@inheritdoc}
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('taxons', 'choice', array(
        'label' => 'Thème',
        'choices' => $this->getThemeChoices(),
        'multiple' => true,
        'required' => true
    ));
}

public function getName()
{
    return 'promotion_rule_taxonomy_configuration';
}

protected function getThemeChoices() {

    $taxonomyRepository = $this->container->get('sylius.repository.taxonomy');
    $taxonomy = $taxonomyRepository->findOneByName('Thematique');
    $taxons = $taxonomy->getTaxonsAsList($taxonomy);

    $choices = array();
    foreach($taxons as $t) {
        $choices[$t->getId()] = $t->getName();
    }

    return $choices;
}
}

プロモーション ルールの編集時に、正しくシリアル化され、取得された 1 つ以上の分類群を選択できます。このサービスの引数として @service_container を渡す必要がありました。

これが SO で承認されている場合、次のステップ (ルールの確認、注文全体ではなく製品価格の調整...) についてこの投稿を更新します。

于 2014-06-13T08:42:29.670 に答える