PHP Interface Sonata\Component\Product\ProductProviderInterface

Show file Open project: sonata-project/ecommerce Interface Usage Examples

Public Methods

Method Description
basketAddProduct ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Product\ProductInterface $product, Sonata\Component\Basket\BasketElementInterface $newBasketElement ) return true if the basket element is still valid.
basketMergeProduct ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Product\ProductInterface $product, Sonata\Component\Basket\BasketElementInterface $newBasketElement ) 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, boolean $isVariation = false )
buildForm ( Symfony\Component\Form\FormBuilderInterface $builder, array $options, boolean $isVariation = false ) Build form by adding provider fields.
calculatePrice ( Sonata\Component\Product\ProductInterface $product, Sonata\Component\Currency\CurrencyInterface $currency, boolean $vat = false, integer $quantity = 1 ) : float Calculate the product price depending on the currency.
configureShowFields ( Sonata\AdminBundle\Show\ShowMapper $showMapper )
createBasketElement ( Sonata\Component\Product\ProductInterface $product = null, array $options = [] ) : Sonata\Component\Basket\BasketElementInterface
createVariation ( Sonata\Component\Product\ProductInterface $product, boolean $copyDependencies = true ) : Sonata\Component\Product\ProductInterface Creates a variation from a given Product and its dependencies.
defineAddBasketForm ( Sonata\Component\Product\ProductInterface $product, FormBuilder $formBuilder, boolean $showQuantity = true, array $options = [] )
defineBasketElementForm ( Sonata\Component\Basket\BasketElementInterface $basketElement, FormBuilder $formBuilder, array $options = [] )
getBaseControllerName ( ) : string
getBasketElementManager ( ) : Sonata\Component\Basket\BasketElementManagerInterface
getCheapestEnabledVariation ( Sonata\Component\Product\ProductInterface $product ) : null | Sonata\Component\Product\ProductInterface Fetch the cheapest variation if provided/existing.
getEnabledVariations ( Sonata\Component\Product\ProductInterface $product ) : ArrayCollection Return the list of enabled product variations.
getFilters ( ) : mixed Gets the fields on which the product might be filtered in the catalog view.
getProductCategoryManager ( ) : Sonata\Component\Product\ProductCategoryManagerInterface
getProductCollectionManager ( ) : Sonata\Component\Product\ProductCollectionManagerInterface
getStockAvailable ( Sonata\Component\Product\ProductInterface $product ) : integer return the stock available for the current product.
getVariatedProperties ( Sonata\Component\Product\ProductInterface $product, array $fields = [] ) : array Gets the properties values of $product amongst variation fields or $fields if set.
getVariation ( Sonata\Component\Product\ProductInterface $product, array $choices = [] ) Gets the variation matching $choices from master product $product.
getVariationsChoices ( Sonata\Component\Product\ProductInterface $product, array $fields = [] ) : array Gets the possible values for $fields (or variation fields if not set).
hasEnabledVariations ( Sonata\Component\Product\ProductInterface $product ) : boolean Return true if Product has enabled variation(s).
hasVariations ( Sonata\Component\Product\ProductInterface $product ) : boolean Check if the product has variations.
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
setBasketElementManager ( Sonata\Component\Basket\BasketElementManagerInterface $basketElementManager )
setProductCategoryManager ( Sonata\Component\Product\ProductCategoryManagerInterface $productCategoryManager )
setProductCollectionManager ( Sonata\Component\Product\ProductCollectionManagerInterface $productCollectionManager )
synchronizeVariations ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null ) Synchronizes all parent Product data to its variations (or a single one if $targetVariation is specified).
synchronizeVariationsCategories ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null ) Synchronizes parent Product categories to its variations (or a single one if $targetVariation is specified).
synchronizeVariationsCollections ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null ) Synchronizes parent Product collections to its variations (or a single one if $targetVariation is specified).
synchronizeVariationsDeliveries ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null ) Synchronizes parent Product deliveries to its variations (or a single one if $targetVariation is specified).
synchronizeVariationsPackages ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null ) Synchronizes parent Product packages to its variations (or a single one if $targetVariation is specified).
synchronizeVariationsProduct ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null ) Synchronizes parent Product data to its variations (or a single one if $targetVariation is specified).
updateComputationPricesFields ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Basket\BasketElementInterface $basketElement, Sonata\Component\Product\ProductInterface $product ) Updates basket element different prices computation fields values.
updateStock ( Sonata\Component\Product\ProductInterface | integer $product, Sonata\Component\Product\ProductManagerInterface $productManager, integer $diff ) Update the stock value of a given Product id.
validateFormBasketElement ( Sonata\CoreBundle\Validator\ErrorElement $errorElement, Sonata\Component\Basket\BasketElementInterface $basketElement, Sonata\Component\Basket\BasketInterface $basket ) return an array of errors if any, you can also manipulate the basketElement if require please not you always work with a clone version of the basketElement.

