Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Variants] introduce Variant Bundle #1990

Merged
merged 23 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c15c5f0
[Variants] introduce Variant Bundle
dpfaffenbauer May 4, 2022
0118c36
[Variants] fix installing product
dpfaffenbauer May 4, 2022
db6b16f
Update src/CoreShop/Component/Variant/composer.json
dpfaffenbauer May 4, 2022
bd11bdf
[Variants] remove serialize in twig
dpfaffenbauer May 4, 2022
feeebff
Merge branch 'features/variant' of github.com:dpfaffenbauer/CoreShop …
dpfaffenbauer May 4, 2022
680e044
[Variants] fix stan issues
dpfaffenbauer May 4, 2022
f76e24e
[Variants] fix stan issues
dpfaffenbauer May 4, 2022
a905b17
[Variants] fix tests
dpfaffenbauer May 4, 2022
cca02dc
[Variants] fix psalm tests
dpfaffenbauer May 4, 2022
058ad16
[VariantBundle] frontend for variants
breakone May 4, 2022
ab96491
Merge remote-tracking branch 'dpfaffenbauer/features/variant' into fe…
breakone May 4, 2022
e5fd493
[Variants] add ui tests
dpfaffenbauer May 4, 2022
e72b7e6
[Variants] tests
dpfaffenbauer May 4, 2022
b6f1617
[Variants] add sorting to tests
dpfaffenbauer May 4, 2022
c9e1a16
[Variants] add tests for not available variants
dpfaffenbauer May 4, 2022
f698aa0
[Variants] add screenshot command
dpfaffenbauer May 4, 2022
dc5d7fb
[Variants] add full log
dpfaffenbauer May 4, 2022
99dc862
[Variants] add full log
dpfaffenbauer May 4, 2022
90ff923
[Variants] upload pimcore logs on failure
dpfaffenbauer May 4, 2022
c83df6a
[Variants] upload pimcore logs on failure
dpfaffenbauer May 4, 2022
5adbad7
[Tests] reduce log levels and fix behat deprecated notice
dpfaffenbauer May 5, 2022
5c47b1d
[Variants] disable test for now, as I have no idea why it doesn't run
dpfaffenbauer May 5, 2022
0df56fa
[Variants] fix variant-bundle composer.json
dpfaffenbauer May 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/subtree-release
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ split 'src/CoreShop/Component/Tracking' tracking
split 'src/CoreShop/Component/User' user
split 'src/CoreShop/Component/PayumPayment' payum-payment
split 'src/CoreShop/Component/ProductQuantityPriceRules' product-quantity-price-rules
split 'src/CoreShop/Component/Variant' variant

split 'src/CoreShop/Bundle/AddressBundle' address-bundle
split 'src/CoreShop/Bundle/ConfigurationBundle' configuration-bundle
Expand Down Expand Up @@ -71,3 +72,4 @@ split 'src/CoreShop/Bundle/MenuBundle' menu-bundle
split 'src/CoreShop/Bundle/PayumPaymentBundle' payum-payment-bundle
split 'src/CoreShop/Bundle/UserBundle' user-bundle
split 'src/CoreShop/Bundle/OptimisticEntityLockBundle' optimistic-entity-lock-bundle
split 'src/CoreShop/Bundle/VariantBundle' variant-bundle
4 changes: 4 additions & 0 deletions bin/subtree-split
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ remote tracking [email protected]:CoreShop/Tracking.git
remote product-quantity-price-rules [email protected]:CoreShop/ProductQuantityPriceRules.git
remote user [email protected]:CoreShop/User.git
remote payum-payment [email protected]:CoreShop/PayumPayment.git
remote variant [email protected]:CoreShop/Variant.git

remote address-bundle [email protected]:CoreShop/AddressBundle.git
remote configuration-bundle [email protected]:CoreShop/ConfigurationBundle.git
Expand Down Expand Up @@ -105,6 +106,7 @@ remote menu-bundle [email protected]:CoreShop/MenuBundle.git
remote payum-payment-bundle [email protected]:CoreShop/PayumPaymentBundle.git
remote user-bundle [email protected]:CoreShop/UserBundle.git
remote optimistic-entity-lock-bundle [email protected]:CoreShop/OptimisticEntityLockBundle.git
remote variant-bundle [email protected]:CoreShop/VariantBundle.git

split 'src/CoreShop/Component/Resource' resource
split 'src/CoreShop/Component/Registry' registry
Expand Down Expand Up @@ -132,6 +134,7 @@ split 'src/CoreShop/Component/Tracking' tracking
split 'src/CoreShop/Component/ProductQuantityPriceRules' product-quantity-price-rules
split 'src/CoreShop/Component/User' user
split 'src/CoreShop/Component/PayumPayment' payum-payment
split 'src/CoreShop/Component/Variant' variant

