[Product] Merge Variation component to Product

This commit is contained in:
Kamil Kokot 2016-09-12 15:57:21 +02:00
parent 1012e29782
commit e866f08039
No known key found for this signature in database
GPG key ID: 7BD76F7054D93C89
91 changed files with 807 additions and 1600 deletions

View file

@ -64,7 +64,7 @@ UPGRADE
### Variation and VariationBundle
* Removed concept of master variant (removed ``$master`` flag from ``Sylius\Component\Variation\Model\Variant``), all usages of **master** variant has been, for now, replaced with **first** variant;
* Removed concept of master variant (removed ``$master`` flag from ``Sylius\Component\Product\Model\Variant``), all usages of **master** variant has been, for now, replaced with **first** variant;
* Renamed `presentation` to `name` (`VariantInterface`, `OptionValueInterface`)
### Payment

View file

@ -27,7 +27,6 @@ suites:
Taxation: { namespace: Sylius\Component\Taxation, psr4_prefix: Sylius\Component\Taxation, spec_path: src/Sylius/Component/Taxation, src_path: src/Sylius/Component/Taxation }
Taxonomy: { namespace: Sylius\Component\Taxonomy, psr4_prefix: Sylius\Component\Taxonomy, spec_path: src/Sylius/Component/Taxonomy, src_path: src/Sylius/Component/Taxonomy }
User: { namespace: Sylius\Component\User, psr4_prefix: Sylius\Component\User, spec_path: src/Sylius/Component/User, src_path: src/Sylius/Component/User }
Variation: { namespace: Sylius\Component\Variation, psr4_prefix: Sylius\Component\Variation, spec_path: src/Sylius/Component/Variation, src_path: src/Sylius/Component/Variation }
AssociationBundle: { namespace: Sylius\Bundle\AssociationBundle, psr4_prefix: Sylius\Bundle\AssociationBundle, spec_path: src/Sylius/Bundle/AssociationBundle, src_path: src/Sylius/Bundle/AssociationBundle }
AddressingBundle: { namespace: Sylius\Bundle\AddressingBundle, psr4_prefix: Sylius\Bundle\AddressingBundle, spec_path: src/Sylius/Bundle/AddressingBundle, src_path: src/Sylius/Bundle/AddressingBundle }

View file

@ -17,7 +17,7 @@ use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Variation\Resolver\VariantResolverInterface;
use Sylius\Component\Product\Resolver\VariantResolverInterface;
use Webmozart\Assert\Assert;
/**

View file

@ -37,7 +37,7 @@ use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Shipping\ShipmentTransitions;
use Sylius\Component\Customer\Model\CustomerInterface;
use Sylius\Component\User\Model\UserInterface;
use Sylius\Component\Variation\Resolver\VariantResolverInterface;
use Sylius\Component\Product\Resolver\VariantResolverInterface;
/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>

View file

@ -28,7 +28,7 @@ use Sylius\Component\Product\Model\OptionInterface;
use Sylius\Component\Product\Model\OptionValueInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
use Sylius\Component\Variation\Resolver\VariantResolverInterface;
use Sylius\Component\Product\Resolver\VariantResolverInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>

View file

@ -17,7 +17,7 @@ use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Product\Model\OptionInterface;
use Sylius\Component\Product\Model\OptionValueInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Variation\Repository\OptionRepositoryInterface;
use Sylius\Component\Product\Repository\OptionRepositoryInterface;
/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>

View file

@ -12,7 +12,7 @@
namespace Sylius\Behat\Context\Transform;
use Behat\Behat\Context\Context;
use Sylius\Component\Variation\Repository\OptionRepositoryInterface;
use Sylius\Component\Product\Repository\OptionRepositoryInterface;
use Webmozart\Assert\Assert;
/**

View file

@ -14,7 +14,7 @@ namespace Sylius\Bundle\CoreBundle\EventListener;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Uploader\ImageUploaderInterface;
use Sylius\Component\Variation\Resolver\VariantResolverInterface;
use Sylius\Component\Product\Resolver\VariantResolverInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Webmozart\Assert\Assert;

View file

@ -23,7 +23,7 @@ use Sylius\Component\Product\Model\AttributeInterface;
use Sylius\Component\Product\Model\AttributeValueInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Variation\Generator\VariantGeneratorInterface;
use Sylius\Component\Product\Generator\VariantGeneratorInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

View file

@ -20,7 +20,7 @@ use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Model\Taxon;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Core\Uploader\ImageUploaderInterface;
use Sylius\Component\Variation\Resolver\VariantResolverInterface;
use Sylius\Component\Product\Resolver\VariantResolverInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**

View file

@ -12,7 +12,7 @@
namespace Sylius\Bundle\ProductBundle\Form\EventSubscriber;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Variation\Generator\VariantGeneratorInterface;
use Sylius\Component\Product\Generator\VariantGeneratorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

View file

@ -12,7 +12,7 @@
namespace Sylius\Bundle\ProductBundle\Form\EventSubscriber;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Variation\Resolver\VariantResolverInterface;
use Sylius\Component\Product\Resolver\VariantResolverInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

View file

@ -15,7 +15,7 @@ use Sylius\Bundle\ProductBundle\Form\EventSubscriber\ProductOptionFieldSubscribe
use Sylius\Bundle\ProductBundle\Form\EventSubscriber\SimpleProductSubscriber;
use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Sylius\Component\Variation\Resolver\VariantResolverInterface;
use Sylius\Component\Product\Resolver\VariantResolverInterface;
use Symfony\Component\Form\FormBuilderInterface;
/**

View file

@ -17,7 +17,7 @@
http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="sylius.set_builder.cartesian.class">Sylius\Component\Variation\SetBuilder\CartesianSetBuilder</parameter>
<parameter key="sylius.set_builder.cartesian.class">Sylius\Component\Product\SetBuilder\CartesianSetBuilder</parameter>
<parameter key="sylius.validator.product.unique.class">Sylius\Bundle\ProductBundle\Validator\ProductUniqueValidator</parameter>

View file

@ -24,8 +24,8 @@ use Sylius\Component\Product\Model\OptionValueTranslation;
use Sylius\Component\Product\Model\OptionValueTranslationInterface;
use Sylius\Component\Resource\Factory\Factory;
use Sylius\Component\Resource\Factory\TranslatableFactory;
use Sylius\Component\Variation\Model\OptionTranslation;
use Sylius\Component\Variation\Model\OptionTranslationInterface;
use Sylius\Component\Product\Model\OptionTranslation;
use Sylius\Component\Product\Model\OptionTranslationInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

View file

@ -12,7 +12,7 @@
namespace Sylius\Bundle\VariationBundle\Doctrine\ORM;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Variation\Repository\OptionRepositoryInterface;
use Sylius\Component\Product\Repository\OptionRepositoryInterface;
/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>

View file

@ -11,7 +11,7 @@
namespace Sylius\Bundle\VariationBundle\Form\ChoiceList;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
/**
@ -20,9 +20,9 @@ use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
class VariantChoiceList extends ObjectChoiceList
{
/**
* @param VariableInterface $variable
* @param ProductInterface $variable
*/
public function __construct(VariableInterface $variable)
public function __construct(ProductInterface $variable)
{
parent::__construct($variable->getVariants(), 'name', [], null, 'id');
}

View file

@ -11,9 +11,9 @@
namespace Sylius\Bundle\VariationBundle\Form\DataTransformer;
use Sylius\Component\Variation\Model\OptionValueInterface;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Product\Model\OptionValueInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\VariantInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
@ -27,14 +27,14 @@ class VariantToCombinationTransformer implements DataTransformerInterface
/**
* Currently matching variable.
*
* @var VariableInterface
* @var ProductInterface
*/
protected $variable;
/**
* @param VariableInterface $variable
* @param ProductInterface $variable
*/
public function __construct(VariableInterface $variable)
public function __construct(ProductInterface $variable)
{
$this->variable = $variable;
}

View file

