Skip to content
This repository has been archived by the owner on Nov 30, 2017. It is now read-only.

Update Product properties to attributes #297

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions bundles/SyliusProductBundle/attributes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Product Attributes
==================

Managing Attributes
-------------------

Managing attributes happens exactly the same way like products, you have ``sylius.repository.product_attribute`` and ``sylius.manager.product_attribute`` at your disposal.

Assigning attributes to product
-------------------------------

Value of specific Attribute for one of Products is defined through AttributeValue model, which holds the references to Product, Attribute pair and the value.
If you want to programatically set an attribute value on product, use the following code.

.. code-block:: php

<?php

public function myAction(Request $request)
{
$attributeRepository = $this->container->get('sylius.repository.product_attribute');
$attributeValueRepository = $this->container->get('sylius.repository.product_attribute_value');

$attribute = $attributeRepository->findOneBy(array('name' => 'T-Shirt Collection'));
$attributeValue = $attributeValueRepository->createNew();

$attributeValue
->setAttribute($attribute)
->setValue('Summer 2013')
;

$product->addAttribute($attributeValue);

$manager = $this->container->get('sylius.manager.product');

$manager->persist($product);
$manager->flush(); // Save changes in database.
}

This looks a bit tedious, doesn't it? There is a **ProductBuilder** service which simplifies the creation of products dramatically, you can learn about it in appropriate chapter.
40 changes: 0 additions & 40 deletions bundles/SyliusProductBundle/properties.rst

This file was deleted.