PHP Class Sonata\ProductBundle\Model\BaseProductProvider

Inheritance: implements Sonata\Component\Product\ProductProviderInterface
Show file Open project: sonata-project/ecommerce Class Usage Examples

Protected Properties

Property Type Description
$basketElementManager Sonata\Component\Basket\BasketElementManagerInterface
$code string
$currencyPriceCalculator Sonata\Component\Currency\CurrencyPriceCalculatorInterface
$eventDispatcher Symfony\Component\EventDispatcher\EventDispatcherInterface
$options array
$orderElementClassName string
$productCategoryManager Sonata\Component\Product\ProductCategoryManagerInterface
$productCollectionManager Sonata\Component\Product\ProductCollectionManagerInterface
$serializer JMS\Serializer\SerializerInterface
$variationFields array

Public Methods

Method Description
__construct ( JMS\Serializer\SerializerInterface $serializer )
basketAddProduct ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Product\ProductInterface $product, Sonata\Component\Basket\BasketElementInterface $basketElement ) : boolean | Sonata\Component\Basket\BasketElementInterface Adds $basketElement related to $product to $basket.
basketMergeProduct ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Product\ProductInterface $product, Sonata\Component\Basket\BasketElementInterface $newBasketElement ) : boolean | Sonata\Component\Basket\BasketElementInterface Merge a product with another when the product is already present into the basket.
buildBasketElement ( Sonata\Component\Basket\BasketElementInterface $basketElement, Sonata\Component\Product\ProductInterface $product = null, array $options = [] )
buildCreateForm ( Sonata\AdminBundle\Form\FormMapper $formMapper )
buildEditForm ( Sonata\AdminBundle\Form\FormMapper $formMapper, $isVariation = false )
buildForm ( Symfony\Component\Form\FormBuilderInterface $builder, array $options, $isVariation = false )
calculatePrice ( Sonata\Component\Product\ProductInterface $product, Sonata\Component\Currency\CurrencyInterface $currency, $vat = false, $quantity = 1 )
configureShowFields ( Sonata\AdminBundle\Show\ShowMapper $showMapper )
createBasketElement ( Sonata\Component\Product\ProductInterface $product = null, array $options = [] ) (non-PHPdoc).
createOrderElement ( Sonata\Component\Basket\BasketElementInterface $basketElement, string $format = 'json' ) : Sonata\Component\Order\OrderElementInterface
createVariation ( Sonata\Component\Product\ProductInterface $product, $copyDependencies = true )
defineAddBasketForm ( Sonata\Component\Product\ProductInterface $product, FormBuilder $formBuilder, boolean $showQuantity = true, array $options = [] ) This function return the form used in the product view page.
defineBasketElementForm ( Sonata\Component\Basket\BasketElementInterface $basketElement, FormBuilder $formBuilder, array $options = [] )
findOneById ( integer $id ) : boolean
getBasketElementManager ( ) : Sonata\Component\Basket\BasketElementManagerInterface
getCheapestEnabledVariation ( Sonata\Component\Product\ProductInterface $product )
getCode ( ) : string
getCurrencyPriceCalculator ( ) : Sonata\Component\Currency\CurrencyPriceCalculatorInterface
getEnabledVariations ( Sonata\Component\Product\ProductInterface $product )
getEventDispatcher ( ) : Symfony\Component\EventDispatcher\EventDispatcherInterface
getFilters ( )
getOption ( string $name, mixed $default = null ) : array | null
getOptions ( ) : array
getProductCategoryManager ( )
getProductCollectionManager ( )
getProductFromRaw ( Sonata\Component\Order\OrderElementInterface $orderElement, string $type, string $format = 'json' ) : Sonata\Component\Product\ProductInterface
getRawProduct ( Sonata\Component\Product\ProductInterface $product, string $format = 'json' ) : array
getStockAvailable ( Sonata\Component\Product\ProductInterface $product )
getVariatedProperties ( Sonata\Component\Product\ProductInterface $product, array $fields = [] )
getVariation ( Sonata\Component\Product\ProductInterface $product, array $choices = [] )
getVariationFields ( ) : array
getVariationsChoices ( Sonata\Component\Product\ProductInterface $product, array $fields = [] )
hasEnabledVariations ( Sonata\Component\Product\ProductInterface $product )
hasVariationFields ( ) : boolean
hasVariations ( Sonata\Component\Product\ProductInterface $product )
isAddableToBasket ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Product\ProductInterface $product, array $options = [] ) : boolean Return true if the product can be added to the provided basket.
isValidBasketElement ( Sonata\Component\Basket\BasketElementInterface $basketElement ) : boolean
isVariateBy ( $name ) : boolean
reloadProduct ( Sonata\Component\Product\ProductInterface $product ) : Sonata\Component\Product\ProductInterface return a fresh product instance (so information are reloaded: enabled and stock .
setBasketElementManager ( Sonata\Component\Basket\BasketElementManagerInterface $basketElementManager )
setCode ( string $code )
setCurrencyPriceCalculator ( Sonata\Component\Currency\CurrencyPriceCalculatorInterface $currencyPriceCalculator )
setEventDispatcher ( Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher )
setOptions ( array $options = [] )
setOrderElementClassName ( string $orderElementClassName )
setProductCategoryManager ( Sonata\Component\Product\ProductCategoryManagerInterface $productCategoryManager )
setProductCollectionManager ( Sonata\Component\Product\ProductCollectionManagerInterface $productCollectionManager )
setVariationFields ( array $fields = [] )
synchronizeVariations ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
synchronizeVariationsCategories ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
synchronizeVariationsCollections ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
synchronizeVariationsDeliveries ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
synchronizeVariationsPackages ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
synchronizeVariationsProduct ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
updateComputationPricesFields ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Basket\BasketElementInterface $basketElement, Sonata\Component\Product\ProductInterface $product )
updateStock ( $product, Sonata\Component\Product\ProductManagerInterface $productManager, $diff )
validateFormBasketElement ( Sonata\CoreBundle\Validator\ErrorElement $errorElement, Sonata\Component\Basket\BasketElementInterface $basketElement, Sonata\Component\Basket\BasketInterface $basket )