@ -66,7 +66,7 @@ class BuildVariantFormSubscriber implements EventSubscriberInterface
}
// Get related variable object.
$variable = $variant->getObject();
$variable = $variant->getProduct();
// If the object has options, lets add this configuration field.
if ($variable->hasOptions()) {

View file

@ -11,7 +11,7 @@
namespace Sylius\Bundle\VariationBundle\Form\Type;
use Sylius\Component\Variation\Model\OptionInterface;
use Sylius\Component\Product\Model\OptionInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
use Symfony\Component\OptionsResolver\Options;

View file

@ -11,7 +11,7 @@
namespace Sylius\Bundle\VariationBundle\Form\Type;
use Sylius\Component\Variation\Model\OptionInterface;
use Sylius\Component\Product\Model\OptionInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Exception\InvalidConfigurationException;
use Symfony\Component\Form\FormBuilderInterface;
@ -50,13 +50,13 @@ class OptionValueCollectionType extends AbstractType
!($options['options'] instanceof \Traversable && $options['options'] instanceof \ArrayAccess)
) {
throw new InvalidConfigurationException(
'array or (\Traversable and \ArrayAccess) of "Sylius\Component\Variation\Model\OptionInterface" must be passed to collection'
'array or (\Traversable and \ArrayAccess) of "Sylius\Component\Product\Model\OptionInterface" must be passed to collection'
);
}
foreach ($options['options'] as $i => $option) {
if (!$option instanceof OptionInterface) {
throw new InvalidConfigurationException('Each object passed as option list must implement "Sylius\Component\Variation\Model\OptionInterface"');
throw new InvalidConfigurationException('Each object passed as option list must implement "Sylius\Component\Product\Model\OptionInterface"');
}
$builder->add((string) $option->getId(), sprintf('sylius_%s_option_value_choice', $this->variableName), [

View file

@ -12,7 +12,7 @@
namespace Sylius\Bundle\VariationBundle\Form\Type;
use Sylius\Bundle\VariationBundle\Form\ChoiceList\VariantChoiceList;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
@ -66,7 +66,7 @@ class VariantChoiceType extends AbstractType
->setRequired([
'variable',
])
->setAllowedTypes('variable', VariableInterface::class)
->setAllowedTypes('variable', ProductInterface::class)
;
}

View file

@ -13,7 +13,7 @@ namespace Sylius\Bundle\VariationBundle\Form\Type;
use Gedmo\Sluggable\Util\Urlizer;
use Sylius\Bundle\VariationBundle\Form\DataTransformer\VariantToCombinationTransformer;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -61,7 +61,7 @@ class VariantMatchType extends AbstractType
->setRequired([
'variable',
])
->setAllowedTypes('variable', VariableInterface::class)
->setAllowedTypes('variable', ProductInterface::class)
;
}

View file

@ -17,7 +17,7 @@
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping">
<mapped-superclass name="Sylius\Component\Variation\Model\Option" table="sylius_option">
<mapped-superclass name="Sylius\Component\Product\Model\Option" table="sylius_option">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>

View file

@ -16,7 +16,7 @@
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="Sylius\Component\Variation\Model\OptionTranslation" table="sylius_option_translation">
<mapped-superclass name="Sylius\Component\Product\Model\OptionTranslation" table="sylius_option_translation">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>

View file

@ -17,7 +17,7 @@
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<mapped-superclass name="Sylius\Component\Variation\Model\OptionValue" table="sylius_option_value">
<mapped-superclass name="Sylius\Component\Product\Model\OptionValue" table="sylius_option_value">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>

View file

@ -12,7 +12,7 @@
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="Sylius\Component\Variation\Model\OptionValueTranslation"
<mapped-superclass name="Sylius\Component\Product\Model\OptionValueTranslation"
table="sylius_option_value_translation">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />

View file

@ -18,7 +18,7 @@
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
>
<mapped-superclass name="Sylius\Component\Variation\Model\Variant" table="sylius_variant">
<mapped-superclass name="Sylius\Component\Product\Model\Variant" table="sylius_variant">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>

View file

@ -1,4 +1,4 @@
Sylius\Component\Variation\Model\Option:
Sylius\Component\Product\Model\Option:
exclusion_policy: ALL
xml_root_name: option
properties:

View file

@ -1,4 +1,4 @@
Sylius\Component\Variation\Model\OptionValue:
Sylius\Component\Product\Model\OptionValue:
exclusion_policy: ALL
xml_root_name: option-value
properties:

View file

@ -1,4 +1,4 @@
Sylius\Component\Variation\Model\Variant:
Sylius\Component\Product\Model\Variant:
exclusion_policy: ALL
xml_root_name: variant
properties:

View file

@ -22,9 +22,9 @@
<parameter key="sylius.validator.variant.unique.class">Sylius\Bundle\VariationBundle\Validator\VariantUniqueValidator</parameter>
<parameter key="sylius.validator.variant.combination.class">Sylius\Bundle\VariationBundle\Validator\VariantCombinationValidator</parameter>
<parameter key="sylius.generator.variant.class">Sylius\Component\Variation\Generator\VariantGenerator</parameter>
<parameter key="sylius.generator.variant.class">Sylius\Component\Product\Generator\VariantGenerator</parameter>
<parameter key="sylius.variant_resolver.default.class">Sylius\Component\Variation\Resolver\DefaultVariantResolver</parameter>
<parameter key="sylius.variant_resolver.default.class">Sylius\Component\Product\Resolver\DefaultVariantResolver</parameter>
</parameters>
<services>

View file

@ -16,7 +16,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">
<class name="Sylius\Component\Variation\Model\Variant">
<class name="Sylius\Component\Product\Model\Variant">
<property name="code">
<constraint name="NotBlank">
<option name="message">sylius.option.code.not_blank</option>
@ -28,7 +28,7 @@
</constraint>
</class>
<class name="Sylius\Component\Variation\Model\Option">
<class name="Sylius\Component\Product\Model\Option">
<constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity">
<option name="fields">code</option>
<option name="message">sylius.option.code.unique</option>
@ -53,7 +53,7 @@
</property>
</class>
<class name="Sylius\Component\Variation\Model\OptionTranslation">
<class name="Sylius\Component\Product\Model\OptionTranslation">
<property name="name">
<constraint name="NotBlank">
<option name="message">sylius.option.name.not_blank</option>
@ -69,7 +69,7 @@
</property>
</class>
<class name="Sylius\Component\Variation\Model\OptionValue">
<class name="Sylius\Component\Product\Model\OptionValue">
<constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity">
<option name="fields">code</option>
<option name="message">sylius.option_value.code.unique</option>
@ -86,7 +86,7 @@
</property>
</class>
<class name="Sylius\Component\Variation\Model\OptionValueTranslation">
<class name="Sylius\Component\Product\Model\OptionValueTranslation">
<property name="value">
<constraint name="NotBlank">
<option name="message">sylius.option_value.value.not_blank</option>

View file

@ -37,6 +37,6 @@ class SyliusVariationBundle extends AbstractResourceBundle
*/
protected function getModelNamespace()
{
return 'Sylius\Component\Variation\Model';
return 'Sylius\Component\Product\Model';
}
}

View file

