getProvider() public method

public getProvider ( Sonata\Component\Product\ProductInterface | string $code ) : Sonata\Component\Product\ProductProviderInterface
$code Sonata\Component\Product\ProductInterface | string
return Sonata\Component\Product\ProductProviderInterface
Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $choices = $this->pool->getProvider($options['product'])->getVariationsChoices($options['product'], $options['fields']);
     foreach ($choices as $choiceTitle => $choiceValues) {
         $builder->add($choiceTitle, 'choice', array_merge(array('translation_domain' => 'SonataProductBundle'), $options['field_options'], array('label' => sprintf('form_%s', $choiceTitle), 'choices' => $choiceValues)));
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if ($options['provider_name']) {
         $provider = $this->productPool->getProvider($options['provider_name']);
         $provider->buildForm($builder, $options);
     }
 }
Ejemplo n.º 3
0
 /**
  * The validator asks each product repository to validate the related basket element.
  *
  * @param BasketInterface $basket
  * @param Constraint      $constraint
  */
 public function validate($basket, Constraint $constraint)
 {
     foreach ($basket->getBasketElements() as $pos => $basketElement) {
         // create a new ErrorElement object
         $errorElement = new ErrorElement($basket, $this->constraintValidatorFactory, $this->context, $this->context->getGroup());
         $errorElement->with('basketElements[' . $pos . ']');
         // validate the basket element through the related service provider
         $this->productPool->getProvider($basketElement->getProductCode())->validateFormBasketElement($errorElement, $basketElement, $basket);
     }
     if (count($this->context->getViolations()) > 0) {
         $this->context->addViolationAt('basketElements', $constraint->message);
     }
 }
Ejemplo n.º 4
0
 /**
  * Returns a "add to basket" form for a specified product.
  *
  * @param ProductInterface $product A product instance
  *
  * @return FormView
  */
 public function getFormAddBasket(ProductInterface $product)
 {
     $formBuilder = $this->formFactory->createNamedBuilder('add_basket', 'form', null, array('data_class' => $this->basketElementClass, 'csrf_protection' => false));
     $this->productPool->getProvider($product)->defineAddBasketForm($product, $formBuilder, false);
     $form = $formBuilder->getForm()->createView();
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function execute(BlockContextInterface $blockContext, Response $response = null)
 {
     $product = $blockContext->getSetting('product');
     if (null === $product) {
         return $this->renderResponse($blockContext->getTemplate(), array('context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'choices' => array(), 'form' => null), $response);
     }
     $fields = $blockContext->getSetting('variations_properties');
     $choices = $this->pool->getProvider($product)->getVariationsChoices($product, $fields);
     $accessor = PropertyAccess::createPropertyAccessor();
     $currentValues = array();
     foreach ($choices as $field => $values) {
         $currentValues[$field] = array_search($accessor->getValue($product, $field), $values);
     }
     $form = $this->formFactory->createBuilder('sonata_product_variation_choices', $currentValues, array('field_options' => $blockContext->getSetting('form_field_options'), 'product' => $product, 'fields' => $fields))->getForm();
     $params = array('context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'choices' => $choices, 'form' => $form->createView());
     return $this->renderResponse($blockContext->getTemplate(), $params, $response);
 }
 /**
  * Get the ProductProvider of the given Product.
  *
  * @param string $productType
  *
  * @return ProductProviderInterface
  */
 protected function getProductProvider($productType)
 {
     return $this->productPool->getProvider($productType);
 }
Ejemplo n.º 7
0
 /**
  * Return the available stock of the product.
  *
  * @param ProductInterface $product  A product instance
  *
  * @return int
  */
 public function getProductStock(ProductInterface $product)
 {
     return $this->productPool->getProvider($product)->getStockAvailable($product);
 }