Protected Methods

Method Description
getMergedFields ( array $fields ) : array Checks $fields if specified, returns variation fields otherwise.

Method Details

__construct() public method

public __construct ( JMS\Serializer\SerializerInterface $serializer )
$serializer JMS\Serializer\SerializerInterface

basketAddProduct() public method

Adds $basketElement related to $product to $basket.
public basketAddProduct ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Product\ProductInterface $product, Sonata\Component\Basket\BasketElementInterface $basketElement ) : boolean | Sonata\Component\Basket\BasketElementInterface
$basket Sonata\Component\Basket\BasketInterface
$product Sonata\Component\Product\ProductInterface
$basketElement Sonata\Component\Basket\BasketElementInterface
return boolean | Sonata\Component\Basket\BasketElementInterface

basketMergeProduct() public method

Merge a product with another when the product is already present into the basket.
public basketMergeProduct ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Product\ProductInterface $product, Sonata\Component\Basket\BasketElementInterface $newBasketElement ) : boolean | Sonata\Component\Basket\BasketElementInterface
$basket Sonata\Component\Basket\BasketInterface
$product Sonata\Component\Product\ProductInterface
$newBasketElement Sonata\Component\Basket\BasketElementInterface
return boolean | Sonata\Component\Basket\BasketElementInterface

buildBasketElement() public method

public buildBasketElement ( Sonata\Component\Basket\BasketElementInterface $basketElement, Sonata\Component\Product\ProductInterface $product = null, array $options = [] )
$basketElement Sonata\Component\Basket\BasketElementInterface
$product Sonata\Component\Product\ProductInterface
$options array

buildCreateForm() public method

public buildCreateForm ( Sonata\AdminBundle\Form\FormMapper $formMapper )
$formMapper Sonata\AdminBundle\Form\FormMapper

buildEditForm() public method

public buildEditForm ( Sonata\AdminBundle\Form\FormMapper $formMapper, $isVariation = false )
$formMapper Sonata\AdminBundle\Form\FormMapper

buildForm() public method

public buildForm ( Symfony\Component\Form\FormBuilderInterface $builder, array $options, $isVariation = false )
$builder Symfony\Component\Form\FormBuilderInterface
$options array

calculatePrice() public method

public calculatePrice ( Sonata\Component\Product\ProductInterface $product, Sonata\Component\Currency\CurrencyInterface $currency, $vat = false, $quantity = 1 )
$product Sonata\Component\Product\ProductInterface
$currency Sonata\Component\Currency\CurrencyInterface

configureShowFields() public method

public configureShowFields ( Sonata\AdminBundle\Show\ShowMapper $showMapper )
$showMapper Sonata\AdminBundle\Show\ShowMapper

createBasketElement() public method

(non-PHPdoc).
See also: Sonata\Component\Product\ProductProviderInterface::createBasketElement()
public createBasketElement ( Sonata\Component\Product\ProductInterface $product = null, array $options = [] )
$product Sonata\Component\Product\ProductInterface
$options array

createOrderElement() public method

public createOrderElement ( Sonata\Component\Basket\BasketElementInterface $basketElement, string $format = 'json' ) : Sonata\Component\Order\OrderElementInterface
$basketElement Sonata\Component\Basket\BasketElementInterface A basket element instance
$format string A format to obtain raw product
return Sonata\Component\Order\OrderElementInterface

createVariation() public method