split 'src/CoreShop/Bundle/AddressBundle' address-bundle
split 'src/CoreShop/Bundle/ConfigurationBundle' configuration-bundle
Expand Down Expand Up @@ -165,3 +168,4 @@ split 'src/CoreShop/Bundle/MenuBundle' menu-bundle
split 'src/CoreShop/Bundle/UserBundle' user-bundle
split 'src/CoreShop/Bundle/PayumPaymentBundle' payum-payment-bundle
split 'src/CoreShop/Bundle/OptimisticEntityLockBundle' optimistic-entity-lock-bundle
split 'src/CoreShop/Bundle/VariantBundle' variant-bundle
39 changes: 39 additions & 0 deletions features/domain/product/variant/adding_attributes.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@domain @product @variant
Feature: Adding a Attributes

Background:
Given the site operates on a store in "Austria"

Scenario: Create a Color Attribute Group
Given the site has a attribute group "Color"
And the site has a color attribute "red" with hex code "#FF0000" in attribute group
And the site has a color attribute "blue" with hex code "#0000FF" in attribute group
And the site has a color attribute "green" with hex code "#00FF00" in attribute group
Then the attribute group "Color" should have 3 attributes

Scenario: Create a Value Attribute Group
Given the site has a attribute group "Size"
And the site has a value attribute "S" in attribute group
And the site has a value attribute "M" in attribute group
And the site has a value attribute "L" in attribute group
And the site has a value attribute "XL" in attribute group
And the site has a value attribute "XXL" in attribute group
Then the attribute group "Size" should have 5 attributes

Scenario: Create multiple Attribute Group
Given the site has a attribute group "Size"
And the site has a value attribute "S" in attribute group
And the site has a value attribute "M" in attribute group
And the site has a value attribute "L" in attribute group
And the site has a value attribute "XL" in attribute group
And the site has a value attribute "XXL" in attribute group
Then the attribute group "Size" should have 5 attributes
Given the site has a attribute group "Color"
And the site has a color attribute "red" with hex code "#FF0000" in attribute group
And the site has a color attribute "blue" with hex code "#0000FF" in attribute group
And the site has a color attribute "green" with hex code "#00FF00" in attribute group
Then the attribute group "Color" should have 3 attributes
Given the site has a attribute group "Season"
And the site has a value attribute "Winter" in attribute group
And the site has a value attribute "Summer" in attribute group
Then the attribute group "Season" should have 2 attributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@domain @product @variant
Feature: Adding a new Product with Variants

Background:
Given the site operates on a store in "Austria"
And the site has a attribute group "Color"
And the site has a color attribute "red" with hex code "#FF0000" in attribute group
And the site has a color attribute "blue" with hex code "#0000FF" in attribute group
And the site has a color attribute "green" with hex code "#00FF00" in attribute group

Scenario: Create a new product with 3 variants
Given the site has a product "Shoe" priced at 100
And the product is allowed attribute group "Color"
And the product has a variant "red"
And the variant uses attribute color "red"
And the variant is published
And the product has a variant "blue"
And the variant uses attribute color "blue"
And the variant is published
And the product has a variant "green"
And the variant uses attribute color "green"
And the variant is published
Then the product should have 3 variants
57 changes: 57 additions & 0 deletions src/CoreShop/Behat/Context/Domain/VariantContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

declare(strict_types=1);

namespace CoreShop\Behat\Context\Domain;

use Behat\Behat\Context\Context;
use CoreShop\Behat\Service\SharedStorageInterface;
use CoreShop\Component\Core\Model\ProductInterface;
use CoreShop\Component\Taxation\Model\TaxRuleGroupInterface;
use CoreShop\Component\Variant\Model\AttributeGroupInterface;
use Pimcore\Model\DataObject\AbstractObject;
use Pimcore\Model\DataObject\Concrete;
use Webmozart\Assert\Assert;