@ -11,8 +11,8 @@
namespace Sylius\Bundle\VariationBundle\Validator;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\VariantInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
@ -31,7 +31,7 @@ class VariantCombinationValidator extends ConstraintValidator
throw new UnexpectedTypeException($value, VariantInterface::class);
}
$variable = $value->getObject();
$variable = $value->getProduct();
if (!$variable->hasVariants() || !$variable->hasOptions()) {
return;
}
@ -43,11 +43,11 @@ class VariantCombinationValidator extends ConstraintValidator
/**
* @param VariantInterface $variant
* @param VariableInterface $variable
* @param ProductInterface $variable
*
* @return bool
*/
private function matches(VariantInterface $variant, VariableInterface $variable)
private function matches(VariantInterface $variant, ProductInterface $variable)
{
foreach ($variable->getVariants() as $existingVariant) {
if ($variant === $existingVariant) {

View file

@ -12,7 +12,7 @@
namespace Sylius\Bundle\VariationBundle\Validator;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Product\Model\VariantInterface;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

View file

@ -12,12 +12,12 @@
namespace spec\Sylius\Bundle\VariationBundle\Form\ChoiceList;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\VariantInterface;
final class VariantChoiceListSpec extends ObjectBehavior
{
function let(VariableInterface $variable, VariantInterface $variant)
function let(ProductInterface $variable, VariantInterface $variant)
{
$variable->getVariants()->shouldBeCalled()->willReturn([$variant]);

View file

@ -13,15 +13,15 @@ namespace spec\Sylius\Bundle\VariationBundle\Form\DataTransformer;
use Doctrine\Common\Collections\Collection;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Variation\Model\OptionValueInterface;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Product\Model\OptionValueInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\VariantInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
final class VariantToCombinationTransformerSpec extends ObjectBehavior
{
function let(VariableInterface $variable)
function let(ProductInterface $variable)
{
$this->beConstructedWith($variable);
}
@ -71,7 +71,7 @@ final class VariantToCombinationTransformerSpec extends ObjectBehavior
}
function it_should_reverse_transform_variable_without_variants_into_null(
VariableInterface $variable,
ProductInterface $variable,
OptionValueInterface $optionValue
) {
$variable->getVariants()->willReturn([]);
@ -80,7 +80,7 @@ final class VariantToCombinationTransformerSpec extends ObjectBehavior
}
function it_should_reverse_transform_variable_with_variants_if_options_match(
VariableInterface $variable,
ProductInterface $variable,
VariantInterface $variant,
OptionValueInterface $optionValue
) {
@ -92,7 +92,7 @@ final class VariantToCombinationTransformerSpec extends ObjectBehavior
}
function it_should_not_reverse_transform_variable_with_variants_if_options_not_match(
VariableInterface $variable,
ProductInterface $variable,
VariantInterface $variant,
OptionValueInterface $optionValue
) {
@ -104,7 +104,7 @@ final class VariantToCombinationTransformerSpec extends ObjectBehavior
}
function it_should_not_reverse_transform_variable_with_variants_if_options_are_missing(
VariableInterface $variable,
ProductInterface $variable,
VariantInterface $variant
) {
$variable->getVariants()->willReturn([$variant]);

View file

@ -12,10 +12,10 @@
namespace spec\Sylius\Bundle\VariationBundle\Form\EventListener;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Variation\Model\OptionInterface;
use Sylius\Component\Variation\Model\OptionValueInterface;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Product\Model\OptionInterface;
use Sylius\Component\Product\Model\OptionValueInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\VariantInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormFactoryInterface;
@ -45,7 +45,7 @@ final class BuildVariantFormSubscriberSpec extends ObjectBehavior
FormEvent $event,
FormInterface $form,
FormInterface $optionsForm,
VariableInterface $variable,
ProductInterface $variable,
VariantInterface $variant,
OptionValueInterface $optionValue,
OptionInterface $options
@ -53,7 +53,7 @@ final class BuildVariantFormSubscriberSpec extends ObjectBehavior
$event->getForm()->shouldBeCalled()->willReturn($form);
$event->getData()->shouldBeCalled()->willReturn($variant);
$variant->getObject()->shouldBeCalled()->willReturn($variable);
$variant->getProduct()->shouldBeCalled()->willReturn($variable);
$variant->getOptions()->shouldBeCalled()->willReturn([$optionValue]);
$variable->getOptions()->shouldBeCalled()->willReturn([$options]);
$variable->hasOptions()->shouldBeCalled()->willReturn(true);

View file

@ -13,7 +13,7 @@ namespace spec\Sylius\Bundle\VariationBundle\Form\Type;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Variation\Model\OptionInterface;
use Sylius\Component\Product\Model\OptionInterface;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

View file

@ -12,7 +12,7 @@
namespace spec\Sylius\Bundle\VariationBundle\Form\Type;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Variation\Model\OptionInterface;
use Sylius\Component\Product\Model\OptionInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

View file

@ -13,7 +13,7 @@ namespace spec\Sylius\Bundle\VariationBundle\Form\Type;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormTypeInterface;
@ -55,7 +55,7 @@ final class VariantChoiceTypeSpec extends ObjectBehavior
'variable',
])->shouldBeCalled()->willReturn($resolver);
$resolver->setAllowedTypes('variable', VariableInterface::class)->shouldBeCalled()->willReturn($resolver);
$resolver->setAllowedTypes('variable', ProductInterface::class)->shouldBeCalled()->willReturn($resolver);
$this->configureOptions($resolver);
}

View file

@ -14,8 +14,8 @@ namespace spec\Sylius\Bundle\VariationBundle\Form\Type;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Bundle\VariationBundle\Form\DataTransformer\VariantToCombinationTransformer;
use Sylius\Component\Variation\Model\OptionInterface;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Product\Model\OptionInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\Form\Test\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -37,7 +37,7 @@ final class VariantMatchTypeSpec extends ObjectBehavior
$this->shouldImplement(FormTypeInterface::class);
}
function it_builds_a_form(FormBuilderInterface $builder, VariableInterface $variable, OptionInterface $option)
function it_builds_a_form(FormBuilderInterface $builder, ProductInterface $variable, OptionInterface $option)
{
$variable->getOptions()->shouldBeCalled()->willReturn([$option]);
$option->getName()->shouldBeCalled()->willReturn('option_name');
@ -62,7 +62,7 @@ final class VariantMatchTypeSpec extends ObjectBehavior
'variable',
])->shouldBeCalled()->willReturn($resolver);
$resolver->setAllowedTypes('variable', VariableInterface::class)->shouldBeCalled()->willReturn($resolver);
$resolver->setAllowedTypes('variable', ProductInterface::class)->shouldBeCalled()->willReturn($resolver);
$this->configureOptions($resolver);
}

View file

@ -15,9 +15,9 @@ use Doctrine\Common\Collections\ArrayCollection;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Bundle\VariationBundle\Validator\Constraint\VariantCombination;
use Sylius\Component\Variation\Model\OptionValueInterface;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Product\Model\OptionValueInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\VariantInterface;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
@ -40,13 +40,13 @@ final class VariantCombinationValidatorSpec extends ObjectBehavior
function it_should_not_add_violation_if_variable_dont_have_options(
VariantInterface $variant,
VariableInterface $variable
ProductInterface $variable
) {
$constraint = new VariantCombination([
'message' => 'Variant with given options already exists',
]);
$variant->getObject()->willReturn($variable);
$variant->getProduct()->willReturn($variable);
$variable->hasVariants()->willReturn(false);
$variable->hasOptions()->willReturn(true);
@ -56,13 +56,13 @@ final class VariantCombinationValidatorSpec extends ObjectBehavior
function it_should_not_add_violation_if_variable_dont_have_variants(
VariantInterface $variant,
VariableInterface $variable
ProductInterface $variable
) {
$constraint = new VariantCombination([
'message' => 'Variant with given options already exists',
]);
$variant->getObject()->willReturn($variable);
$variant->getProduct()->willReturn($variable);
$variable->hasVariants()->willReturn(true);
$variable->hasOptions()->willReturn(false);
@ -73,7 +73,7 @@ final class VariantCombinationValidatorSpec extends ObjectBehavior
function it_should_add_violation_if_variant_with_given_same_options_already_exists(
VariantInterface $variant,
VariantInterface $existingVariant,
VariableInterface $variable,
ProductInterface $variable,
OptionValueInterface $option,
$context
) {
@ -81,7 +81,7 @@ final class VariantCombinationValidatorSpec extends ObjectBehavior
'message' => 'Variant with given options already exists',
]);
$variant->getObject()->willReturn($variable);
$variant->getProduct()->willReturn($variable);
$variant->getOptions()->willReturn(new ArrayCollection([$option->getWrappedObject()]));

View file

@ -15,7 +15,7 @@ use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Bundle\VariationBundle\Validator\Constraint\VariantUnique;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Product\Model\VariantInterface;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Context\ExecutionContextInterface;

View file

@ -13,7 +13,7 @@ namespace Sylius\Component\Core\Factory;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Variation\Resolver\VariantResolverInterface;
use Sylius\Component\Product\Resolver\VariantResolverInterface;
/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>

View file

@ -18,7 +18,7 @@ use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Variation\Resolver\VariantResolverInterface;
use Sylius\Component\Product\Resolver\VariantResolverInterface;
/**
* @mixin CartItemFactory

View file

@ -9,12 +9,12 @@
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Generator;
namespace Sylius\Component\Product\Generator;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Variation\SetBuilder\SetBuilderInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\VariantInterface;
use Sylius\Component\Product\SetBuilder\SetBuilderInterface;
/**
* Variant generator service implementation.
@ -55,7 +55,7 @@ class VariantGenerator implements VariantGeneratorInterface
/**
* {@inheritdoc}
*/
public function generate(VariableInterface $variable)
public function generate(ProductInterface $variable)
{
if (!$variable->hasOptions()) {
throw new \InvalidArgumentException('Cannot generate variants for an object without options.');
@ -80,16 +80,16 @@ class VariantGenerator implements VariantGeneratorInterface
}
/**
* @param VariableInterface $variable
* @param ProductInterface $variable
* @param array $optionMap
* @param mixed $permutation
*
* @return VariantInterface
*/
protected function createVariant(VariableInterface $variable, array $optionMap, $permutation)
protected function createVariant(ProductInterface $variable, array $optionMap, $permutation)
{
$variant = $this->variantFactory->createNew();
$variant->setObject($variable);
$variant->setProduct($variable);
if (is_array($permutation)) {
foreach ($permutation as $id) {

View file

@ -9,9 +9,9 @@
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Generator;
namespace Sylius\Component\Product\Generator;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Product\Model\ProductInterface;
/**
* Interface for variant generating service.
@ -26,7 +26,7 @@ interface VariantGeneratorInterface
/**
* Generate all possible variants if they don't exist currently.
*
* @param VariableInterface $variable
* @param ProductInterface $variable
*/
public function generate(VariableInterface $variable);
public function generate(ProductInterface $variable);
}

View file

@ -11,12 +11,143 @@
namespace Sylius\Component\Product\Model;
use Sylius\Component\Variation\Model\Option as BaseOption;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Resource\Model\TimestampableTrait;
use Sylius\Component\Resource\Model\TranslatableTrait;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
class Option extends BaseOption implements OptionInterface
class Option implements OptionInterface
{
use TimestampableTrait;
use TranslatableTrait {
__construct as private initializeTranslationsCollection;
}
/**
* @var mixed
*/
protected $id;
/**
* @var string
*/
protected $code;
/**
* Displayed to user.
*
* @var string
*/
protected $name;
/**
* @var Collection|OptionValueInterface[]
*/
protected $values;
public function __construct()
{
$this->initializeTranslationsCollection();
$this->values = new ArrayCollection();
$this->createdAt = new \DateTime();
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return $this->getName();
}
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getCode()
{
return $this->code;
}
/**
* {@inheritdoc}
*/
public function setCode($code)
{
$this->code = $code;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->translate()->getName();
}
/**
* {@inheritdoc}
*/
public function setName($name)
{
$this->translate()->setName($name);
}
/**
* {@inheritdoc}
*/
public function getValues()
{
return $this->values;
}
/**
* {@inheritdoc}
*/
public function setValues(Collection $values)
{
$this->values = $values;
}
/**
* {@inheritdoc}
*/
public function addValue(OptionValueInterface $value)
{
if (!$this->hasValue($value)) {
$value->setOption($this);
$this->values->add($value);
}
}
/**
* {@inheritdoc}
*/
public function removeValue(OptionValueInterface $value)
{
if ($this->hasValue($value)) {
$this->values->removeElement($value);
$value->setOption(null);
}
}
/**
* {@inheritdoc}
*/
public function hasValue(OptionValueInterface $value)
{
return $this->values->contains($value);
}
}

View file

@ -11,11 +11,57 @@
namespace Sylius\Component\Product\Model;
use Sylius\Component\Variation\Model\OptionInterface as BaseOptionInterface;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Resource\Model\CodeAwareInterface;
use Sylius\Component\Resource\Model\TimestampableInterface;
use Sylius\Component\Resource\Model\TranslatableInterface;
/**
* Model implementing this interface represents the option type, which can be
* attached to an object.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface OptionInterface extends BaseOptionInterface
interface OptionInterface extends
CodeAwareInterface,
TimestampableInterface,
OptionTranslationInterface,
TranslatableInterface
{
/**
* Returns all option values.
*
* @return Collection|OptionValueInterface[]
*/
public function getValues();
/**
* Sets all option values.
*
* @param Collection $optionValues
*/
public function setValues(Collection $optionValues);
/**
* Adds option value.
*
* @param OptionValueInterface $optionValue
*/
public function addValue(OptionValueInterface $optionValue);
/**
* Removes option value.
*
* @param OptionValueInterface $optionValue
*/
public function removeValue(OptionValueInterface $optionValue);
/**
* Checks whether option has given value.
*
* @param OptionValueInterface $optionValue
*
* @return bool
*/
public function hasValue(OptionValueInterface $optionValue);
}

View file

@ -11,11 +11,44 @@
namespace Sylius\Component\Product\Model;
use Sylius\Component\Variation\Model\OptionTranslation as BaseOptionTranslation;
use Sylius\Component\Resource\Model\AbstractTranslation;
/**
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
class OptionTranslation extends BaseOptionTranslation implements OptionTranslationInterface
class OptionTranslation extends AbstractTranslation implements OptionTranslationInterface
{
/**
* @var mixed
*/
protected $id;
/**
* @var string
*/
protected $name;
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
/**
* {@inheritdoc}
*/
public function setName($name)
{
$this->name = $name;
}
}

View file

@ -11,11 +11,22 @@
namespace Sylius\Component\Product\Model;
use Sylius\Component\Variation\Model\OptionTranslationInterface as BaseOptionTranslationInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
/**
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
interface OptionTranslationInterface extends BaseOptionTranslationInterface
interface OptionTranslationInterface extends ResourceInterface
{
/**
* The name displayed to user.
*
* @return string
*/
public function getName();
/**
* @param string $name
*/
public function setName($name);
}

View file

@ -11,11 +11,127 @@
namespace Sylius\Component\Product\Model;
use Sylius\Component\Variation\Model\OptionValue as BaseOptionValue;
use Sylius\Component\Resource\Model\TranslatableTrait;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class OptionValue extends BaseOptionValue implements OptionValueInterface
class OptionValue implements OptionValueInterface
{
use TranslatableTrait {
__construct as private initializeTranslationCollection;
}
/**
* @var mixed
*/
protected $id;
/**
* @var string
*/
protected $code;
/**
* @var string
*/
protected $value;
/**
* @var OptionInterface
*/
protected $option;
public function __construct()
{
$this->initializeTranslationCollection();
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return $this->getValue();
}
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getCode()
{
return $this->code;
}
/**
* {@inheritdoc}
*/
public function setCode($code)
{
$this->code = $code;
}
/**
* {@inheritdoc}
*/
public function getOption()
{
return $this->option;
}
/**
* {@inheritdoc}
*/
public function setOption(OptionInterface $option = null)
{
$this->option = $option;
}
/**
* {@inheritdoc}
*/
public function getValue()
{
return $this->translate()->getValue();
}
/**
* {@inheritdoc}
*/
public function setValue($value)
{
$this->translate()->setValue($value);
}
/**
* {@inheritdoc}
*/
public function getOptionCode()
{
if (null === $this->option) {
throw new \BadMethodCallException('The option have not been created yet so you cannot access proxy methods.');
}
return $this->option->getCode();
}
/**
* {@inheritdoc}
*/
public function getName()
{
if (null === $this->option) {
throw new \BadMethodCallException('The option have not been created yet so you cannot access proxy methods.');
}
return $this->option->getName();
}
}

View file

@ -11,11 +11,50 @@
namespace Sylius\Component\Product\Model;
use Sylius\Component\Variation\Model\OptionValueInterface as BaseOptionValueInterface;
use Sylius\Component\Resource\Model\CodeAwareInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Model\TranslatableInterface;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface OptionValueInterface extends BaseOptionValueInterface
interface OptionValueInterface extends ResourceInterface, CodeAwareInterface, TranslatableInterface
{
/**
* @return OptionInterface
*/
public function getOption();
/**
* @param OptionInterface $option
*/
public function setOption(OptionInterface $option = null);
/**
* Get internal value.
*
* @return string
*/
public function getValue();
/**
* Set internal value.
*
* @param string $value
*/
public function setValue($value);
/**
* Proxy method to access the presentation of real option object.
*
* @return string The code of object
*/
public function getOptionCode();
/**
* Proxy method to access the name of real option object.
*
* @return string The name of object
*/
public function getName();
}

View file

@ -11,11 +11,44 @@
namespace Sylius\Component\Product\Model;
use Sylius\Component\Variation\Model\OptionValueTranslation as BaseOptionValueTranslation;
use Sylius\Component\Resource\Model\AbstractTranslation;
/**
* @author Vincenzo Provenza <vincenzo.provenza89@gmail.com>
*/
class OptionValueTranslation extends BaseOptionValueTranslation implements OptionValueTranslationInterface
class OptionValueTranslation extends AbstractTranslation implements OptionValueTranslationInterface
{
/**
* @var mixed
*/
protected $id;
/**
* @var string
*/
protected $value;
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getValue()
{
return $this->value;
}
/**
* {@inheritdoc}
*/
public function setValue($value)
{
$this->value = $value;
}
}

View file

@ -11,11 +11,22 @@
namespace Sylius\Component\Product\Model;
use Sylius\Component\Variation\Model\OptionValueTranslationInterface as BaseOptionValueTranslationInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
/**
* @author Vincenzo Provenza <vincenzo.provenza89@gmail.com>
*/
interface OptionValueTranslationInterface extends BaseOptionValueTranslationInterface
interface OptionValueTranslationInterface extends ResourceInterface
{
/**
* The name displayed to user.
*
* @return string
*/
public function getValue();
/**
* @param string $value
*/
public function setValue($value);
}

View file

@ -17,8 +17,8 @@ use Sylius\Component\Attribute\Model\AttributeValueInterface as BaseAttributeVal
use Sylius\Component\Resource\Model\TimestampableTrait;
use Sylius\Component\Resource\Model\ToggleableTrait;
use Sylius\Component\Resource\Model\TranslatableTrait;
use Sylius\Component\Variation\Model\OptionInterface as BaseOptionInterface;
use Sylius\Component\Variation\Model\VariantInterface as BaseVariantInterface;
use Sylius\Component\Product\Model\OptionInterface as BaseOptionInterface;
use Sylius\Component\Product\Model\VariantInterface as BaseVariantInterface;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>

View file

@ -11,6 +11,7 @@
namespace Sylius\Component\Product\Model;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Association\Model\AssociableInterface;
use Sylius\Component\Attribute\Model\AttributeSubjectInterface;
use Sylius\Component\Resource\Model\CodeAwareInterface;
@ -18,7 +19,6 @@ use Sylius\Component\Resource\Model\SlugAwareInterface;
use Sylius\Component\Resource\Model\TimestampableInterface;
use Sylius\Component\Resource\Model\ToggleableInterface;
use Sylius\Component\Resource\Model\TranslatableInterface;
use Sylius\Component\Variation\Model\VariableInterface;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
@ -32,9 +32,61 @@ interface ProductInterface extends
ProductTranslationInterface,
AssociableInterface,
CodeAwareInterface,
TranslatableInterface,
VariableInterface
TranslatableInterface
{
/**
* @return bool
*/
public function hasVariants();
/**
* @return Collection|VariantInterface[]
*/
public function getVariants();
/**
* @param Collection $variants
*/
public function setVariants(Collection $variants);
/**
* @param VariantInterface $variant
*/
public function addVariant(VariantInterface $variant);
/**
* @param VariantInterface $variant
*/
public function removeVariant(VariantInterface $variant);
/**
* @param VariantInterface $variant
*
* @return bool
*/
public function hasVariant(VariantInterface $variant);
/**
* @return bool
*/
public function hasOptions();
/**
* @return Collection|OptionInterface[]
*/
public function getOptions();
/**
* @param Collection $options
*/
public function setOptions(Collection $options);
/**
* @param OptionInterface $option
*/
public function addOption(OptionInterface $option);
/**
* @param OptionInterface $option
*/
public function removeOption(OptionInterface $option);
/**
* @param OptionInterface $option
*
* @return bool
*/
public function hasOption(OptionInterface $option);
/**
* @return bool
*/

View file

@ -11,14 +11,42 @@
namespace Sylius\Component\Product\Model;
use Sylius\Component\Variation\Model\Variant as BaseVariant;
use Sylius\Component\Variation\Model\VariantInterface as BaseVariantInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Resource\Model\TimestampableTrait;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class Variant extends BaseVariant implements VariantInterface
class Variant implements VariantInterface
{
use TimestampableTrait;
/**
* @var mixed
*/
protected $id;
/**
* @var string
*/
protected $code;
/**
* @var string
*/
protected $name;
/**
* @var ProductInterface
*/
protected $product;
/**
* @var Collection|OptionValueInterface[]
*/
protected $options;
/**
* @var \DateTime
*/
@ -31,17 +59,102 @@ class Variant extends BaseVariant implements VariantInterface
public function __construct()
{
parent::__construct();
$this->options = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->availableOn = new \DateTime();
}
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*/
public function setCode($code)
{
$this->code = $code;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
/**
* {@inheritdoc}
*/
public function setName($name)
{
$this->name = $name;
}
/**
* {@inheritdoc}
*/
public function getOptions()
{
return $this->options;
}
/**
* {@inheritdoc}
*/
public function setOptions(Collection $options)
{
$this->options = $options;
}
/**
* {@inheritdoc}
*/
public function addOption(OptionValueInterface $option)
{
if (!$this->hasOption($option)) {
$this->options->add($option);
}
}
/**
* {@inheritdoc}
*/
public function removeOption(OptionValueInterface $option)
{
if ($this->hasOption($option)) {
$this->options->removeElement($option);
}
}
/**
* {@inheritdoc}
*/
public function hasOption(OptionValueInterface $option)
{
return $this->options->contains($option);
}
/**
* {@inheritdoc}
*/
public function getProduct()
{
return parent::getObject();
return $this->product;
}
/**
@ -49,7 +162,7 @@ class Variant extends BaseVariant implements VariantInterface
*/
public function setProduct(ProductInterface $product = null)
{
return parent::setObject($product);
$this->product = $product;
}
/**

View file

@ -11,13 +11,56 @@
namespace Sylius\Component\Product\Model;
use Sylius\Component\Variation\Model\VariantInterface as BaseVariantInterface;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Resource\Model\CodeAwareInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Model\TimestampableInterface;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface VariantInterface extends BaseVariantInterface
interface VariantInterface extends TimestampableInterface, ResourceInterface, CodeAwareInterface
{
/**
* This should be generated from option values
* when no other is set.
*
* @return string
*/
public function getName();
/**
* @param string $name
*/
public function setName($name);
/**
* @return Collection|OptionValueInterface[]
*/
public function getOptions();
/**
* @param Collection $options
*/
public function setOptions(Collection $options);
/**
* @param OptionValueInterface $option
*/
public function addOption(OptionValueInterface $option);
/**
* @param OptionValueInterface $option
*/
public function removeOption(OptionValueInterface $option);
/**
* @param OptionValueInterface $option
*
* @return bool
*/
public function hasOption(OptionValueInterface $option);
/**
* @return ProductInterface
*/

View file

@ -9,10 +9,10 @@
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Repository;
namespace Sylius\Component\Product\Repository;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Variation\Model\OptionInterface;
use Sylius\Component\Product\Model\OptionInterface;
/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>

View file

@ -9,9 +9,9 @@
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Resolver;
namespace Sylius\Component\Product\Resolver;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Product\Model\ProductInterface;
/**
* @author Anna Walasek <anna.walasek@lakion.com>
@ -21,7 +21,7 @@ final class DefaultVariantResolver implements VariantResolverInterface
/**
* {@inheritdoc}
*/
public function getVariant(VariableInterface $subject)
public function getVariant(ProductInterface $subject)
{
if ($subject->getVariants()->isEmpty()) {
return null;

View file

@ -9,10 +9,10 @@
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Resolver;
namespace Sylius\Component\Product\Resolver;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\VariantInterface;
/**
* @author Anna Walasek <anna.walasek@lakion.com>
@ -20,9 +20,9 @@ use Sylius\Component\Variation\Model\VariantInterface;
interface VariantResolverInterface
{
/**
* @param VariableInterface $subject
* @param ProductInterface $subject
*
* @return VariantInterface
*/
public function getVariant(VariableInterface $subject);
public function getVariant(ProductInterface $subject);
}

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\SetBuilder;
namespace Sylius\Component\Product\SetBuilder;
/**
* Builds the Cartesian product set from one or more given sets.

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\SetBuilder;
namespace Sylius\Component\Product\SetBuilder;
/**
* Build a product set from one or more given sets.

View file

@ -15,7 +15,7 @@ use PhpSpec\ObjectBehavior;
use Sylius\Component\Product\Factory\ProductFactoryInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Product\Model\VariantInterface;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>

View file

@ -9,17 +9,17 @@
* file that was distributed with this source code.
*/
namespace spec\Sylius\Component\Variation\Generator;
namespace spec\Sylius\Component\Product\Generator;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Variation\Generator\VariantGeneratorInterface;
use Sylius\Component\Variation\Model\OptionInterface;
use Sylius\Component\Variation\Model\OptionValue;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Variation\SetBuilder\SetBuilderInterface;
use Sylius\Component\Product\Generator\VariantGeneratorInterface;
use Sylius\Component\Product\Model\OptionInterface;
use Sylius\Component\Product\Model\OptionValue;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\VariantInterface;
use Sylius\Component\Product\SetBuilder\SetBuilderInterface;
/**
* @author Adam Elsodaney <adam.elso@gmail.com>
@ -33,7 +33,7 @@ final class VariantGeneratorSpec extends ObjectBehavior
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Component\Variation\Generator\VariantGenerator');
$this->shouldHaveType('Sylius\Component\Product\Generator\VariantGenerator');
}
function it_is_a_Sylius_variant_generator()
@ -41,7 +41,7 @@ final class VariantGeneratorSpec extends ObjectBehavior
$this->shouldImplement(VariantGeneratorInterface::class);
}
function it_cannot_generate_variants_for_an_object_without_options(VariableInterface $variable)
function it_cannot_generate_variants_for_an_object_without_options(ProductInterface $variable)
{
$variable->hasOptions()->willReturn(false);
@ -55,7 +55,7 @@ final class VariantGeneratorSpec extends ObjectBehavior
OptionValue $redColor,
OptionValue $whiteColor,
SetBuilderInterface $setBuilder,
VariableInterface $productVariable,
ProductInterface $productVariable,
VariantInterface $permutationVariant
) {
$productVariable->hasOptions()->willReturn(true);
@ -76,8 +76,8 @@ final class VariantGeneratorSpec extends ObjectBehavior
]);
$variantFactory->createNew()->willReturn($permutationVariant);
$permutationVariant->setObject($productVariable)->shouldBeCalled();
$permutationVariant->addOption(Argument::type('Sylius\Component\Variation\Model\OptionValue'))->shouldBeCalled();
$permutationVariant->setProduct($productVariable)->shouldBeCalled();
$permutationVariant->addOption(Argument::type('Sylius\Component\Product\Model\OptionValue'))->shouldBeCalled();
$productVariable->addVariant($permutationVariant)->shouldBeCalled();
$this->generate($productVariable);
@ -94,7 +94,7 @@ final class VariantGeneratorSpec extends ObjectBehavior
OptionValue $smallSize,
OptionValue $whiteColor,
SetBuilderInterface $setBuilder,
VariableInterface $productVariable,
ProductInterface $productVariable,
VariantInterface $permutationVariant
) {
$productVariable->hasOptions()->willReturn(true);
@ -127,8 +127,8 @@ final class VariantGeneratorSpec extends ObjectBehavior
]);
$variantFactory->createNew()->willReturn($permutationVariant);
$permutationVariant->setObject($productVariable)->shouldBeCalled();
$permutationVariant->addOption(Argument::type('Sylius\Component\Variation\Model\OptionValue'))->shouldBeCalled();
$permutationVariant->setProduct($productVariable)->shouldBeCalled();
$permutationVariant->addOption(Argument::type('Sylius\Component\Product\Model\OptionValue'))->shouldBeCalled();
$productVariable->addVariant($permutationVariant)->shouldBeCalled();
$this->generate($productVariable);

View file

@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/
namespace spec\Sylius\Component\Variation\Resolver;
namespace spec\Sylius\Component\Product\Resolver;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Variation\Resolver\DefaultVariantResolver;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Resolver\DefaultVariantResolver;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Variation\Model\VariantInterface;
use Sylius\Component\Variation\Resolver\VariantResolverInterface;
use Sylius\Component\Product\Model\VariantInterface;
use Sylius\Component\Product\Resolver\VariantResolverInterface;
/**
* @author Anna Walasek <anna.walasek@lakion.com>
@ -35,7 +35,7 @@ final class DefaultVariantResolverSpec extends ObjectBehavior
}
function it_returns_first_variant(
VariableInterface $product,
ProductInterface $product,
VariantInterface $variant,
Collection $variants
) {
@ -46,7 +46,7 @@ final class DefaultVariantResolverSpec extends ObjectBehavior
$this->getVariant($product)->shouldReturn($variant);
}
function it_returns_null_if_first_variant_is_not_definied(VariableInterface $product, Collection $variants)
function it_returns_null_if_first_variant_is_not_definied(ProductInterface $product, Collection $variants)
{
$product->getVariants()->willReturn($variants);
$variants->isEmpty()->willReturn(true);

View file

@ -9,11 +9,11 @@
* file that was distributed with this source code.
*/
namespace spec\Sylius\Component\Variation\SetBuilder;
namespace spec\Sylius\Component\Product\SetBuilder;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Variation\SetBuilder\SetBuilderInterface;
use Sylius\Component\Product\SetBuilder\SetBuilderInterface;
/**
* @author Adam Elsodaney <adam.elso@gmail.com>

View file

@ -1,5 +0,0 @@
vendor/
bin/
composer.phar
composer.lock

View file

@ -1,7 +0,0 @@
CHANGELOG
=========
### v0.10.0
* Initial dev release.

View file

@ -1,19 +0,0 @@
Copyright (c) 2011-2016 Paweł Jędrzejewski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -1,153 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Model;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Resource\Model\TimestampableTrait;
use Sylius\Component\Resource\Model\TranslatableTrait;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
class Option implements OptionInterface
{
use TimestampableTrait;
use TranslatableTrait {
__construct as private initializeTranslationsCollection;
}
/**
* @var mixed
*/
protected $id;
/**
* @var string
*/
protected $code;
/**
* Displayed to user.
*
* @var string
*/
protected $name;
/**
* @var Collection|OptionValueInterface[]
*/
protected $values;
public function __construct()
{
$this->initializeTranslationsCollection();
$this->values = new ArrayCollection();
$this->createdAt = new \DateTime();
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return $this->getName();
}
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getCode()
{
return $this->code;
}
/**
* {@inheritdoc}
*/
public function setCode($code)
{
$this->code = $code;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->translate()->getName();
}
/**
* {@inheritdoc}
*/
public function setName($name)
{
$this->translate()->setName($name);
}
/**
* {@inheritdoc}
*/
public function getValues()
{
return $this->values;
}
/**
* {@inheritdoc}
*/
public function setValues(Collection $values)
{
$this->values = $values;
}
/**
* {@inheritdoc}
*/
public function addValue(OptionValueInterface $value)
{
if (!$this->hasValue($value)) {
$value->setOption($this);
$this->values->add($value);
}
}
/**
* {@inheritdoc}
*/
public function removeValue(OptionValueInterface $value)
{
if ($this->hasValue($value)) {
$this->values->removeElement($value);
$value->setOption(null);
}
}
/**
* {@inheritdoc}
*/
public function hasValue(OptionValueInterface $value)
{
return $this->values->contains($value);
}
}

View file

@ -1,67 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Model;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Resource\Model\CodeAwareInterface;
use Sylius\Component\Resource\Model\TimestampableInterface;
use Sylius\Component\Resource\Model\TranslatableInterface;
/**
* Model implementing this interface represents the option type, which can be
* attached to an object.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface OptionInterface extends
CodeAwareInterface,
TimestampableInterface,
OptionTranslationInterface,
TranslatableInterface
{
/**
* Returns all option values.
*
* @return Collection|OptionValueInterface[]
*/
public function getValues();
/**
* Sets all option values.
*
* @param Collection $optionValues
*/
public function setValues(Collection $optionValues);
/**
* Adds option value.
*
* @param OptionValueInterface $optionValue
*/
public function addValue(OptionValueInterface $optionValue);
/**
* Removes option value.
*
* @param OptionValueInterface $optionValue
*/
public function removeValue(OptionValueInterface $optionValue);
/**
* Checks whether option has given value.
*
* @param OptionValueInterface $optionValue
*
* @return bool
*/
public function hasValue(OptionValueInterface $optionValue);
}

View file

@ -1,54 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Model;
use Sylius\Component\Resource\Model\AbstractTranslation;
/**
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
class OptionTranslation extends AbstractTranslation implements OptionTranslationInterface
{
/**
* @var mixed
*/
protected $id;
/**
* @var string
*/
protected $name;
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
/**
* {@inheritdoc}
*/
public function setName($name)
{
$this->name = $name;
}
}

View file

@ -1,32 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Model;
use Sylius\Component\Resource\Model\ResourceInterface;
/**
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
interface OptionTranslationInterface extends ResourceInterface
{
/**
* The name displayed to user.
*
* @return string
*/
public function getName();
/**
* @param string $name
*/
public function setName($name);
}

View file

@ -1,137 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Model;
use Sylius\Component\Resource\Model\TranslatableTrait;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class OptionValue implements OptionValueInterface
{
use TranslatableTrait {
__construct as private initializeTranslationCollection;
}
/**
* @var mixed
*/
protected $id;
/**
* @var string
*/
protected $code;
/**
* @var string
*/
protected $value;
/**
* @var OptionInterface
*/
protected $option;
public function __construct()
{
$this->initializeTranslationCollection();
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return $this->getValue();
}
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getCode()
{
return $this->code;
}
/**
* {@inheritdoc}
*/
public function setCode($code)
{
$this->code = $code;
}
/**
* {@inheritdoc}
*/
public function getOption()
{
return $this->option;
}
/**
* {@inheritdoc}
*/
public function setOption(OptionInterface $option = null)
{
$this->option = $option;
}
/**
* {@inheritdoc}
*/
public function getValue()
{
return $this->translate()->getValue();
}
/**
* {@inheritdoc}
*/
public function setValue($value)
{
$this->translate()->setValue($value);
}
/**
* {@inheritdoc}
*/
public function getOptionCode()
{
if (null === $this->option) {
throw new \BadMethodCallException('The option have not been created yet so you cannot access proxy methods.');
}
return $this->option->getCode();
}
/**
* {@inheritdoc}
*/
public function getName()
{
if (null === $this->option) {
throw new \BadMethodCallException('The option have not been created yet so you cannot access proxy methods.');
}
return $this->option->getName();
}
}

View file

@ -1,60 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Model;
use Sylius\Component\Resource\Model\CodeAwareInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Model\TranslatableInterface;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface OptionValueInterface extends ResourceInterface, CodeAwareInterface, TranslatableInterface
{
/**
* @return OptionInterface
*/
public function getOption();
/**
* @param OptionInterface $option
*/
public function setOption(OptionInterface $option = null);
/**
* Get internal value.
*
* @return string
*/
public function getValue();
/**
* Set internal value.
*
* @param string $value
*/
public function setValue($value);
/**
* Proxy method to access the presentation of real option object.
*
* @return string The code of object
*/
public function getOptionCode();
/**
* Proxy method to access the name of real option object.
*
* @return string The name of object
*/
public function getName();
}

View file

@ -1,54 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Model;
use Sylius\Component\Resource\Model\AbstractTranslation;
/**
* @author Vincenzo Provenza <vincenzo.provenza89@gmail.com>
*/
class OptionValueTranslation extends AbstractTranslation implements OptionValueTranslationInterface
{
/**
* @var mixed
*/
protected $id;
/**
* @var string
*/
protected $value;
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getValue()
{
return $this->value;
}
/**
* {@inheritdoc}
*/
public function setValue($value)
{
$this->value = $value;
}
}

View file

@ -1,32 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Model;
use Sylius\Component\Resource\Model\ResourceInterface;
/**
* @author Vincenzo Provenza <vincenzo.provenza89@gmail.com>
*/
interface OptionValueTranslationInterface extends ResourceInterface
{
/**
* The name displayed to user.
*
* @return string
*/
public function getValue();
/**
* @param string $value
*/
public function setValue($value);
}

View file

@ -1,86 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Model;
use Doctrine\Common\Collections\Collection;
/**
* Should be implemented by models that support variants and options.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface VariableInterface
{
/**
* @return bool
*/
public function hasVariants();
/**
* @return Collection|VariantInterface[]
*/
public function getVariants();
/**
* @param Collection $variants
*/
public function setVariants(Collection $variants);
/**
* @param VariantInterface $variant
*/
public function addVariant(VariantInterface $variant);
/**
* @param VariantInterface $variant
*/
public function removeVariant(VariantInterface $variant);
/**
* @param VariantInterface $variant
*
* @return bool
*/
public function hasVariant(VariantInterface $variant);
/**
* @return bool
*/
public function hasOptions();
/**
* @return Collection|OptionInterface[]
*/
public function getOptions();
/**
* @param Collection $options
*/
public function setOptions(Collection $options);
/**
* @param OptionInterface $option
*/
public function addOption(OptionInterface $option);
/**
* @param OptionInterface $option
*/
public function removeOption(OptionInterface $option);
/**
* @param OptionInterface $option
*
* @return bool
*/
public function hasOption(OptionInterface $option);
}