public createVariation ( Sonata\Component\Product\ProductInterface $product, $copyDependencies = true )
$product Sonata\Component\Product\ProductInterface

defineAddBasketForm() public method

This function return the form used in the product view page.
public defineAddBasketForm ( Sonata\Component\Product\ProductInterface $product, FormBuilder $formBuilder, boolean $showQuantity = true, array $options = [] )
$product Sonata\Component\Product\ProductInterface A Sonata product instance
$formBuilder Symfony\Component\Form\FormBuilder Symfony form builder
$showQuantity boolean Specifies if quantity field will be displayed (default true)
$options array An options array

defineBasketElementForm() public method

public defineBasketElementForm ( Sonata\Component\Basket\BasketElementInterface $basketElement, FormBuilder $formBuilder, array $options = [] )
$basketElement Sonata\Component\Basket\BasketElementInterface
$formBuilder Symfony\Component\Form\FormBuilder
$options array

findOneById() public method

public findOneById ( integer $id ) : boolean
$id integer
return boolean

getBasketElementManager() public method

public getBasketElementManager ( ) : Sonata\Component\Basket\BasketElementManagerInterface
return Sonata\Component\Basket\BasketElementManagerInterface

getCheapestEnabledVariation() public method

public getCheapestEnabledVariation ( Sonata\Component\Product\ProductInterface $product )
$product Sonata\Component\Product\ProductInterface

getCode() public method

public getCode ( ) : string
return string

getCurrencyPriceCalculator() public method

public getCurrencyPriceCalculator ( ) : Sonata\Component\Currency\CurrencyPriceCalculatorInterface
return Sonata\Component\Currency\CurrencyPriceCalculatorInterface

getEnabledVariations() public method

public getEnabledVariations ( Sonata\Component\Product\ProductInterface $product )
$product Sonata\Component\Product\ProductInterface

getEventDispatcher() public method

public getEventDispatcher ( ) : Symfony\Component\EventDispatcher\EventDispatcherInterface
return Symfony\Component\EventDispatcher\EventDispatcherInterface

getFilters() public method

public getFilters ( )

getMergedFields() protected method

Checks $fields if specified, returns variation fields otherwise.
protected getMergedFields ( array $fields ) : array
$fields array
return array

getOption() public method

public getOption ( string $name, mixed $default = null ) : array | null
$name string
$default mixed
return array | null

getOptions() public method

public getOptions ( ) : array
return array

getProductCategoryManager() public method

getProductCollectionManager() public method

getProductFromRaw() public method

public getProductFromRaw ( Sonata\Component\Order\OrderElementInterface $orderElement, string $type, string $format = 'json' ) : Sonata\Component\Product\ProductInterface
$orderElement Sonata\Component\Order\OrderElementInterface
$type string
$format string
return Sonata\Component\Product\ProductInterface

getRawProduct() public method

public getRawProduct ( Sonata\Component\Product\ProductInterface $product, string $format = 'json' ) : array
$product Sonata\Component\Product\ProductInterface
$format string
return array

getStockAvailable() public method

public getStockAvailable ( Sonata\Component\Product\ProductInterface $product )
$product Sonata\Component\Product\ProductInterface

getVariatedProperties() public method

public getVariatedProperties ( Sonata\Component\Product\ProductInterface $product, array $fields = [] )
$product Sonata\Component\Product\ProductInterface
$fields array

getVariation() public method

public getVariation ( Sonata\Component\Product\ProductInterface $product, array $choices = [] )
$product Sonata\Component\Product\ProductInterface
$choices array

getVariationFields() public method

public getVariationFields ( ) : array
return array

getVariationsChoices() public method

public getVariationsChoices ( Sonata\Component\Product\ProductInterface $product, array $fields = [] )
$product Sonata\Component\Product\ProductInterface
$fields array

hasEnabledVariations() public method

public hasEnabledVariations ( Sonata\Component\Product\ProductInterface $product )
$product Sonata\Component\Product\ProductInterface

hasVariationFields() public method

public hasVariationFields ( ) : boolean
return boolean return true if the product haas some variation fields

hasVariations() public method

public hasVariations ( Sonata\Component\Product\ProductInterface $product )
$product Sonata\Component\Product\ProductInterface

isAddableToBasket() public method

Return true if the product can be added to the provided basket.
public isAddableToBasket ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Product\ProductInterface $product, array $options = [] ) : boolean
$basket Sonata\Component\Basket\BasketInterface
$product Sonata\Component\Product\ProductInterface
$options array
return boolean

isValidBasketElement() public method

public isValidBasketElement ( Sonata\Component\Basket\BasketElementInterface $basketElement ) : boolean
$basketElement Sonata\Component\Basket\BasketElementInterface
return boolean true if the basket element is still valid

isVariateBy() public method

public isVariateBy ( $name ) : boolean
$name
return boolean return true if the field $name is a variation

