/** * {@inheritdoc} */ public function isEligible(ShippingSubjectInterface $subject, ShippingMethodInterface $method) { if (!$this->isCategoryEligible($subject, $method)) { return false; } foreach ($method->getRules() as $rule) { $checker = $this->registry->getChecker($rule->getType()); if (!$checker->isEligible($subject, $rule->getConfiguration())) { return false; } } return true; }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventSubscriber(new BuildShippingMethodFormListener($this->calculatorRegistry, $builder->getFormFactory()))->add('translations', 'a2lix_translationsForms', array('form_type' => 'sylius_shipping_method_translation', 'label' => 'sylius.form.shipping_method.name'))->add('enabled', 'checkbox', array('required' => false, 'label' => 'sylius.form.shipping_method.enabled'))->add('category', 'sylius_shipping_category_choice', array('required' => false, 'label' => 'sylius.form.shipping_method.category'))->add('categoryRequirement', 'choice', array('choices' => ShippingMethod::getCategoryRequirementLabels(), 'multiple' => false, 'expanded' => true, 'label' => 'sylius.form.shipping_method.category_requirement'))->add('calculator', 'sylius_shipping_calculator_choice', array('label' => 'sylius.form.shipping_method.calculator')); $prototypes = array(); $prototypes['rules'] = array(); foreach ($this->checkerRegistry->getCheckers() as $type => $checker) { $prototypes['rules'][$type] = $builder->create('__name__', $checker->getConfigurationFormType())->getForm(); } $prototypes['calculators'] = array(); foreach ($this->calculatorRegistry->getCalculators() as $name => $calculator) { if (!$calculator->isConfigurable()) { continue; } $prototypes['calculators'][$name] = $builder->create('configuration', $calculator->getConfigurationFormType())->getForm(); } $builder->setAttribute('prototypes', $prototypes); }
/** * @param FormInterface $form * @param $ruleType * @param array $data */ protected function addConfigurationFields(FormInterface $form, $ruleType, array $data = array()) { $checker = $this->checkerRegistry->getChecker($ruleType); $configurationField = $this->factory->createNamed('configuration', $checker->getConfigurationFormType(), $data, array('auto_initialize' => false)); $form->add($configurationField); }