mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Core][Product][Web] Remove deleted methods usage on Product
This commit is contained in:
parent
5dec350d2f
commit
9f32bf6003
9 changed files with 68 additions and 27 deletions
|
|
@ -362,7 +362,7 @@ final class OrderContext implements Context
|
|||
/** @var OrderItemInterface $item */
|
||||
$item = $this->orderItemFactory->createNew();
|
||||
$item->setVariant($productVariant);
|
||||
$item->setUnitPrice($price);
|
||||
$item->setUnitPrice($productVariant->getPrice());
|
||||
|
||||
$this->itemQuantityModifier->modify($item, $quantity);
|
||||
|
||||
|
|
|
|||
|
|
@ -402,10 +402,10 @@ final class ProductContext implements Context
|
|||
private function createProduct($productName, $price = 0)
|
||||
{
|
||||
/** @var ProductInterface $product */
|
||||
$product = $this->productFactory->createNew();
|
||||
$product = $this->productFactory->createWithVariant();
|
||||
|
||||
$product->setName($productName);
|
||||
$product->setPrice($price);
|
||||
$product->getVariants()->first()->setPrice($price);
|
||||
$product->setCode($this->convertToCode($productName));
|
||||
$product->getMasterVariant()->setCode($product->getCode());
|
||||
|
||||
|
|
|
|||
|
|
@ -34,16 +34,12 @@ class ProductContext extends DefaultContext
|
|||
|
||||
$product->setCurrentLocale($this->getContainer()->getParameter('locale'));
|
||||
$product->setName(trim($data['name']));
|
||||
<<<<<<< daaa73c203015544dad10b35e84adde66d5cc81b
|
||||
|
||||
$code = isset($data['sku']) ? $data['sku'] : $this->generateCode($data['name']);
|
||||
$product->setCode($code);
|
||||
|
||||
$product->getMasterVariant()->setPrice((int) round($data['price'] * 100));
|
||||
$product->getMasterVariant()->setCode($code);
|
||||
=======
|
||||
$product->getVariants()->first()->setPrice((int) round($data['price'] * 100));
|
||||
>>>>>>> [Core][Product][Variation] Remove all masterVariant usages
|
||||
$product->getFirstVariant()->setCode($code);
|
||||
$product->getFirstVariant()->setPrice((int) round($data['price'] * 100));
|
||||
|
||||
if (!empty($data['options'])) {
|
||||
foreach (explode(',', $data['options']) as $option) {
|
||||
|
|
@ -369,7 +365,7 @@ class ProductContext extends DefaultContext
|
|||
if (null === $product) {
|
||||
$product = $this->getRepository('product')->createNew();
|
||||
$product->setName($name);
|
||||
$product->setPrice(0);
|
||||
$product->getVariants()->first()->setPrice(0);
|
||||
$product->setDescription('Lorem ipsum');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class ServicesPass implements CompilerPassInterface
|
|||
$translatableFactoryDefinition,
|
||||
new Reference('sylius.repository.product_archetype'),
|
||||
new Reference('sylius.builder.product_archetype'),
|
||||
new Reference('sylius.factory.product_variant'),
|
||||
]);
|
||||
|
||||
$container->setDefinition('sylius.factory.product', $decoratedProductFactoryDefinition);
|
||||
|
|
|
|||
|
|
@ -26,16 +26,6 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% if product.images|length > 0 %}
|
||||
<hr>
|
||||
<div id="gallery">
|
||||
{% for image in product.images %}
|
||||
<a href="{{ image.path|imagine_filter('sylius_large') }}" title="{{ product.name }}">
|
||||
<img class="img-rounded" src="{{ image.path|imagine_filter('sylius_small') }}" alt="{{ product.name }}" />
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
namespace Sylius\Component\Product\Factory;
|
||||
|
||||
use Sylius\Component\Archetype\Builder\ArchetypeBuilderInterface;
|
||||
use Sylius\Component\Product\Model\ProductInterface;
|
||||
use Sylius\Component\Resource\Factory\FactoryInterface;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
|
||||
|
|
@ -36,16 +37,23 @@ class ProductFactory implements ProductFactoryInterface
|
|||
*/
|
||||
private $archetypeBuilder;
|
||||
|
||||
/**
|
||||
* @var FactoryInterface
|
||||
*/
|
||||
private $variantFactory;
|
||||
|
||||
/**
|
||||
* @param FactoryInterface $factory
|
||||
* @param RepositoryInterface $archetypeRepository
|
||||
* @param ArchetypeBuilderInterface $archetypeBuilder
|
||||
* @param FactoryInterface $variantFactory
|
||||
*/
|
||||
public function __construct(FactoryInterface $factory, RepositoryInterface $archetypeRepository, ArchetypeBuilderInterface $archetypeBuilder)
|
||||
public function __construct(FactoryInterface $factory, RepositoryInterface $archetypeRepository, ArchetypeBuilderInterface $archetypeBuilder, FactoryInterface $variantFactory)
|
||||
{
|
||||
$this->factory = $factory;
|
||||
$this->archetypeRepository = $archetypeRepository;
|
||||
$this->archetypeBuilder = $archetypeBuilder;
|
||||
$this->variantFactory = $variantFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -64,6 +72,19 @@ class ProductFactory implements ProductFactoryInterface
|
|||
return $this->factory->createNew();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createWithVariant()
|
||||
{
|
||||
$variant = $this->variantFactory->createNew();
|
||||
|
||||
$product = $this->factory->createNew();
|
||||
$product->addVariant($variant);
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ use Sylius\Component\Resource\Factory\TranslatableFactoryInterface;
|
|||
*/
|
||||
interface ProductFactoryInterface extends TranslatableFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @return ProductInterface
|
||||
*/
|
||||
public function createWithVariant();
|
||||
|
||||
/**
|
||||
* @param mixed $archetypeCode
|
||||
*
|
||||
|
|
|
|||
|
|
@ -29,9 +29,10 @@ class ProductFactorySpec extends ObjectBehavior
|
|||
function let(
|
||||
FactoryInterface $factory,
|
||||
RepositoryInterface $archetypeRepository,
|
||||
ArchetypeBuilderInterface $archetypeBuilder
|
||||
ArchetypeBuilderInterface $archetypeBuilder,
|
||||
FactoryInterface $variantFactory
|
||||
) {
|
||||
$this->beConstructedWith($factory, $archetypeRepository, $archetypeBuilder);
|
||||
$this->beConstructedWith($factory, $archetypeRepository, $archetypeBuilder, $variantFactory);
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
|
|
@ -51,13 +52,32 @@ class ProductFactorySpec extends ObjectBehavior
|
|||
$this->createNew()->shouldReturn($product);
|
||||
}
|
||||
|
||||
function it_creates_new_product_with_variant(
|
||||
FactoryInterface $factory,
|
||||
ProductInterface $product,
|
||||
VariantInterface $variant,
|
||||
FactoryInterface $variantFactory
|
||||
) {
|
||||
$variantFactory->createNew()->willReturn($variant);
|
||||
|
||||
$factory->createNew()->willReturn($product);
|
||||
$product->addVariant($variant)->shouldBeCalled();
|
||||
|
||||
$this->createWithVariant()->shouldReturn($product);
|
||||
}
|
||||
|
||||
function it_creates_new_product_from_archetype(
|
||||
FactoryInterface $factory,
|
||||
ProductInterface $product,
|
||||
RepositoryInterface $archetypeRepository,
|
||||
ArchetypeBuilderInterface $archetypeBuilder,
|
||||
ArchetypeInterface $archetype
|
||||
ArchetypeInterface $archetype,
|
||||
VariantInterface $variant,
|
||||
FactoryInterface $variantFactory
|
||||
) {
|
||||
$variantFactory->createNew()->willReturn($variant);
|
||||
$product->addVariant($variant)->shouldBeCalled();
|
||||
|
||||
$factory->createNew()->willReturn($product);
|
||||
|
||||
$archetypeRepository->findOneBy(['code' => 'book'])->willReturn($archetype);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
Sylius\Component\Core\Model\ProductVariant:
|
||||
productVariant1:
|
||||
<<<<<<< 5dec350d2f16a9384f267d1dd5c3db27f4ce9a25
|
||||
master: true
|
||||
code: MUG_1
|
||||
productVariant2:
|
||||
|
|
@ -8,6 +9,16 @@ Sylius\Component\Core\Model\ProductVariant:
|
|||
productVariant3:
|
||||
master: true
|
||||
code: MUG_3
|
||||
=======
|
||||
setPrice: [20]
|
||||
setSku: [mug1]
|
||||
productVariant2:
|
||||
setPrice: [20]
|
||||
setSku: [mug2]
|
||||
productVariant3:
|
||||
setPrice: [20]
|
||||
setSku: [mug3]
|
||||
>>>>>>> [Core][Product][Web] Remove deleted methods usage on Product
|
||||
|
||||
Sylius\Component\Core\Model\Product:
|
||||
product1:
|
||||
|
|
@ -15,21 +26,18 @@ Sylius\Component\Core\Model\Product:
|
|||
currentLocale: en_US
|
||||
currentTranslation: @productTranslation1
|
||||
variants: [@productVariant1]
|
||||
setPrice: [20]
|
||||
code: MUG_SW
|
||||
product2:
|
||||
updatedAt: 2015-10-04
|
||||
currentLocale: en_US
|
||||
currentTranslation: @productTranslation2
|
||||
variants: [@productVariant2]
|
||||
setPrice: [20]
|
||||
code: MUG_LOTR
|
||||
product3:
|
||||
updatedAt: 2015-10-05
|
||||
currentLocale: en_US
|
||||
currentTranslation: @productTranslation3
|
||||
variants: [@productVariant3]
|
||||
setPrice: [20]
|
||||
code: MUG_BB
|
||||
|
||||
Sylius\Component\Core\Model\ProductTranslation:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue