-
Notifications
You must be signed in to change notification settings - Fork 4
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
Configure number of synchronised products in Channel configuration #32
Merged
lchrusciel
merged 7 commits into
CommerceWeavers:main
from
Zales0123:number-in-configuration
Jul 29, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e8a9c3c
[Behat] Configure number of synchronised items
Zales0123 ccfa813
Configure number of synchronised products on Channel
Zales0123 270342b
Use number configured on channel
Zales0123 9e3efb5
[Behat] Number of products on channel configuration
Zales0123 c44433d
CS fixes
Zales0123 94d8dbf
PR review fixes
Zales0123 a6a4862
CS fixes
Zales0123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<container | ||
xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" | ||
> | ||
<services> | ||
<service id="CommerceWeavers\SyliusAlsoBoughtPlugin\Form\Extension\ChannelTypeExtension" public="true"> | ||
<tag name="form.type_extension" /> | ||
</service> | ||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
features/managing_number_of_items_to_synchronize_on_channel.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@managing_channels | ||
Feature: Managing number of items to synchronize on channel | ||
In order to change the number of items that are synchronised as bought together products | ||
As an Administrator | ||
I want to be able to edit their number on channel configuration | ||
|
||
Background: | ||
Given the store operates on a channel named "Web Channel" | ||
And I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Seeing the default number of synchronised products | ||
When I want to modify a channel "Web Channel" | ||
Then the number of synchronised products should be 10 | ||
|
||
@ui | ||
Scenario: Modifying the number of synchronised products | ||
When I want to modify a channel "Web Channel" | ||
And I change the number of synchronised products to 5 | ||
And I save my changes | ||
Then I should be notified that it has been successfully edited | ||
And the number of synchronised products should be 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeaversSyliusAlsoBoughtMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20240408131819 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add synchronised products number for channel'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE sylius_channel ADD number_of_synchronised_products INT DEFAULT 10 NOT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE sylius_channel DROP number_of_synchronised_products'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusAlsoBoughtPlugin\Entity; | ||
|
||
interface BoughtTogetherConfigurableChannelInterface | ||
{ | ||
public function setNumberOfSynchronisedProducts(int $number): void; | ||
|
||
public function getNumberOfSynchronisedProducts(): int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,24 @@ | ||||||
<?php | ||||||
|
||||||
declare(strict_types=1); | ||||||
|
||||||
namespace CommerceWeavers\SyliusAlsoBoughtPlugin\Entity; | ||||||
|
||||||
use Doctrine\ORM\Mapping as ORM; | ||||||
|
||||||
trait BoughtTogetherConfigurableChannelTrait | ||||||
{ | ||||||
/** @ORM\Column(name="number_of_synchronised_products", type="integer", nullable=false, options={"default": 10}) */ | ||||||
#[ORM\Column(name: 'number_of_synchronised_products', type: 'integer', nullable: false, options: ['default' => 10])] | ||||||
private int $numberOfSynchronisedProducts = 10; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #32 (comment) 😅 |
||||||
|
||||||
public function setNumberOfSynchronisedProducts(int $number): void | ||||||
{ | ||||||
$this->numberOfSynchronisedProducts = $number; | ||||||
} | ||||||
|
||||||
public function getNumberOfSynchronisedProducts(): int | ||||||
{ | ||||||
return $this->numberOfSynchronisedProducts; | ||||||
} | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusAlsoBoughtPlugin\Form\Extension; | ||
|
||
use Sylius\Bundle\ChannelBundle\Form\Type\ChannelType; | ||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\Extension\Core\Type\NumberType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
final class ChannelTypeExtension extends AbstractTypeExtension | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('numberOfSynchronisedProducts', NumberType::class, [ | ||
'label' => 'commerce_weavers_sylius_also_bought.form.channel.number_of_synchronised_products', | ||
'required' => true, | ||
]) | ||
; | ||
} | ||
|
||
public static function getExtendedTypes(): iterable | ||
{ | ||
yield ChannelType::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusAlsoBoughtPlugin\Provider; | ||
|
||
use CommerceWeavers\SyliusAlsoBoughtPlugin\Entity\BoughtTogetherConfigurableChannelInterface; | ||
use Sylius\Component\Core\Model\ProductInterface; | ||
|
||
final class SynchronizableProductsNumberProvider implements SynchronizableProductsNumberProviderInterface | ||
{ | ||
public function __construct(private int $defaultNumberOfProducts = 10) | ||
{ | ||
} | ||
|
||
public function getNumberOfProductsToSynchronise(ProductInterface $product): int | ||
{ | ||
$channels = $product->getChannels(); | ||
|
||
$numberOfProducts = 0; | ||
/** @var BoughtTogetherConfigurableChannelInterface $channel */ | ||
foreach ($channels as $channel) { | ||
$numberOfProducts = max($numberOfProducts, $channel->getNumberOfSynchronisedProducts()); | ||
} | ||
|
||
if ($numberOfProducts <= 0) { | ||
return $this->defaultNumberOfProducts; | ||
} | ||
|
||
return $numberOfProducts; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just because in different places, we already use the US version with
z
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for twig tempalte file name etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me change that in a separate PR, as it would require also changing the property name and a bunch of other stuff :D