View file

@ -1,155 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Model;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Resource\Model\TimestampableTrait;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class Variant implements VariantInterface
{
use TimestampableTrait;
/**
* @var mixed
*/
protected $id;
/**
* @var string
*/
protected $code;
/**
* @var string
*/
protected $name;
/**
* @var VariableInterface
*/
protected $object;
/**
* @var Collection|OptionValueInterface[]
*/
protected $options;
public function __construct()
{
$this->options = new ArrayCollection();
$this->createdAt = new \DateTime();
}
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*/
public function setCode($code)
{
$this->code = $code;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
/**
* {@inheritdoc}
*/
public function setName($name)
{
$this->name = $name;
}
/**
* {@inheritdoc}
*/
public function getObject()
{
return $this->object;
}
/**
* {@inheritdoc}
*/
public function setObject(VariableInterface $object = null)
{
$this->object = $object;
}
/**
* {@inheritdoc}
*/
public function getOptions()
{
return $this->options;
}
/**
* {@inheritdoc}
*/
public function setOptions(Collection $options)
{
$this->options = $options;
}
/**
* {@inheritdoc}
*/
public function addOption(OptionValueInterface $option)
{
if (!$this->hasOption($option)) {
$this->options->add($option);
}
}
/**
* {@inheritdoc}
*/
public function removeOption(OptionValueInterface $option)
{
if ($this->hasOption($option)) {
$this->options->removeElement($option);
}
}
/**
* {@inheritdoc}
*/
public function hasOption(OptionValueInterface $option)
{
return $this->options->contains($option);
}
}

View file

@ -1,73 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Variation\Model;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Resource\Model\CodeAwareInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Model\TimestampableInterface;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface VariantInterface extends TimestampableInterface, ResourceInterface, CodeAwareInterface
{
/**
* This should be generated from option values
* when no other is set.
*
* @return string
*/
public function getName();
/**
* @param string $name
*/
public function setName($name);
/**
* @return VariableInterface
*/
public function getObject();
/**
* @param VariableInterface|null $object
*/
public function setObject(VariableInterface $object = null);
/**
* @return Collection|OptionValueInterface[]
*/
public function getOptions();
/**
* @param Collection $options
*/
public function setOptions(Collection $options);
/**
* @param OptionValueInterface $option
*/
public function addOption(OptionValueInterface $option);
/**
* @param OptionValueInterface $option
*/
public function removeOption(OptionValueInterface $option);
/**
* @param OptionValueInterface $option
*
* @return bool
*/
public function hasOption(OptionValueInterface $option);
}

View file

@ -1,52 +0,0 @@
Variation Component [![Build status...](https://secure.travis-ci.org/Sylius/Variation.png?branch=master)](http://travis-ci.org/Sylius/Variation)
===================
Modern business applications often need to provide a system for entity
options. For example, a Server can have multiple variants or a Product can be
available in different sizes and colors.
Sylius Variation component contains basic models and architecture to handle
this functionality.
Sylius
------
Modern ecommerce for PHP and Symfony2. Visit [Sylius.org](http://sylius.org).
Documentation
-------------
Documentation is available on [**docs.sylius.org**](http://docs.sylius.org/en/latest/components/Variation/index.html).
Contributing
------------
All instructions for contributing to Sylius can be found in the [Contributing Guide](http://docs.sylius.org/en/latest/contributing/index.html).
Support
-------
If you have a question regarding the usage of this library, please ask on
[Stackoverflow](http://stackoverflow.com). You should use "sylius"
tag when posting and make sure to [browse existing questions](http://stackoverflow.com/questions/tagged/sylius).
Sylius on Twitter
-----------------
[Follow the official Sylius account on Twitter!](http://twitter.com/Sylius).
Bug Tracking
------------
If you find a bug, please refer to the [Reporting a Bug](http://docs.sylius.org/en/latest/contributing/code/bugs.html) guide.
MIT License
-----------
License can be found [here](https://github.com/Sylius/Variation/blob/master/LICENSE).
Authors
-------
The component was originally created by [Paweł Jędrzejewski](http://pjedrzejewski.com).
See the list of [contributors](https://github.com/Sylius/Variation/contributors).

View file

@ -1,52 +0,0 @@
{
"name": "sylius/variation",
"type": "library",
"description": "Object variants and options management for PHP.",
"keywords": ["shop", "ecommerce", "products", "product", "options", "variants"],
"homepage": "http://sylius.org",
"license": "MIT",
"authors": [
{
"name": "Paweł Jędrzejewski",
"homepage": "http://pjedrzejewski.com"
},
{
"name": "Sylius project",
"homepage": "http://sylius.org"
},
{
"name": "Community contributions",
"homepage": "http://github.com/Sylius/Sylius/contributors"
}
],
"require": {
"php": "^5.6|^7.0",
"sylius/resource": "^1.0"
},
"require-dev": {
"phpspec/phpspec": "^3.0"
},
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-4": { "Sylius\\Component\\Variation\\": "" }
},
"autoload-dev": {
"psr-4": { "Sylius\\Component\\Variation\\spec\\": "spec/" }
},
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{
"type": "path",
"url": "../../*/*"
}
],
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
}
}

View file

@ -1,5 +0,0 @@
suites:
main:
namespace: Sylius\Component\Variation
psr4_prefix: Sylius\Component\Variation
src_path: .

View file

@ -1,103 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Component\Variation\Model;
use Doctrine\Common\Collections\Collection;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Variation\Model\OptionInterface;
use Sylius\Component\Variation\Model\OptionValueInterface;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
final class OptionSpec extends ObjectBehavior
{
public function let()
{
$this->setCurrentLocale('en_US');
$this->setFallbackLocale('en_US');
}
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Component\Variation\Model\Option');
}
function it_implement_Sylius_option_interface()
{
$this->shouldImplement(OptionInterface::class);
}
function it_should_not_have_id_by_default()
{
$this->getId()->shouldReturn(null);
}
function it_has_mutable_code()
{
$this->setCode('O1');
$this->getCode()->shouldReturn('O1');
}
function it_should_not_have_name_by_default()
{
$this->getName()->shouldReturn(null);
}
function its_name_should_be_mutable()
{
$this->setName('Size');
$this->getName()->shouldReturn('Size');
}
function it_returns_name_when_converted_to_string()
{
$this->setName('T-Shirt color');
$this->__toString()->shouldReturn('T-Shirt color');
}
function it_should_initialize_values_collection_by_default()
{
$this->getValues()->shouldHaveType(Collection::class);
}
function it_should_add_value(OptionValueInterface $value)
{
$value->setOption($this)->shouldBeCalled();
$this->addValue($value);
$this->hasValue($value)->shouldReturn(true);
}
function it_should_remove_value(OptionValueInterface $value)
{
$value->setOption($this)->shouldBeCalled();
$this->addValue($value);
$this->hasValue($value)->shouldReturn(true);
$value->setOption(null)->shouldBeCalled();
$this->removeValue($value);
$this->hasValue($value)->shouldReturn(false);
}
function it_should_initialize_creation_date_by_default()
{
$this->getCreatedAt()->shouldHaveType(\DateTime::class);
}
function it_should_not_have_last_update_date_by_default()
{
$this->getUpdatedAt()->shouldReturn(null);
}
}

View file

@ -1,47 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Component\Variation\Model;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Variation\Model\OptionTranslationInterface;
/**
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
final class OptionTranslationSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Component\Variation\Model\OptionTranslation');
}
function it_implement_Sylius_option_interface()
{
$this->shouldImplement(OptionTranslationInterface::class);
}
function it_should_not_have_id_by_default()
{
$this->getId()->shouldReturn(null);
}
function it_should_not_have_name_by_default()
{
$this->getName()->shouldReturn(null);
}
function its_name_should_be_mutable()
{
$this->setName('Size');
$this->getName()->shouldReturn('Size');
}
}

View file

@ -1,121 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Component\Variation\Model;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Variation\Model\OptionInterface;
use Sylius\Component\Variation\Model\OptionValue;
use Sylius\Component\Variation\Model\OptionValueInterface;
/**
* @mixin OptionValue
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
final class OptionValueSpec extends ObjectBehavior
{
public function let()
{
$this->setCurrentLocale('en_US');
$this->setFallbackLocale('en_US');
}
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Component\Variation\Model\OptionValue');
}
function it_is_a_Sylius_product_option_value()
{
$this->shouldImplement(OptionValueInterface::class);
}
function it_should_not_have_id_by_default()
{
$this->getId()->shouldReturn(null);
}
function it_has_mutable_code()
{
$this->setCode('OV1');
$this->getCode()->shouldReturn('OV1');
}
function it_should_not_belong_to_an_option_by_default()
{
$this->getOption()->shouldReturn(null);
}
function it_should_allow_assigning_itself_to_an_option(OptionInterface $option)
{
$this->setOption($option);
$this->getOption()->shouldReturn($option);
}
function it_should_allow_detaching_itself_from_an_option(OptionInterface $option)
{
$this->setOption($option);
$this->getOption()->shouldReturn($option);
$this->setOption(null);
$this->getOption()->shouldReturn(null);
}
function it_should_not_have_value_by_default()
{
$this->getValue()->shouldReturn(null);
}
function its_value_should_be_mutable()
{
$this->setValue('XXL');
$this->getValue()->shouldReturn('XXL');
}
function it_returns_its_value_when_converted_to_string()
{
$this->setValue('S');
$this->__toString()->shouldReturn('S');
}
function it_throws_exception_when_trying_to_get_option_code_without_option_being_assigned()
{
$this
->shouldThrow(\BadMethodCallException::class)
->duringGetOptionCode()
;
}
function it_returns_its_option_code(OptionInterface $option)
{
$option->getCode()->willReturn('01');
$this->setOption($option);
$this->getOptionCode()->shouldReturn('01');
}
function it_throws_exception_when_trying_to_get_name_without_option_being_assigned()
{
$this
->shouldThrow(\BadMethodCallException::class)
->during('getName')
;
}
function it_returns_its_option_name(OptionInterface $option)
{
$option->getName()->willReturn('Size');
$this->setOption($option);
$this->getName()->shouldReturn('Size');
}
}

View file

@ -1,106 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Component\Variation\Model;
use Doctrine\Common\Collections\Collection;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Variation\Model\OptionValueInterface;
use Sylius\Component\Variation\Model\VariableInterface;
use Sylius\Component\Variation\Model\VariantInterface;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
final class VariantSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Component\Variation\Model\Variant');
}
function it_implements_Sylius_variant_interface()
{
$this->shouldImplement(VariantInterface::class);
}
function it_should_not_have_id_by_default()
{
$this->getId()->shouldReturn(null);
}
function it_should_not_belong_to_a_variable_by_default()
{
$this->getObject()->shouldReturn(null);
}
function it_should_allow_assigning_itself_to_a_variable(VariableInterface $variable)
{
$this->setObject($variable);
$this->getObject()->shouldReturn($variable);
}
function it_should_allow_detaching_itself_from_a_variable(VariableInterface $variable)
{
$this->setObject($variable);
$this->getObject()->shouldReturn($variable);
$this->setObject(null);
$this->getObject()->shouldReturn(null);
}
function it_should_not_have_name_by_default()
{
$this->getName()->shouldReturn(null);
}
function its_name_should_be_mutable()
{
$this->setName('Super variant');
$this->getName()->shouldReturn('Super variant');
}
function it_should_initialize_option_values_collection_by_default()
{
$this->getOptions()->shouldHaveType('Doctrine\Common\Collections\Collection');
}
function its_option_values_collection_should_be_mutable(Collection $options)
{
$this->setOptions($options);
$this->getOptions()->shouldReturn($options);
}
function it_should_add_option_value_properly(OptionValueInterface $option)
{
$this->addOption($option);
$this->hasOption($option)->shouldReturn(true);
}
function it_should_remove_option_value_properly(OptionValueInterface $option)
{
$this->addOption($option);
$this->hasOption($option)->shouldReturn(true);
$this->removeOption($option);
$this->hasOption($option)->shouldReturn(false);
}
function it_should_initialize_creation_date_by_default()
{
$this->getCreatedAt()->shouldHaveType('DateTime');
}
function it_should_not_have_last_update_date_by_default()
{
$this->getUpdatedAt()->shouldReturn(null);
}
}