This version of product-bundle will only work with sulu version >= 1.3
.
If you use an older sulu version please use product-bundle version
~0.16
.
Add the following to composer.json
"sulu/product-bundle": "~0.16"
Add the following to your application kernel:
// Product bundle
new Sulu\Bundle\ProductBundle\SuluProductBundle(),
new Sulu\Bundle\ValidationBundle\SuluValidationBundle(),
Add the following to your admin/routing.yml
:
# Sulu Product Bundle
sulu_product:
resource: "@SuluProductBundle/Resources/config/routing.yml"
prefix: /admin/product
sulu_product_api:
type: rest
resource: "@SuluProductBundle/Resources/config/routing_api.yml"
prefix: /admin/api
Sample configuration:
sulu_route:
mappings:
Sulu\Bundle\ProductBundle\Entity\ProductTranslation:
generator: schema
options:
route_schema: /products/{object.getName()}
sulu_product:
category_root_key: ~
default_currency: 'EUR'
default_formatter_locale: 'en'
display_recurring_prices: true
fallback_locale: de
fixtures:
attributes:
- src/Acme/Bundle/ProductBundle/DataFixtures/attributes.xml
locales:
- de
- en
objects:
product:
model: Acme\Bundle\ProductBundle\Entity\Product
repository: Acme\Bundle\ProductBundle\Entity\ProductRepository
template: AcmeShopBundle:views:templates/productdetail.html.twig
Note: If you use Sulu 1.3.*
routing has to be defined as follows:
sulu_route:
mappings:
Sulu\Bundle\ProductBundle\Entity\ProductTranslation:
route_schema: /products/{object.getName()}
Multiple locales for managing products can be defined in the config. If non defined, 'en' is taken as default.
If the users language matches any of the given locales, that one is
displayed in the admin area. Otherwise the fallback_locale
parameter
is used.
You can define custom routes by defining the sulu_route.mappings
parameter for ProductTranslation
entity.
Then you can specify the sulu_product.template
parameter to define
which template is shown when route is called.
To update routes for existing products, simply call
var/console sulu:route:update SuluProductBundle:ProductTranslation --batch-size 1
When creating a new product translation a new route is created. You then can change the route's path in the content tab.
The following properties are available when defining a route:
object
(ProductTranslation)product
(Api/Product) and of coursetranslator
The property recurring prices can be disabled via parameter
display_recurring_prices
. This option hides the UI elements for
recurring prices.
If you'd like to overwrite the sulu product entity you simply need to
set the objects.product
parameters.
For shop purposes template
can be used to define the template for
displaying product details.
You can write multiple attribute fixture files and define the path of your xmls in your config (as seen in the example above)
<attributes>
<attribute>
<key>example.key</key>
<type>1</type>
<names>
<name locale="en">English Attribute</name>
<name locale="de">German Attribute</name>
</names>
<values>
<value>
<name locale="de">German Value 1</name>
<name locale="en">English Value 1</name>
</value>
<value>
<name locale="de">German Value 2</name>
<name locale="en">English Value 2</name>
</value>
</values>
</attribute>
</attributes>
<property name="product" type="product" mandatory="true">
<meta>
<title lang="de">Produkt</title>
<title lang="en">Product</title>
</meta>
</property>
The following api's have been documented: Product Addon Api Product Variant Api
The sulu product developer documentation can be found here: Developer Documentation