Method Details

basketAddProduct() public method

return true if the basket element is still valid.
public basketAddProduct ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Product\ProductInterface $product, Sonata\Component\Basket\BasketElementInterface $newBasketElement )
$basket Sonata\Component\Basket\BasketInterface
$product Sonata\Component\Product\ProductInterface
$newBasketElement 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 )
$basket Sonata\Component\Basket\BasketInterface
$product Sonata\Component\Product\ProductInterface
$newBasketElement 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, boolean $isVariation = false )
$formMapper Sonata\AdminBundle\Form\FormMapper
$isVariation boolean

buildForm() public method

Build form by adding provider fields.
public buildForm ( Symfony\Component\Form\FormBuilderInterface $builder, array $options, boolean $isVariation = false )
$builder Symfony\Component\Form\FormBuilderInterface Symfony form builder
$options array An options array
$isVariation boolean Is the product a variation of a master product?

calculatePrice() public method

Calculate the product price depending on the currency.
public calculatePrice ( Sonata\Component\Product\ProductInterface $product, Sonata\Component\Currency\CurrencyInterface $currency, boolean $vat = false, integer $quantity = 1 ) : float
$product Sonata\Component\Product\ProductInterface A product instance
$currency Sonata\Component\Currency\CurrencyInterface A currency instance
$vat boolean Returns price including VAT?
$quantity integer Defaults to one
return float

configureShowFields() public method

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

createBasketElement() public method

public createBasketElement ( Sonata\Component\Product\ProductInterface $product = null, array $options = [] ) : Sonata\Component\Basket\BasketElementInterface
$product Sonata\Component\Product\ProductInterface
$options array
return Sonata\Component\Basket\BasketElementInterface

createVariation() public method

Creates a variation from a given Product and its dependencies.
public createVariation ( Sonata\Component\Product\ProductInterface $product, boolean $copyDependencies = true ) : Sonata\Component\Product\ProductInterface
$product Sonata\Component\Product\ProductInterface Product to duplicate
$copyDependencies boolean If false, duplicates only Product (without dependencies)
return Sonata\Component\Product\ProductInterface

defineAddBasketForm() public method

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

getBaseControllerName() public method

public getBaseControllerName ( ) : string
return string

getBasketElementManager() public method

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

getCheapestEnabledVariation() public method

Fetch the cheapest variation if provided/existing.
public getCheapestEnabledVariation ( Sonata\Component\Product\ProductInterface $product ) : null | Sonata\Component\Product\ProductInterface
$product Sonata\Component\Product\ProductInterface
return null | Sonata\Component\Product\ProductInterface

getEnabledVariations() public method

Return the list of enabled product variations.
public getEnabledVariations ( Sonata\Component\Product\ProductInterface $product ) : ArrayCollection
$product Sonata\Component\Product\ProductInterface
return Doctrine\Common\Collections\ArrayCollection

getFilters() public method

Gets the fields on which the product might be filtered in the catalog view.
public getFilters ( ) : mixed
return mixed

getProductCategoryManager() public method

public getProductCategoryManager ( ) : Sonata\Component\Product\ProductCategoryManagerInterface
return Sonata\Component\Product\ProductCategoryManagerInterface

getProductCollectionManager() public method

public getProductCollectionManager ( ) : Sonata\Component\Product\ProductCollectionManagerInterface
return Sonata\Component\Product\ProductCollectionManagerInterface