reloadProduct() public method

..).
public reloadProduct ( Sonata\Component\Product\ProductInterface $product ) : Sonata\Component\Product\ProductInterface
$product Sonata\Component\Product\ProductInterface
return Sonata\Component\Product\ProductInterface

setBasketElementManager() public method

public setBasketElementManager ( Sonata\Component\Basket\BasketElementManagerInterface $basketElementManager )
$basketElementManager Sonata\Component\Basket\BasketElementManagerInterface

setCode() public method

public setCode ( string $code )
$code string

setCurrencyPriceCalculator() public method

public setCurrencyPriceCalculator ( Sonata\Component\Currency\CurrencyPriceCalculatorInterface $currencyPriceCalculator )
$currencyPriceCalculator Sonata\Component\Currency\CurrencyPriceCalculatorInterface

setEventDispatcher() public method

public setEventDispatcher ( Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher )
$eventDispatcher Symfony\Component\EventDispatcher\EventDispatcherInterface

setOptions() public method

public setOptions ( array $options = [] )
$options array

setOrderElementClassName() public method

public setOrderElementClassName ( string $orderElementClassName )
$orderElementClassName string

setProductCategoryManager() public method

public setProductCategoryManager ( Sonata\Component\Product\ProductCategoryManagerInterface $productCategoryManager )
$productCategoryManager Sonata\Component\Product\ProductCategoryManagerInterface

setProductCollectionManager() public method

public setProductCollectionManager ( Sonata\Component\Product\ProductCollectionManagerInterface $productCollectionManager )
$productCollectionManager Sonata\Component\Product\ProductCollectionManagerInterface

setVariationFields() public method

public setVariationFields ( array $fields = [] )
$fields array

synchronizeVariations() public method

public synchronizeVariations ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface
$variations Doctrine\Common\Collections\ArrayCollection

synchronizeVariationsCategories() public method

public synchronizeVariationsCategories ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface
$variations Doctrine\Common\Collections\ArrayCollection

synchronizeVariationsCollections() public method

public synchronizeVariationsCollections ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface
$variations Doctrine\Common\Collections\ArrayCollection

synchronizeVariationsDeliveries() public method

public synchronizeVariationsDeliveries ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface
$variations Doctrine\Common\Collections\ArrayCollection

synchronizeVariationsPackages() public method

public synchronizeVariationsPackages ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface
$variations Doctrine\Common\Collections\ArrayCollection

synchronizeVariationsProduct() public method

public synchronizeVariationsProduct ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface
$variations Doctrine\Common\Collections\ArrayCollection

updateComputationPricesFields() public method

public updateComputationPricesFields ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Basket\BasketElementInterface $basketElement, Sonata\Component\Product\ProductInterface $product )
$basket Sonata\Component\Basket\BasketInterface
$basketElement Sonata\Component\Basket\BasketElementInterface
$product Sonata\Component\Product\ProductInterface

updateStock() public method

public updateStock ( $product, Sonata\Component\Product\ProductManagerInterface $productManager, $diff )
$productManager Sonata\Component\Product\ProductManagerInterface

validateFormBasketElement() public method

public validateFormBasketElement ( Sonata\CoreBundle\Validator\ErrorElement $errorElement, Sonata\Component\Basket\BasketElementInterface $basketElement, Sonata\Component\Basket\BasketInterface $basket )
$errorElement Sonata\CoreBundle\Validator\ErrorElement
$basketElement Sonata\Component\Basket\BasketElementInterface
$basket Sonata\Component\Basket\BasketInterface

Property Details

$basketElementManager protected property

protected BasketElementManagerInterface,Sonata\Component\Basket $basketElementManager
return Sonata\Component\Basket\BasketElementManagerInterface

$code protected property

protected string $code
return string

$currencyPriceCalculator protected property

protected CurrencyPriceCalculatorInterface,Sonata\Component\Currency $currencyPriceCalculator
return Sonata\Component\Currency\CurrencyPriceCalculatorInterface

$eventDispatcher protected property

protected EventDispatcherInterface,Symfony\Component\EventDispatcher $eventDispatcher
return Symfony\Component\EventDispatcher\EventDispatcherInterface

$options protected property

protected array $options
return array

$orderElementClassName protected property

protected string $orderElementClassName
return string

$productCategoryManager protected property

protected ProductCategoryManagerInterface,Sonata\Component\Product $productCategoryManager
return Sonata\Component\Product\ProductCategoryManagerInterface

$productCollectionManager protected property

protected ProductCollectionManagerInterface,Sonata\Component\Product $productCollectionManager
return Sonata\Component\Product\ProductCollectionManagerInterface

$serializer protected property

protected SerializerInterface,JMS\Serializer $serializer
return JMS\Serializer\SerializerInterface

$variationFields protected property

protected array $variationFields
return array