final class VariantContext implements Context
{
public function __construct(protected SharedStorageInterface $sharedStorage)
{
}

/**
* @Then /^the (attribute group "[^"]+") should have (\d+) attributes$/
*/
public function theAttributeGroupShouldHaveXAttributes(AttributeGroupInterface $attributeGroup, int $count): void
{
Assert::eq(
count($attributeGroup->getChildren()),
$count,
sprintf(
'%d attributes have been found in group "%s".',
count($attributeGroup->getChildren()),
$attributeGroup->getRealFullPath()
)
);
}

/**
* @Then /^the (product "[^"]+") should have (\d+) variants$/
* @Then /^the (product) should have (\d+) variants$/
*/
public function theProductShouldHaveVariants(ProductInterface $product, int $count): void
{
Assert::eq(count($product->getChildren([AbstractObject::OBJECT_TYPE_VARIANT], true)), $count);
}

}
4 changes: 4 additions & 0 deletions src/CoreShop/Behat/Context/Setup/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ public function theProductHasOnHold(ProductInterface $product, int $onHold): voi
/**
* @Given /^the (product "[^"]+") is published$/
* @Given /^the (product) is published$/
* @Given /^the (variant "[^"]+") is published$/
* @Given /^the (variant) is published$/
*/
public function theProductIsPublished(ProductInterface $product): void
{
Expand All @@ -306,6 +308,8 @@ public function theProductIsPublished(ProductInterface $product): void
/**
* @Given /^the (product "[^"]+") is not published$/
* @Given /^the (product) is not published$/
* @Given /^the (variant "[^"]+") is not published$/
* @Given /^the (variant) is not published$/
*/
public function theProductIsNotPublished(ProductInterface $product): void
{
Expand Down
164 changes: 164 additions & 0 deletions src/CoreShop/Behat/Context/Setup/VariantContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

declare(strict_types=1);

namespace CoreShop\Behat\Context\Setup;

use Behat\Behat\Context\Context;
use CoreShop\Behat\Service\SharedStorageInterface;
use CoreShop\Component\Core\Model\ProductInterface;
use CoreShop\Component\Resource\Factory\FactoryInterface;
use CoreShop\Component\Variant\Model\AttributeColorInterface;
use CoreShop\Component\Variant\Model\AttributeGroupInterface;
use CoreShop\Component\Variant\Model\AttributeValueInterface;
use CoreShop\Component\Variant\Model\ProductVariantAwareInterface;
use Pimcore\File;
use Pimcore\Model\DataObject\Data\RgbaColor;
use Pimcore\Model\DataObject\Service;

final class VariantContext implements Context
{
public function __construct(
private SharedStorageInterface $sharedStorage,
private FactoryInterface $attributeGroupFactory,
private FactoryInterface $attributeColorFactory,
private FactoryInterface $attributeValueFactory,
) {
}

/**
* @Given /^the site has a attribute group "([^"]+)"$/
*/
public function thereIsAAttributeGroup($name): void
{
/**
* @var AttributeGroupInterface $attributeGroup
*/
$attributeGroup = $this->attributeGroupFactory->createNew();

$attributeGroup->setName($name);
$attributeGroup->setParent(Service::createFolderByPath('/attributes'));
$attributeGroup->setKey(File::getValidFilename($name));
$attributeGroup->setPublished(true);
$attributeGroup->save();

$this->sharedStorage->set('attribute-group', $attributeGroup);
}

/**
* @Given /^the site has a color attribute "([^"]+)" with hex code "([^"]+)" in (attribute group "[^"]+")$/
* @Given /^the site has a color attribute "([^"]+)" with hex code "([^"]+)" in (attribute group)$/
*/
public function thereIsAColorAttributeInGroup(string $name, string $hex, AttributeGroupInterface $group): void
{
/**
* @var AttributeColorInterface $attribute
*/
$attribute = $this->attributeColorFactory->createNew();

$attribute->setName($name);
$attribute->setValueText($name);
$attribute->setValueColor($this->hex2rgba($hex));
$attribute->setParent($group);
$attribute->setKey(File::getValidFilename($name));
$attribute->setPublished(true);
$attribute->save();

$this->sharedStorage->set('attribute', $attribute);
}

/**
* @Given /^the site has a value attribute "([^"]+)" in (attribute group "[^"]+")$/
* @Given /^the site has a value attribute "([^"]+)" in (attribute group)$/
*/
public function thereIsAValueAttributeInGroup(string $name, AttributeGroupInterface $group): void
{
/**
* @var AttributeValueInterface $attribute
*/
$attribute = $this->attributeValueFactory->createNew();

$attribute->setName($name);
$attribute->setValueText($name);
$attribute->setParent($group);
$attribute->setKey(File::getValidFilename($name));
$attribute->setPublished(true);
$attribute->save();

$this->sharedStorage->set('attribute', $attribute);
}

/**
* @Given /^the (product "[^"]+") is allowed (attribute group "[^"]+")$/
* @Given /^the (product) is allowed (attribute group "[^"]+")$/
*/
public function theProductIsAllowedAttributeGroup(
ProductVariantAwareInterface $product,
AttributeGroupInterface $group
): void {
$groups = $product->getAllowedAttributeGroups() ?? [];

$groups[] = $group;

$product->setAllowedAttributeGroups($groups);
$product->save();
}

/**
* @Given /^the (variant "[^"]+") uses (attribute color "[^"]+")$/
* @Given /^the (variant) uses (attribute color "[^"]+")$/
*/
public function theVariantUsesAttributeColor(
ProductVariantAwareInterface $product,
AttributeColorInterface $attributeColor
): void {
$attributes = $product->getAttributes() ?? [];

$attributes[] = $attributeColor;

$product->setAttributes($attributes);
$product->save();
}

private function hex2rgba(string $color, float $opacity = 1): RgbaColor
{
// Sanitize $color if "#" is provided
if ($color[0] === '#') {
$color = substr($color, 1);
}

// Check if color has 6 or 3 characters and get values
if (strlen($color) === 6) {
$hex = array($color[0].$color[1], $color[2].$color[3], $color[4].$color[5]);
} elseif (strlen($color) === 3) {
$hex = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
} else {
return new RgbaColor(0, 0, 0, 0);
}

// Convert hexadec to rgb
$rgb = array_map('hexdec', $hex);

// Check if opacity is set(rgba or rgb)
if ($opacity) {
if (abs($opacity) > 1) {
$opacity = 1.0;
}

return new RgbaColor($rgb[0], $rgb[1], $rgb[2], $opacity);
}

return new RgbaColor($rgb[0], $rgb[1], $rgb[2]);

}
}
Loading