getStockAvailable() public method

return the stock available for the current product.
public getStockAvailable ( Sonata\Component\Product\ProductInterface $product ) : integer
$product Sonata\Component\Product\ProductInterface
return integer the stock available

getVariatedProperties() public method

Gets the properties values of $product amongst variation fields or $fields if set.
public getVariatedProperties ( Sonata\Component\Product\ProductInterface $product, array $fields = [] ) : array
$product Sonata\Component\Product\ProductInterface
$fields array
return array

getVariation() public method

Gets the variation matching $choices from master product $product.
public getVariation ( Sonata\Component\Product\ProductInterface $product, array $choices = [] )
$product Sonata\Component\Product\ProductInterface
$choices array

getVariationsChoices() public method

Gets the possible values for $fields (or variation fields if not set).
public getVariationsChoices ( Sonata\Component\Product\ProductInterface $product, array $fields = [] ) : array
$product Sonata\Component\Product\ProductInterface
$fields array
return array

hasEnabledVariations() public method

Return true if Product has enabled variation(s).
public hasEnabledVariations ( Sonata\Component\Product\ProductInterface $product ) : boolean
$product Sonata\Component\Product\ProductInterface
return boolean

hasVariations() public method

Check if the product has variations.
public hasVariations ( Sonata\Component\Product\ProductInterface $product ) : boolean
$product Sonata\Component\Product\ProductInterface
return boolean

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

setBasketElementManager() public method

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

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

synchronizeVariations() public method

Synchronizes all parent Product data to its variations (or a single one if $targetVariation is specified).
public synchronizeVariations ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface Parent Product
$variations Doctrine\Common\Collections\ArrayCollection Optional target variations to synchronize

synchronizeVariationsCategories() public method

Synchronizes parent Product categories to its variations (or a single one if $targetVariation is specified).
public synchronizeVariationsCategories ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface Parent Product
$variations Doctrine\Common\Collections\ArrayCollection Optional target variations to synchronize

synchronizeVariationsCollections() public method

Synchronizes parent Product collections to its variations (or a single one if $targetVariation is specified).
public synchronizeVariationsCollections ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface Parent Product
$variations Doctrine\Common\Collections\ArrayCollection Optional target variations to synchronize

synchronizeVariationsDeliveries() public method

Synchronizes parent Product deliveries to its variations (or a single one if $targetVariation is specified).
public synchronizeVariationsDeliveries ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface Parent Product
$variations Doctrine\Common\Collections\ArrayCollection Optional target variations to synchronize

synchronizeVariationsPackages() public method

Synchronizes parent Product packages to its variations (or a single one if $targetVariation is specified).
public synchronizeVariationsPackages ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface Parent Product
$variations Doctrine\Common\Collections\ArrayCollection Optional target variations to synchronize

synchronizeVariationsProduct() public method

Synchronizes parent Product data to its variations (or a single one if $targetVariation is specified).
public synchronizeVariationsProduct ( Sonata\Component\Product\ProductInterface $product, ArrayCollection $variations = null )
$product Sonata\Component\Product\ProductInterface Parent Product
$variations Doctrine\Common\Collections\ArrayCollection Optional target variations to synchronize

updateComputationPricesFields() public method

Updates basket element different prices computation fields values.
public updateComputationPricesFields ( Sonata\Component\Basket\BasketInterface $basket, Sonata\Component\Basket\BasketElementInterface $basketElement, Sonata\Component\Product\ProductInterface $product )
$basket Sonata\Component\Basket\BasketInterface A basket instance
$basketElement Sonata\Component\Basket\BasketElementInterface A basket element instance
$product Sonata\Component\Product\ProductInterface A product instance

updateStock() public method

Update the stock value of a given Product id.
public updateStock ( Sonata\Component\Product\ProductInterface | integer $product, Sonata\Component\Product\ProductManagerInterface $productManager, integer $diff )
$product Sonata\Component\Product\ProductInterface | integer
$productManager Sonata\Component\Product\ProductManagerInterface
$diff integer

validateFormBasketElement() public method

If the basket is valid it will then replace the one in session
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