mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
Merge pull request #6731 from Zales0123/select-channel-on-shipping-and-payment-method-forms
[Core][Admin] Select channel on shipping and payment method's forms
This commit is contained in:
commit
9ed09b10c2
58 changed files with 692 additions and 484 deletions
48
app/migrations/Version20161115142753.php
Normal file
48
app/migrations/Version20161115142753.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Sylius\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
class Version20161115142753 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('CREATE TABLE sylius_payment_method_channels (payment_method_id INT NOT NULL, channel_id INT NOT NULL, INDEX IDX_543AC0CC5AA1164F (payment_method_id), INDEX IDX_543AC0CC72F5A1AA (channel_id), PRIMARY KEY(payment_method_id, channel_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
|
||||
$this->addSql('CREATE TABLE sylius_shipping_method_channels (shipping_method_id INT NOT NULL, channel_id INT NOT NULL, INDEX IDX_2D9833355F7D6850 (shipping_method_id), INDEX IDX_2D98333572F5A1AA (channel_id), PRIMARY KEY(shipping_method_id, channel_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
|
||||
$this->addSql('ALTER TABLE sylius_payment_method_channels ADD CONSTRAINT FK_543AC0CC5AA1164F FOREIGN KEY (payment_method_id) REFERENCES sylius_payment_method (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE sylius_payment_method_channels ADD CONSTRAINT FK_543AC0CC72F5A1AA FOREIGN KEY (channel_id) REFERENCES sylius_channel (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE sylius_shipping_method_channels ADD CONSTRAINT FK_2D9833355F7D6850 FOREIGN KEY (shipping_method_id) REFERENCES sylius_shipping_method (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE sylius_shipping_method_channels ADD CONSTRAINT FK_2D98333572F5A1AA FOREIGN KEY (channel_id) REFERENCES sylius_channel (id) ON DELETE CASCADE');
|
||||
$this->addSql('DROP TABLE sylius_channel_payment_methods');
|
||||
$this->addSql('DROP TABLE sylius_channel_shipping_methods');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('CREATE TABLE sylius_channel_payment_methods (channel_id INT NOT NULL, payment_method_id INT NOT NULL, INDEX IDX_B0C0002B72F5A1AA (channel_id), INDEX IDX_B0C0002B5AA1164F (payment_method_id), PRIMARY KEY(channel_id, payment_method_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
|
||||
$this->addSql('CREATE TABLE sylius_channel_shipping_methods (channel_id INT NOT NULL, shipping_method_id INT NOT NULL, INDEX IDX_6858B18E72F5A1AA (channel_id), INDEX IDX_6858B18E5F7D6850 (shipping_method_id), PRIMARY KEY(channel_id, shipping_method_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
|
||||
$this->addSql('ALTER TABLE sylius_channel_payment_methods ADD CONSTRAINT FK_B0C0002B5AA1164F FOREIGN KEY (payment_method_id) REFERENCES sylius_payment_method (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE sylius_channel_payment_methods ADD CONSTRAINT FK_B0C0002B72F5A1AA FOREIGN KEY (channel_id) REFERENCES sylius_channel (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE sylius_channel_shipping_methods ADD CONSTRAINT FK_6858B18E5F7D6850 FOREIGN KEY (shipping_method_id) REFERENCES sylius_shipping_method (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE sylius_channel_shipping_methods ADD CONSTRAINT FK_6858B18E72F5A1AA FOREIGN KEY (channel_id) REFERENCES sylius_channel (id) ON DELETE CASCADE');
|
||||
$this->addSql('DROP TABLE sylius_payment_method_channels');
|
||||
$this->addSql('DROP TABLE sylius_shipping_method_channels');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
@managing_channels
|
||||
Feature: Selecting available payment methods for a channel
|
||||
In order to give an opportunity of choosing different payment methods to customers
|
||||
As an Administrator
|
||||
I want to be able to select available payment methods
|
||||
|
||||
Background:
|
||||
Given the store has currency "Euro"
|
||||
And the store has locale "English (United States)"
|
||||
And the store has a payment method "Offline" with a code "OFF"
|
||||
And I am logged in as an administrator
|
||||
|
||||
@ui
|
||||
Scenario: Adding a new channel with payment methods
|
||||
Given I want to create a new channel
|
||||
When I specify its code as MOBILE
|
||||
And I name it "Mobile store"
|
||||
And I select the "Offline" payment method
|
||||
And I choose "Euro" as a default currency
|
||||
And I choose "English (United States)" as a default locale
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And the "Offline" payment method should be available for the "Mobile store" channel
|
||||
|
||||
@ui
|
||||
Scenario: Adding payment methods to an existing channel
|
||||
Given the store operates on a channel named "Web store"
|
||||
And I want to modify this channel
|
||||
When I select the "Offline" payment method
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And the "Offline" payment method should be available for the "Web store" channel
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
@managing_channels
|
||||
Feature: Selecting available shipping methods for a channel
|
||||
In order to give an opportunity of choosing different shipping methods to customer
|
||||
As an Administrator
|
||||
I want to be able to select available shipping methods
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "United States"
|
||||
And the store has currency "Euro"
|
||||
And the store has locale "English (United States)"
|
||||
And the store allows shipping with "UPS Carrier" identified by "UPS_CARRIER"
|
||||
And I am logged in as an administrator
|
||||
|
||||
@ui
|
||||
Scenario: Adding a new channel with shipping methods
|
||||
Given I want to create a new channel
|
||||
When I specify its code as MOBILE
|
||||
And I name it "Mobile store"
|
||||
And I select the "UPS Carrier" shipping method
|
||||
And I choose "Euro" as a default currency
|
||||
And I choose "English (United States)" as a default locale
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And the "UPS Carrier" shipping method should be available for the "Mobile store" channel
|
||||
|
||||
@ui
|
||||
Scenario: Adding shipping methods to an existing channel
|
||||
Given the store operates on a channel named "Web store"
|
||||
And I want to modify this channel
|
||||
When I select the "UPS Carrier" shipping method
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And the "UPS Carrier" shipping method should be available for the "Web store" channel
|
||||
|
|
@ -5,7 +5,7 @@ Feature: Adding a new payment method
|
|||
I want to add a new payment method to the registry
|
||||
|
||||
Background:
|
||||
Given the store is available in "English (United States)"
|
||||
Given the store operates on a single channel in "United States"
|
||||
And I am logged in as an administrator
|
||||
|
||||
@ui
|
||||
|
|
@ -40,3 +40,15 @@ Feature: Adding a new payment method
|
|||
Then I should be notified that it has been successfully created
|
||||
And the payment method "Offline" should appear in the registry
|
||||
And the payment method "Offline" should have instructions "Bank account: 0000 1111 2222 3333" in "English (United States)"
|
||||
|
||||
@ui
|
||||
Scenario: Adding a new payment method for channel
|
||||
Given I want to create a new payment method
|
||||
When I name it "Paypal Express Checkout" in "English (United States)"
|
||||
And I specify its code as "PEC"
|
||||
And I choose "Paypal Express Checkout" gateway
|
||||
And make it available in channel "United States"
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And the payment method "Paypal Express Checkout" should appear in the registry
|
||||
And the payment method "Paypal Express Checkout" should be available in channel "United States"
|
||||
|
|
|
|||
|
|
@ -46,3 +46,18 @@ Feature: Adding a new shipping method
|
|||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And the shipping method "FedEx Carrier" should appear in the registry
|
||||
|
||||
@ui @javascript
|
||||
Scenario: Adding a new shipping method for channel
|
||||
Given I want to create a new shipping method
|
||||
When I specify its code as "FED_EX_CARRIER"
|
||||
And I name it "FedEx Carrier" in "English (United States)"
|
||||
And I describe it as "FedEx Carrier shipping method for United States" in "English (United States)"
|
||||
And I define it for the "United States" zone
|
||||
And I make it available in channel "United States"
|
||||
And I choose "Flat rate per unit" calculator
|
||||
And I specify its amount as 20
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And the shipment method "FedEx Carrier" should appear in the registry
|
||||
And the shipment method "FedEx Carrier" should be available in channel "United States"
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ use Behat\Behat\Context\Context;
|
|||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Sylius\Behat\Service\SharedStorageInterface;
|
||||
use Sylius\Bundle\CoreBundle\Test\Services\PaymentMethodNameToGatewayConverterInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentMethodInterface;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Model\PaymentMethodInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentMethodTranslationInterface;
|
||||
use Sylius\Component\Payment\Repository\PaymentMethodRepositoryInterface;
|
||||
use Sylius\Component\Resource\Factory\FactoryInterface;
|
||||
|
|
@ -158,8 +159,7 @@ final class PaymentContext implements Context
|
|||
$paymentMethod->setDescription($description);
|
||||
|
||||
if ($addForCurrentChannel && $this->sharedStorage->has('channel')) {
|
||||
$channel = $this->sharedStorage->get('channel');
|
||||
$channel->addPaymentMethod($paymentMethod);
|
||||
$paymentMethod->addChannel($this->sharedStorage->get('channel'));
|
||||
}
|
||||
|
||||
$this->sharedStorage->set('payment_method', $paymentMethod);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use Sylius\Behat\Service\SharedStorageInterface;
|
|||
use Sylius\Component\Addressing\Model\ZoneInterface;
|
||||
use Sylius\Component\Addressing\Repository\ZoneRepositoryInterface;
|
||||
use Sylius\Component\Core\Formatter\StringInflector;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Model\ShippingMethodInterface;
|
||||
use Sylius\Component\Resource\Factory\FactoryInterface;
|
||||
use Sylius\Component\Shipping\Calculator\DefaultCalculators;
|
||||
|
|
@ -255,8 +256,7 @@ final class ShippingContext implements Context
|
|||
$shippingMethod->setEnabled($enabled);
|
||||
|
||||
if ($addForCurrentChannel && $this->sharedStorage->has('channel')) {
|
||||
$channel = $this->sharedStorage->get('channel');
|
||||
$channel->addShippingMethod($shippingMethod);
|
||||
$shippingMethod->addChannel($this->sharedStorage->get('channel'));
|
||||
}
|
||||
|
||||
$this->shippingMethodRepository->add($shippingMethod);
|
||||
|
|
|
|||
|
|
@ -415,39 +415,6 @@ final class ManagingChannelsContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I select the :shippingMethodName shipping method
|
||||
*/
|
||||
public function iSelectTheShippingMethod($shippingMethodName)
|
||||
{
|
||||
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
|
||||
|
||||
$currentPage->chooseShippingMethod($shippingMethodName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the :shippingMethodName shipping method should be available for the :channel channel
|
||||
*/
|
||||
public function theShippingMethodShouldBeAvailableForTheChannel($shippingMethodName, ChannelInterface $channel)
|
||||
{
|
||||
$this->updatePage->open(['id' => $channel->getId()]);
|
||||
|
||||
Assert::true(
|
||||
$this->updatePage->isShippingMethodChosen($shippingMethodName),
|
||||
sprintf('Shipping method %s should be selected but it is not', $shippingMethodName)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I select the :paymentMethodName payment method
|
||||
*/
|
||||
public function iSelectThePaymentMethod($paymentMethodName)
|
||||
{
|
||||
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
|
||||
|
||||
$currentPage->choosePaymentMethod($paymentMethodName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I select the :taxZone as default tax zone
|
||||
*/
|
||||
|
|
@ -476,19 +443,6 @@ final class ManagingChannelsContext implements Context
|
|||
$currentPage->chooseTaxCalculationStrategy($taxCalculationStrategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the :paymentMethodName payment method should be available for the :channel channel
|
||||
*/
|
||||
public function thePaymentMethodShouldBeAvailableForTheChannel($paymentMethodName, ChannelInterface $channel)
|
||||
{
|
||||
$this->updatePage->open(['id' => $channel->getId()]);
|
||||
|
||||
Assert::true(
|
||||
$this->updatePage->isPaymentMethodChosen($paymentMethodName),
|
||||
sprintf('Payment method %s should be selected, but it is not', $paymentMethodName)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the default tax zone for the :channel channel should be :taxZone
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
|
|||
use Sylius\Behat\Page\Admin\PaymentMethod\CreatePageInterface;
|
||||
use Sylius\Behat\Page\Admin\PaymentMethod\UpdatePageInterface;
|
||||
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentMethodInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
|
|
@ -171,6 +172,14 @@ final class ManagingPaymentMethodsContext implements Context
|
|||
$this->createPage->describeIt($description, $language);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When make it available in channel :channel
|
||||
*/
|
||||
public function iMakeItAvailableInChannel($channel)
|
||||
{
|
||||
$this->createPage->checkChannel($channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I set its instruction as :instructions in :language
|
||||
*/
|
||||
|
|
@ -347,6 +356,21 @@ final class ManagingPaymentMethodsContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the payment method :paymentMethod should be available in channel :channelName
|
||||
*/
|
||||
public function thePaymentMethodShouldBeAvailableInChannel(
|
||||
PaymentMethodInterface $paymentMethod,
|
||||
$channelName
|
||||
) {
|
||||
$this->iWantToModifyAPaymentMethod($paymentMethod);
|
||||
|
||||
Assert::true(
|
||||
$this->updatePage->isAvailableInChannel($channelName),
|
||||
sprintf('Payment method should be available in channel "%s" but it does not.', $channelName)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^(this payment method) should no longer exist in the registry$/
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -141,6 +141,14 @@ final class ManagingShippingMethodsContext implements Context
|
|||
$this->createPage->specifyAmount($amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I make it available in channel :channel
|
||||
*/
|
||||
public function iMakeItAvaialbelInChannel($channel)
|
||||
{
|
||||
$this->createPage->checkChannel($channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I add it
|
||||
* @When I try to add it
|
||||
|
|
@ -181,6 +189,21 @@ final class ManagingShippingMethodsContext implements Context
|
|||
$this->theShipmentMethodShouldAppearInTheRegistry($shippingMethod->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the shipment method :shippingMethod should be available in channel :channelName
|
||||
*/
|
||||
public function theShippingMethodShouldBeAvailableInChannel(
|
||||
ShippingMethodInterface $shippingMethod,
|
||||
$channelName
|
||||
) {
|
||||
$this->iWantToModifyAShippingMethod($shippingMethod);
|
||||
|
||||
Assert::true(
|
||||
$this->updatePage->isAvailableInChannel($channelName),
|
||||
sprintf('Shipping method should be available in channel "%s" but it does not.', $channelName)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that shipping method with this code already exists
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -59,22 +59,6 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
|||
$this->getDocument()->selectFieldOption('Locales', $language);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function chooseShippingMethod($shippingMethod)
|
||||
{
|
||||
$this->getDocument()->selectFieldOption('Shipping Methods', $shippingMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function choosePaymentMethod($paymentMethod)
|
||||
{
|
||||
$this->getDocument()->selectFieldOption('Payment Methods', $paymentMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -57,16 +57,6 @@ interface CreatePageInterface extends BaseCreatePageInterface
|
|||
*/
|
||||
public function chooseCurrency($currencyCode);
|
||||
|
||||
/**
|
||||
* @param string $shippingMethod
|
||||
*/
|
||||
public function chooseShippingMethod($shippingMethod);
|
||||
|
||||
/**
|
||||
* @param string $paymentMethod
|
||||
*/
|
||||
public function choosePaymentMethod($paymentMethod);
|
||||
|
||||
/**
|
||||
* @param string $taxZone
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -72,30 +72,6 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
return $this->getElement('currencies')->find('named', array('option', $currencyCode))->hasAttribute('selected');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function chooseShippingMethod($shippingMethod)
|
||||
{
|
||||
$this->getDocument()->selectFieldOption('Shipping Methods', $shippingMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isShippingMethodChosen($shippingMethod)
|
||||
{
|
||||
return $this->getElement('shipping_methods')->find('named', array('option', $shippingMethod))->hasAttribute('selected');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function choosePaymentMethod($paymentMethod)
|
||||
{
|
||||
$this->getDocument()->selectFieldOption('Payment Methods', $paymentMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -112,14 +88,6 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
$this->getDocument()->selectFieldOption('Tax calculation strategy', $taxZone);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isPaymentMethodChosen($paymentMethod)
|
||||
{
|
||||
return $this->getElement('payment_methods')->find('named', array('option', $paymentMethod))->hasAttribute('selected');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -176,8 +144,6 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
'enabled' => '#sylius_channel_enabled',
|
||||
'locales' => '#sylius_channel_locales',
|
||||
'name' => '#sylius_channel_name',
|
||||
'payment_methods' => '#sylius_channel_paymentMethods',
|
||||
'shipping_methods' => '#sylius_channel_shippingMethods',
|
||||
'tax_calculation_strategy' => '#sylius_channel_taxCalculationStrategy',
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,23 +62,6 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
|
|||
*/
|
||||
public function isCurrencyChosen($currencyCode);
|
||||
|
||||
/**
|
||||
* @param string $shippingMethod
|
||||
*/
|
||||
public function chooseShippingMethod($shippingMethod);
|
||||
|
||||
/**
|
||||
* @param string $shippingMethod
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isShippingMethodChosen($shippingMethod);
|
||||
|
||||
/**
|
||||
* @param string $paymentMethod
|
||||
*/
|
||||
public function choosePaymentMethod($paymentMethod);
|
||||
|
||||
/**
|
||||
* @param string $taxZone
|
||||
*/
|
||||
|
|
@ -89,13 +72,6 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
|
|||
*/
|
||||
public function chooseTaxCalculationStrategy($taxCalculationStrategy);
|
||||
|
||||
/**
|
||||
* @param string $paymentMethod
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPaymentMethodChosen($paymentMethod);
|
||||
|
||||
/**
|
||||
* @param string $taxZone
|
||||
*
|
||||
|
|
|
|||
|
|
@ -45,6 +45,14 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
|||
$this->getElement('gateway')->selectOption($gateway);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function checkChannel($channelName)
|
||||
{
|
||||
$this->getDocument()->checkField($channelName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -37,6 +37,11 @@ interface CreatePageInterface extends BaseCreatePageInterface
|
|||
*/
|
||||
public function chooseGateway($gateway);
|
||||
|
||||
/**
|
||||
* @param string $channelName
|
||||
*/
|
||||
public function checkChannel($channelName);
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
* @param string $languageCode
|
||||
|
|
|
|||
|
|
@ -49,6 +49,14 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
return (bool) $this->getToggleableElement()->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isAvailableInChannel($channelName)
|
||||
{
|
||||
return $this->getElement('channel', ['%channel%' => $channelName])->hasAttribute('checked');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -79,6 +87,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
protected function getDefinedElements()
|
||||
{
|
||||
return array_merge(parent::getDefinedElements(), [
|
||||
'channel' => '.checkbox:contains("%channel%") input',
|
||||
'code' => '#sylius_payment_method_code',
|
||||
'enabled' => '#sylius_payment_method_enabled',
|
||||
'gateway' => '#sylius_payment_method_gateway',
|
||||
|
|
|
|||
|
|
@ -42,6 +42,13 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
|
|||
*/
|
||||
public function isPaymentMethodEnabled();
|
||||
|
||||
/**
|
||||
* @param string $channelName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAvailableInChannel($channelName);
|
||||
|
||||
/**
|
||||
* @param string $language
|
||||
*
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Sylius\Behat\Page\Admin\ShippingMethod;
|
||||
|
||||
use Behat\Mink\Driver\Selenium2Driver;
|
||||
use Sylius\Behat\Behaviour\ChoosesCalculator;
|
||||
use Sylius\Behat\Behaviour\SpecifiesItsAmount;
|
||||
use Sylius\Behat\Behaviour\SpecifiesItsCode;
|
||||
|
|
@ -73,6 +74,20 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
|||
$this->getDocument()->selectFieldOption('Calculator', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function checkChannel($channel)
|
||||
{
|
||||
if ($this->getDriver() instanceof Selenium2Driver) {
|
||||
$this->getElement('channel', ['%channel%' => $channel])->click();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->getDocument()->checkField($channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -80,6 +95,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
|||
{
|
||||
return array_merge(parent::getDefinedElements(), [
|
||||
'amount' => '#sylius_shipping_method_configuration_amount',
|
||||
'channel' => '#sylius_shipping_method_channels .ui.checkbox:contains("%channel%")',
|
||||
'calculator' => '#sylius_shipping_method_calculator',
|
||||
'code' => '#sylius_shipping_method_code',
|
||||
'name' => '#sylius_shipping_method_translations_en_US_name',
|
||||
|
|
|
|||
|
|
@ -54,4 +54,9 @@ interface CreatePageInterface extends BaseCreatePageInterface
|
|||
* @param string $name
|
||||
*/
|
||||
public function chooseCalculator($name);
|
||||
|
||||
/**
|
||||
* @return string $channel
|
||||
*/
|
||||
public function checkChannel($channel);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,14 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
use ChecksCodeImmutability;
|
||||
use Toggles;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isAvailableInChannel($channelName)
|
||||
{
|
||||
return $this->getElement('channel', ['%channel%' => $channelName])->hasAttribute('checked');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -45,6 +53,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
protected function getDefinedElements()
|
||||
{
|
||||
return array_merge(parent::getDefinedElements(), [
|
||||
'channel' => '.checkbox:contains("%channel%") input',
|
||||
'code' => '#sylius_shipping_method_code',
|
||||
'enabled' => '#sylius_shipping_method_enabled',
|
||||
'name' => '#sylius_shipping_method_translations_en_US_name',
|
||||
|
|
|
|||
|
|
@ -23,6 +23,13 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
|
|||
*/
|
||||
public function isCodeDisabled();
|
||||
|
||||
/**
|
||||
* @param string $channelName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAvailableInChannel($channelName);
|
||||
|
||||
public function enable();
|
||||
|
||||
public function disable();
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@
|
|||
{{ form_row(form.defaultLocale) }}
|
||||
{{ form_row(form.currencies) }}
|
||||
{{ form_row(form.defaultCurrency) }}
|
||||
{{ form_row(form.shippingMethods) }}
|
||||
{{ form_row(form.paymentMethods) }}
|
||||
{{ form_row(form.defaultTaxZone) }}
|
||||
{{ form_row(form.taxCalculationStrategy) }}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<div class="two fields">
|
||||
{{ form_row(form.code) }}
|
||||
{{ form_row(form.gateway) }}
|
||||
{{ form_row(form.channels) }}
|
||||
</div>
|
||||
{{ form_row(form.enabled) }}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
{{ form_row(form.code) }}
|
||||
{{ form_row(form.position) }}
|
||||
{{ form_row(form.zone) }}
|
||||
{{ form_row(form.channels) }}
|
||||
</div>
|
||||
{{ form_row(form.enabled) }}
|
||||
<h4 class="ui dividing header">{{ 'sylius.ui.category_requirements'|trans }}</h4>
|
||||
|
|
|
|||
|
|
@ -36,10 +36,18 @@ class PaymentMethodRepository extends BasePaymentMethodRepository implements Pay
|
|||
*/
|
||||
public function findEnabledForChannel(ChannelInterface $channel)
|
||||
{
|
||||
return $this->createQueryBuilder('o')
|
||||
$queryBuilder = $this
|
||||
->createQueryBuilder('o')
|
||||
->where('o.enabled = true')
|
||||
->andWhere('o IN (:paymentMethodsInChannel)')
|
||||
->setParameter('paymentMethodsInChannel', $channel->getPaymentMethods()->toArray())
|
||||
;
|
||||
|
||||
$queryBuilder
|
||||
->innerJoin('o.channels', 'channel')
|
||||
->andWhere($queryBuilder->expr()->eq('channel', ':channel'))
|
||||
->setParameter('channel', $channel)
|
||||
;
|
||||
|
||||
return $queryBuilder
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Sylius\Bundle\CoreBundle\Doctrine\ORM;
|
||||
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Sylius\Bundle\ShippingBundle\Doctrine\ORM\ShippingMethodRepository as BaseShippingMethodRepository;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Repository\ShippingMethodRepositoryInterface;
|
||||
|
|
@ -38,11 +39,9 @@ class ShippingMethodRepository extends BaseShippingMethodRepository implements S
|
|||
*/
|
||||
public function findEnabledForZonesAndChannel(array $zones, ChannelInterface $channel)
|
||||
{
|
||||
return $this->createQueryBuilder('o')
|
||||
->where('o.enabled = true')
|
||||
->andWhere('o IN (:channelShippingMethods)')
|
||||
return $this
|
||||
->getEnabledForChannelQueryBuilder($channel)
|
||||
->andWhere('o.zone IN (:zones)')
|
||||
->setParameter('channelShippingMethods', $channel->getShippingMethods()->toArray())
|
||||
->setParameter('zones', $zones)
|
||||
->orderBy('o.position', 'asc')
|
||||
->getQuery()
|
||||
|
|
@ -55,12 +54,31 @@ class ShippingMethodRepository extends BaseShippingMethodRepository implements S
|
|||
*/
|
||||
public function findEnabledForChannel(ChannelInterface $channel)
|
||||
{
|
||||
return $this->createQueryBuilder('o')
|
||||
->where('o.enabled = true')
|
||||
->andWhere('o IN (:channelShippingMethods)')
|
||||
->setParameter('channelShippingMethods', $channel->getShippingMethods()->toArray())
|
||||
return $this
|
||||
->getEnabledForChannelQueryBuilder($channel)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ChannelInterface $channel
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
private function getEnabledForChannelQueryBuilder(ChannelInterface $channel)
|
||||
{
|
||||
$queryBuilder = $this
|
||||
->createQueryBuilder('o')
|
||||
->where('o.enabled = true')
|
||||
;
|
||||
|
||||
$queryBuilder
|
||||
->innerJoin($this->getPropertyName('channels'), 'channel')
|
||||
->andWhere($queryBuilder->expr()->eq('channel', ':channel'))
|
||||
->setParameter('channel', $channel)
|
||||
;
|
||||
|
||||
return $queryBuilder;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,8 +43,6 @@ final class ChannelFixture extends AbstractResourceFixture
|
|||
->arrayNode('locales')->prototype('scalar')->end()->end()
|
||||
->scalarNode('default_currency')->cannotBeEmpty()->end()
|
||||
->arrayNode('currencies')->prototype('scalar')->end()->end()
|
||||
->arrayNode('payment_methods')->prototype('scalar')->end()->end()
|
||||
->arrayNode('shipping_methods')->prototype('scalar')->end()->end()
|
||||
->scalarNode('theme_name')->end()
|
||||
;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,15 +45,11 @@ final class ChannelExampleFactory implements ExampleFactoryInterface
|
|||
* @param ChannelFactoryInterface $channelFactory
|
||||
* @param RepositoryInterface $localeRepository
|
||||
* @param RepositoryInterface $currencyRepository
|
||||
* @param RepositoryInterface $paymentMethodRepository
|
||||
* @param RepositoryInterface $shippingMethodRepository
|
||||
*/
|
||||
public function __construct(
|
||||
ChannelFactoryInterface $channelFactory,
|
||||
RepositoryInterface $localeRepository,
|
||||
RepositoryInterface $currencyRepository,
|
||||
RepositoryInterface $paymentMethodRepository,
|
||||
RepositoryInterface $shippingMethodRepository
|
||||
RepositoryInterface $currencyRepository
|
||||
) {
|
||||
$this->channelFactory = $channelFactory;
|
||||
|
||||
|
|
@ -94,12 +90,6 @@ final class ChannelExampleFactory implements ExampleFactoryInterface
|
|||
->setDefault('currencies', LazyOption::all($currencyRepository))
|
||||
->setAllowedTypes('currencies', 'array')
|
||||
->setNormalizer('currencies', LazyOption::findBy($currencyRepository, 'code'))
|
||||
->setDefault('payment_methods', LazyOption::all($paymentMethodRepository))
|
||||
->setAllowedTypes('payment_methods', 'array')
|
||||
->setNormalizer('payment_methods', LazyOption::findBy($paymentMethodRepository, 'code'))
|
||||
->setDefault('shipping_methods', LazyOption::all($shippingMethodRepository))
|
||||
->setAllowedTypes('shipping_methods', 'array')
|
||||
->setNormalizer('shipping_methods', LazyOption::findBy($shippingMethodRepository, 'code'))
|
||||
->setDefault('theme_name', null)
|
||||
;
|
||||
}
|
||||
|
|
@ -130,14 +120,6 @@ final class ChannelExampleFactory implements ExampleFactoryInterface
|
|||
$channel->addCurrency($currency);
|
||||
}
|
||||
|
||||
foreach ($options['payment_methods'] as $paymentMethod) {
|
||||
$channel->addPaymentMethod($paymentMethod);
|
||||
}
|
||||
|
||||
foreach ($options['shipping_methods'] as $shippingMethod) {
|
||||
$channel->addShippingMethod($shippingMethod);
|
||||
}
|
||||
|
||||
return $channel;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@
|
|||
|
||||
namespace Sylius\Bundle\CoreBundle\Fixture\Factory;
|
||||
|
||||
use Sylius\Bundle\CoreBundle\Fixture\OptionsResolver\LazyOption;
|
||||
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
|
||||
use Sylius\Component\Core\Formatter\StringInflector;
|
||||
use Sylius\Component\Core\Model\PaymentMethodInterface;
|
||||
use Sylius\Component\Locale\Model\LocaleInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentMethodInterface;
|
||||
use Sylius\Component\Resource\Factory\FactoryInterface;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
|
|
@ -34,6 +36,11 @@ final class PaymentMethodExampleFactory implements ExampleFactoryInterface
|
|||
*/
|
||||
private $localeRepository;
|
||||
|
||||
/**
|
||||
* @var ChannelRepositoryInterface
|
||||
*/
|
||||
private $channelRepository;
|
||||
|
||||
/**
|
||||
* @var \Faker\Generator
|
||||
*/
|
||||
|
|
@ -47,11 +54,16 @@ final class PaymentMethodExampleFactory implements ExampleFactoryInterface
|
|||
/**
|
||||
* @param FactoryInterface $paymentMethodFactory
|
||||
* @param RepositoryInterface $localeRepository
|
||||
* @param ChannelRepositoryInterface $channelRepository
|
||||
*/
|
||||
public function __construct(FactoryInterface $paymentMethodFactory, RepositoryInterface $localeRepository)
|
||||
{
|
||||
public function __construct(
|
||||
FactoryInterface $paymentMethodFactory,
|
||||
RepositoryInterface $localeRepository,
|
||||
ChannelRepositoryInterface $channelRepository
|
||||
) {
|
||||
$this->paymentMethodFactory = $paymentMethodFactory;
|
||||
$this->localeRepository = $localeRepository;
|
||||
$this->channelRepository = $channelRepository;
|
||||
|
||||
$this->faker = \Faker\Factory::create();
|
||||
$this->optionsResolver =
|
||||
|
|
@ -69,6 +81,9 @@ final class PaymentMethodExampleFactory implements ExampleFactoryInterface
|
|||
->setDefault('enabled', function (Options $options) {
|
||||
return $this->faker->boolean(90);
|
||||
})
|
||||
->setDefault('channels', LazyOption::all($channelRepository))
|
||||
->setAllowedTypes('channels', 'array')
|
||||
->setNormalizer('channels', LazyOption::findBy($channelRepository, 'code'))
|
||||
->setAllowedTypes('enabled', 'bool')
|
||||
;
|
||||
}
|
||||
|
|
@ -94,6 +109,10 @@ final class PaymentMethodExampleFactory implements ExampleFactoryInterface
|
|||
$paymentMethod->setDescription($options['description']);
|
||||
}
|
||||
|
||||
foreach ($options['channels'] as $channel) {
|
||||
$paymentMethod->addChannel($channel);
|
||||
}
|
||||
|
||||
return $paymentMethod;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace Sylius\Bundle\CoreBundle\Fixture\Factory;
|
|||
|
||||
use Sylius\Bundle\CoreBundle\Fixture\OptionsResolver\LazyOption;
|
||||
use Sylius\Component\Addressing\Model\ZoneInterface;
|
||||
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
|
||||
use Sylius\Component\Core\Formatter\StringInflector;
|
||||
use Sylius\Component\Core\Model\ShippingMethodInterface;
|
||||
use Sylius\Component\Locale\Model\LocaleInterface;
|
||||
|
|
@ -38,6 +39,11 @@ final class ShippingMethodExampleFactory implements ExampleFactoryInterface
|
|||
*/
|
||||
private $localeRepository;
|
||||
|
||||
/**
|
||||
* @var ChannelRepositoryInterface
|
||||
*/
|
||||
private $channelRepository;
|
||||
|
||||
/**
|
||||
* @var \Faker\Generator
|
||||
*/
|
||||
|
|
@ -53,15 +59,18 @@ final class ShippingMethodExampleFactory implements ExampleFactoryInterface
|
|||
* @param RepositoryInterface $zoneRepository
|
||||
* @param RepositoryInterface $shippingCategoryRepository
|
||||
* @param RepositoryInterface $localeRepository
|
||||
* @param ChannelRepositoryInterface $channelRepository
|
||||
*/
|
||||
public function __construct(
|
||||
FactoryInterface $shippingMethodFactory,
|
||||
RepositoryInterface $zoneRepository,
|
||||
RepositoryInterface $shippingCategoryRepository,
|
||||
RepositoryInterface $localeRepository
|
||||
RepositoryInterface $localeRepository,
|
||||
ChannelRepositoryInterface $channelRepository
|
||||
) {
|
||||
$this->shippingMethodFactory = $shippingMethodFactory;
|
||||
$this->localeRepository = $localeRepository;
|
||||
$this->channelRepository = $channelRepository;
|
||||
|
||||
$this->faker = \Faker\Factory::create();
|
||||
$this->optionsResolver =
|
||||
|
|
@ -88,6 +97,9 @@ final class ShippingMethodExampleFactory implements ExampleFactoryInterface
|
|||
->setDefault('calculator', function (Options $options) {
|
||||
return ['type' => DefaultCalculators::FLAT_RATE, 'configuration' => ['amount' => $this->faker->randomNumber(4)]];
|
||||
})
|
||||
->setDefault('channels', LazyOption::all($channelRepository))
|
||||
->setAllowedTypes('channels', 'array')
|
||||
->setNormalizer('channels', LazyOption::findBy($channelRepository, 'code'))
|
||||
;
|
||||
}
|
||||
|
||||
|
|
@ -118,6 +130,10 @@ final class ShippingMethodExampleFactory implements ExampleFactoryInterface
|
|||
$shippingMethod->setDescription($options['description']);
|
||||
}
|
||||
|
||||
foreach ($options['channels'] as $channel) {
|
||||
$shippingMethod->addChannel($channel);
|
||||
}
|
||||
|
||||
return $shippingMethod;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture;
|
|||
use Sylius\Component\Core\Model\AddressInterface;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Core\OrderCheckoutTransitions;
|
||||
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
|
||||
use Sylius\Component\Core\Repository\ShippingMethodRepositoryInterface;
|
||||
use Sylius\Component\Order\Modifier\OrderItemQuantityModifierInterface;
|
||||
use Sylius\Component\Resource\Factory\FactoryInterface;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
|
|
@ -68,6 +70,16 @@ final class OrderFixture extends AbstractFixture
|
|||
*/
|
||||
private $countryRepository;
|
||||
|
||||
/**
|
||||
* @var PaymentMethodRepositoryInterface
|
||||
*/
|
||||
private $paymentMethodRepository;
|
||||
|
||||
/**
|
||||
* @var ShippingMethodRepositoryInterface
|
||||
*/
|
||||
private $shippingMethodRepository;
|
||||
|
||||
/**
|
||||
* @var FactoryInterface
|
||||
*/
|
||||
|
|
@ -92,6 +104,8 @@ final class OrderFixture extends AbstractFixture
|
|||
* @param RepositoryInterface $customerRepository
|
||||
* @param RepositoryInterface $productRepository
|
||||
* @param RepositoryInterface $countryRepository
|
||||
* @param PaymentMethodRepositoryInterface $paymentMethodRepository
|
||||
* @param ShippingMethodRepositoryInterface $shippingMethodRepository
|
||||
* @param FactoryInterface $addressFactory
|
||||
* @param StateMachineFactoryInterface $stateMachineFactory
|
||||
*/
|
||||
|
|
@ -104,6 +118,8 @@ final class OrderFixture extends AbstractFixture
|
|||
RepositoryInterface $customerRepository,
|
||||
RepositoryInterface $productRepository,
|
||||
RepositoryInterface $countryRepository,
|
||||
PaymentMethodRepositoryInterface $paymentMethodRepository,
|
||||
ShippingMethodRepositoryInterface $shippingMethodRepository,
|
||||
FactoryInterface $addressFactory,
|
||||
StateMachineFactoryInterface $stateMachineFactory
|
||||
) {
|
||||
|
|
@ -115,6 +131,8 @@ final class OrderFixture extends AbstractFixture
|
|||
$this->customerRepository = $customerRepository;
|
||||
$this->productRepository = $productRepository;
|
||||
$this->countryRepository = $countryRepository;
|
||||
$this->paymentMethodRepository = $paymentMethodRepository;
|
||||
$this->shippingMethodRepository = $shippingMethodRepository;
|
||||
$this->addressFactory = $addressFactory;
|
||||
$this->stateMachineFactory = $stateMachineFactory;
|
||||
|
||||
|
|
@ -227,7 +245,7 @@ final class OrderFixture extends AbstractFixture
|
|||
*/
|
||||
private function selectShipping(OrderInterface $order)
|
||||
{
|
||||
$shippingMethod = $this->faker->randomElement($order->getChannel()->getShippingMethods()->toArray());
|
||||
$shippingMethod = $this->faker->randomElement($this->shippingMethodRepository->findEnabledForChannel($order->getChannel()));
|
||||
|
||||
Assert::notNull($shippingMethod);
|
||||
|
||||
|
|
@ -243,7 +261,10 @@ final class OrderFixture extends AbstractFixture
|
|||
*/
|
||||
private function selectPayment(OrderInterface $order)
|
||||
{
|
||||
$paymentMethod = $this->faker->randomElement($order->getChannel()->getPaymentMethods()->toArray());
|
||||
$paymentMethod = $this
|
||||
->faker
|
||||
->randomElement($this->paymentMethodRepository->findAll())
|
||||
;
|
||||
|
||||
Assert::notNull($paymentMethod);
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ final class PaymentMethodFixture extends AbstractResourceFixture
|
|||
->scalarNode('name')->cannotBeEmpty()->end()
|
||||
->scalarNode('description')->cannotBeEmpty()->end()
|
||||
->scalarNode('gateway')->cannotBeEmpty()->end()
|
||||
->arrayNode('channels')->prototype('scalar')->end()->end()
|
||||
->booleanNode('enabled')->end()
|
||||
;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ final class ShippingMethodFixture extends AbstractResourceFixture
|
|||
->scalarNode('zone')->cannotBeEmpty()->end()
|
||||
->booleanNode('enabled')->end()
|
||||
->scalarNode('category')->end()
|
||||
->arrayNode('channels')->prototype('scalar')->end()->end()
|
||||
->arrayNode('calculator')
|
||||
->children()
|
||||
->scalarNode('type')->isRequired()->cannotBeEmpty()->end()
|
||||
|
|
|
|||
|
|
@ -59,14 +59,6 @@ class ChannelType extends BaseChannelType
|
|||
'empty_data' => null,
|
||||
'empty_value' => 'sylius.ui.no_theme',
|
||||
])
|
||||
->add('shippingMethods', 'sylius_shipping_method_choice', [
|
||||
'label' => 'sylius.form.channel.shipping_methods',
|
||||
'multiple' => true,
|
||||
])
|
||||
->add('paymentMethods', 'sylius_payment_method_choice', [
|
||||
'label' => 'sylius.form.channel.payment_methods',
|
||||
'multiple' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
<?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\Bundle\CoreBundle\Form\Type\Payment;
|
||||
|
||||
use Sylius\Bundle\PaymentBundle\Form\Type\PaymentMethodType as BasePaymentMethodType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
|
||||
*/
|
||||
class PaymentMethodType extends BasePaymentMethodType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
parent::buildForm($builder, $options);
|
||||
|
||||
$builder
|
||||
->add('channels', 'sylius_channel_choice', [
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'label' => 'sylius.form.payment_method.channels',
|
||||
])
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
@ -35,6 +35,11 @@ class ShippingMethodType extends BaseShippingMethodType
|
|||
'empty_value' => '---',
|
||||
'label' => 'sylius.form.shipping_method.tax_category',
|
||||
])
|
||||
->add('channels', 'sylius_channel_choice', [
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'label' => 'sylius.form.shipping_method.channels',
|
||||
])
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,15 +22,31 @@ sylius_fixtures:
|
|||
countries:
|
||||
- "US"
|
||||
|
||||
channel:
|
||||
options:
|
||||
custom:
|
||||
us_web_store:
|
||||
name: "US Web Store"
|
||||
code: "US_WEB"
|
||||
locales:
|
||||
- "%locale%"
|
||||
currencies:
|
||||
- "%currency%"
|
||||
enabled: true
|
||||
|
||||
payment_method:
|
||||
options:
|
||||
custom:
|
||||
cash_on_delivery:
|
||||
code: "cash_on_delivery"
|
||||
name: "Cash on delivery"
|
||||
channels:
|
||||
- "US_WEB"
|
||||
bank_transfer:
|
||||
code: "bank_transfer"
|
||||
name: "Bank transfer"
|
||||
channels:
|
||||
- "US_WEB"
|
||||
enabled: true
|
||||
|
||||
shipping_method:
|
||||
|
|
@ -40,30 +56,18 @@ sylius_fixtures:
|
|||
code: "ups"
|
||||
name: "UPS"
|
||||
enabled: true
|
||||
channels:
|
||||
- "US_WEB"
|
||||
dhl_express:
|
||||
code: "dhl_express"
|
||||
name: "DHL Express"
|
||||
channels:
|
||||
- "US_WEB"
|
||||
fedex:
|
||||
code: "fedex"
|
||||
name: "FedEx"
|
||||
|
||||
channel:
|
||||
options:
|
||||
custom:
|
||||
us_web_store:
|
||||
name: "US Web Store"
|
||||
locales:
|
||||
- "%locale%"
|
||||
currencies:
|
||||
- "%currency%"
|
||||
shipping_methods:
|
||||
- "ups"
|
||||
- "dhl_express"
|
||||
- "fedex"
|
||||
payment_methods:
|
||||
- "cash_on_delivery"
|
||||
- "bank_transfer"
|
||||
enabled: true
|
||||
channels:
|
||||
- "US_WEB"
|
||||
|
||||
regular_user:
|
||||
name: "shop_user"
|
||||
|
|
|
|||
|
|
@ -9,4 +9,7 @@ sylius_payment:
|
|||
repository: Sylius\Bundle\CoreBundle\Doctrine\ORM\PaymentRepository
|
||||
payment_method:
|
||||
classes:
|
||||
model: Sylius\Component\Core\Model\PaymentMethod
|
||||
repository: Sylius\Bundle\CoreBundle\Doctrine\ORM\PaymentMethodRepository
|
||||
form:
|
||||
default: Sylius\Bundle\CoreBundle\Form\Type\Payment\PaymentMethodType
|
||||
|
|
|
|||
|
|
@ -49,26 +49,6 @@
|
|||
</inverse-join-columns>
|
||||
</join-table>
|
||||
</many-to-many>
|
||||
<many-to-many field="shippingMethods" target-entity="Sylius\Component\Shipping\Model\ShippingMethodInterface">
|
||||
<join-table name="sylius_channel_shipping_methods">
|
||||
<join-columns>
|
||||
<join-column name="channel_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
|
||||
</join-columns>
|
||||
<inverse-join-columns>
|
||||
<join-column name="shipping_method_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
|
||||
</inverse-join-columns>
|
||||
</join-table>
|
||||
</many-to-many>
|
||||
<many-to-many field="paymentMethods" target-entity="Sylius\Component\Payment\Model\PaymentMethodInterface">
|
||||
<join-table name="sylius_channel_payment_methods">
|
||||
<join-columns>
|
||||
<join-column name="channel_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
|
||||
</join-columns>
|
||||
<inverse-join-columns>
|
||||
<join-column name="payment_method_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
|
||||
</inverse-join-columns>
|
||||
</join-table>
|
||||
</many-to-many>
|
||||
</mapped-superclass>
|
||||
|
||||
</doctrine-mapping>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
<mapped-superclass name="Sylius\Component\Core\Model\PaymentMethod" table="sylius_payment_method">
|
||||
<many-to-many field="channels" target-entity="Sylius\Component\Channel\Model\ChannelInterface">
|
||||
<join-table name="sylius_payment_method_channels">
|
||||
<join-columns>
|
||||
<join-column name="payment_method_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
|
||||
</join-columns>
|
||||
<inverse-join-columns>
|
||||
<join-column name="channel_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
|
||||
</inverse-join-columns>
|
||||
</join-table>
|
||||
</many-to-many>
|
||||
</mapped-superclass>
|
||||
|
||||
</doctrine-mapping>
|
||||
|
|
@ -24,6 +24,17 @@
|
|||
<many-to-one field="taxCategory" target-entity="Sylius\Component\Taxation\Model\TaxCategoryInterface">
|
||||
<join-column name="tax_category_id" referenced-column-name="id" nullable="true" on-delete="SET NULL" />
|
||||
</many-to-one>
|
||||
|
||||
<many-to-many field="channels" target-entity="Sylius\Component\Channel\Model\ChannelInterface">
|
||||
<join-table name="sylius_shipping_method_channels">
|
||||
<join-columns>
|
||||
<join-column name="shipping_method_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
|
||||
</join-columns>
|
||||
<inverse-join-columns>
|
||||
<join-column name="channel_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
|
||||
</inverse-join-columns>
|
||||
</join-table>
|
||||
</many-to-many>
|
||||
</mapped-superclass>
|
||||
|
||||
</doctrine-mapping>
|
||||
|
|
|
|||
|
|
@ -150,6 +150,8 @@
|
|||
<argument type="service" id="sylius.repository.customer" />
|
||||
<argument type="service" id="sylius.repository.product" />
|
||||
<argument type="service" id="sylius.repository.country" />
|
||||
<argument type="service" id="sylius.repository.payment_method" />
|
||||
<argument type="service" id="sylius.repository.shipping_method" />
|
||||
<argument type="service" id="sylius.factory.address" />
|
||||
<argument type="service" id="sm.factory" />
|
||||
<tag name="sylius_fixtures.fixture" />
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
<service id="sylius.fixture.example_factory.payment_method" class="Sylius\Bundle\CoreBundle\Fixture\Factory\PaymentMethodExampleFactory">
|
||||
<argument type="service" id="sylius.factory.payment_method" />
|
||||
<argument type="service" id="sylius.repository.locale" />
|
||||
<argument type="service" id="sylius.repository.channel" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.fixture.example_factory.shipping_category" class="Sylius\Bundle\CoreBundle\Fixture\Factory\ShippingCategoryExampleFactory">
|
||||
|
|
@ -27,14 +28,13 @@
|
|||
<argument type="service" id="sylius.repository.zone" />
|
||||
<argument type="service" id="sylius.repository.shipping_category" />
|
||||
<argument type="service" id="sylius.repository.locale" />
|
||||
<argument type="service" id="sylius.repository.channel" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.fixture.example_factory.channel" class="Sylius\Bundle\CoreBundle\Fixture\Factory\ChannelExampleFactory">
|
||||
<argument type="service" id="sylius.factory.channel" />
|
||||
<argument type="service" id="sylius.repository.locale" />
|
||||
<argument type="service" id="sylius.repository.currency" />
|
||||
<argument type="service" id="sylius.repository.payment_method" />
|
||||
<argument type="service" id="sylius.repository.shipping_method" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.fixture.example_factory.shop_user" class="Sylius\Bundle\CoreBundle\Fixture\Factory\ShopUserExampleFactory">
|
||||
|
|
|
|||
|
|
@ -130,6 +130,8 @@ sylius:
|
|||
total_of_items_from_taxon:
|
||||
taxon: Taxon
|
||||
amount: Amount
|
||||
payment_method:
|
||||
channels: Channels
|
||||
|
||||
installer:
|
||||
extensions:
|
||||
|
|
|
|||
|
|
@ -88,22 +88,6 @@ final class ChannelFixtureTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertConfigurationIsValid([['custom' => [['currencies' => ['USD', 'PLN']]]]], 'custom.*.currencies');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function channel_payment_methods_are_optional()
|
||||
{
|
||||
$this->assertConfigurationIsValid([['custom' => [['payment_methods' => ['en_US', 'pl_PL']]]]], 'custom.*.payment_methods');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function channel_shipping_methods_are_optional()
|
||||
{
|
||||
$this->assertConfigurationIsValid([['custom' => [['shipping_methods' => ['en_US', 'pl_PL']]]]], 'custom.*.shipping_methods');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ sylius:
|
|||
calculator: Calculator
|
||||
category: Category
|
||||
category_requirement: Category requirement
|
||||
channels: Channels
|
||||
configuration: Configuration
|
||||
description: Description
|
||||
enabled: Enabled
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ use Sylius\Component\Addressing\Model\ZoneInterface;
|
|||
use Sylius\Component\Channel\Model\Channel as BaseChannel;
|
||||
use Sylius\Component\Currency\Model\CurrencyInterface;
|
||||
use Sylius\Component\Locale\Model\LocaleInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentMethodInterface;
|
||||
use Sylius\Component\Shipping\Model\ShippingMethodInterface as BaseShippingMethodInterface;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
|
|
@ -55,16 +53,6 @@ class Channel extends BaseChannel implements ChannelInterface
|
|||
*/
|
||||
protected $locales;
|
||||
|
||||
/**
|
||||
* @var PaymentMethodInterface[]|Collection
|
||||
*/
|
||||
protected $paymentMethods;
|
||||
|
||||
/**
|
||||
* @var BaseShippingMethodInterface[]|Collection
|
||||
*/
|
||||
protected $shippingMethods;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
@ -76,8 +64,6 @@ class Channel extends BaseChannel implements ChannelInterface
|
|||
|
||||
$this->currencies = new ArrayCollection();
|
||||
$this->locales = new ArrayCollection();
|
||||
$this->paymentMethods = new ArrayCollection();
|
||||
$this->shippingMethods = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -216,78 +202,6 @@ class Channel extends BaseChannel implements ChannelInterface
|
|||
return $this->locales->contains($locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getShippingMethods()
|
||||
{
|
||||
return $this->shippingMethods;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addShippingMethod(BaseShippingMethodInterface $shippingMethod)
|
||||
{
|
||||
if (!$this->hasShippingMethod($shippingMethod)) {
|
||||
$this->shippingMethods->add($shippingMethod);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeShippingMethod(BaseShippingMethodInterface $shippingMethod)
|
||||
{
|
||||
if ($this->hasShippingMethod($shippingMethod)) {
|
||||
$this->shippingMethods->removeElement($shippingMethod);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasShippingMethod(BaseShippingMethodInterface $shippingMethod)
|
||||
{
|
||||
return $this->shippingMethods->contains($shippingMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPaymentMethods()
|
||||
{
|
||||
return $this->paymentMethods;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addPaymentMethod(PaymentMethodInterface $paymentMethod)
|
||||
{
|
||||
if (!$this->hasPaymentMethod($paymentMethod)) {
|
||||
$this->paymentMethods->add($paymentMethod);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removePaymentMethod(PaymentMethodInterface $paymentMethod)
|
||||
{
|
||||
if ($this->hasPaymentMethod($paymentMethod)) {
|
||||
$this->paymentMethods->removeElement($paymentMethod);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasPaymentMethod(PaymentMethodInterface $paymentMethod)
|
||||
{
|
||||
return $this->paymentMethods->contains($paymentMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ use Sylius\Component\Currency\Model\CurrenciesAwareInterface;
|
|||
use Sylius\Component\Currency\Model\CurrencyInterface;
|
||||
use Sylius\Component\Locale\Model\LocaleInterface;
|
||||
use Sylius\Component\Locale\Model\LocalesAwareInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentMethodsAwareInterface;
|
||||
use Sylius\Component\Shipping\Model\ShippingMethodsAwareInterface;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
|
|
@ -26,9 +24,7 @@ use Sylius\Component\Shipping\Model\ShippingMethodsAwareInterface;
|
|||
interface ChannelInterface extends
|
||||
BaseChannelInterface,
|
||||
CurrenciesAwareInterface,
|
||||
LocalesAwareInterface,
|
||||
PaymentMethodsAwareInterface,
|
||||
ShippingMethodsAwareInterface
|
||||
LocalesAwareInterface
|
||||
{
|
||||
/**
|
||||
* @return LocaleInterface
|
||||
|
|
|
|||
80
src/Sylius/Component/Core/Model/PaymentMethod.php
Normal file
80
src/Sylius/Component/Core/Model/PaymentMethod.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?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\Core\Model;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Sylius\Component\Channel\Model\ChannelInterface as BaseChannelInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentMethod as BasePaymentMethod;
|
||||
use Sylius\Component\Payment\Model\PaymentMethodTranslation;
|
||||
|
||||
/**
|
||||
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
|
||||
*/
|
||||
class PaymentMethod extends BasePaymentMethod implements PaymentMethodInterface
|
||||
{
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
private $channels;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->channels = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getChannels()
|
||||
{
|
||||
return $this->channels;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasChannel(BaseChannelInterface $channel)
|
||||
{
|
||||
return $this->channels->contains($channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addChannel(BaseChannelInterface $channel)
|
||||
{
|
||||
if (!$this->hasChannel($channel)) {
|
||||
$this->channels->add($channel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeChannel(BaseChannelInterface $channel)
|
||||
{
|
||||
if ($this->hasChannel($channel)) {
|
||||
$this->channels->removeElement($channel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getTranslationClass()
|
||||
{
|
||||
return PaymentMethodTranslation::class;
|
||||
}
|
||||
}
|
||||
22
src/Sylius/Component/Core/Model/PaymentMethodInterface.php
Normal file
22
src/Sylius/Component/Core/Model/PaymentMethodInterface.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?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\Core\Model;
|
||||
|
||||
use Sylius\Component\Channel\Model\ChannelsAwareInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentMethodInterface as BasePaymentMethodInterface;
|
||||
|
||||
/**
|
||||
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
|
||||
*/
|
||||
interface PaymentMethodInterface extends BasePaymentMethodInterface, ChannelsAwareInterface
|
||||
{
|
||||
}
|
||||
|
|
@ -11,7 +11,10 @@
|
|||
|
||||
namespace Sylius\Component\Core\Model;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Sylius\Component\Addressing\Model\ZoneInterface;
|
||||
use Sylius\Component\Channel\Model\ChannelInterface as BaseChannelInterface;
|
||||
use Sylius\Component\Shipping\Model\ShippingMethod as BaseShippingMethod;
|
||||
use Sylius\Component\Shipping\Model\ShippingMethodTranslation;
|
||||
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
|
||||
|
|
@ -32,6 +35,18 @@ class ShippingMethod extends BaseShippingMethod implements ShippingMethodInterfa
|
|||
*/
|
||||
protected $taxCategory;
|
||||
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
private $channels;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->channels = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -64,6 +79,42 @@ class ShippingMethod extends BaseShippingMethod implements ShippingMethodInterfa
|
|||
$this->taxCategory = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getChannels()
|
||||
{
|
||||
return $this->channels;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasChannel(BaseChannelInterface $channel)
|
||||
{
|
||||
return $this->channels->contains($channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addChannel(BaseChannelInterface $channel)
|
||||
{
|
||||
if (!$this->hasChannel($channel)) {
|
||||
$this->channels->add($channel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeChannel(BaseChannelInterface $channel)
|
||||
{
|
||||
if ($this->hasChannel($channel)) {
|
||||
$this->channels->removeElement($channel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
namespace Sylius\Component\Core\Model;
|
||||
|
||||
use Sylius\Component\Addressing\Model\ZoneInterface;
|
||||
use Sylius\Component\Channel\Model\ChannelsAwareInterface;
|
||||
use Sylius\Component\Shipping\Model\ShippingMethodInterface as BaseShippingMethodInterface;
|
||||
use Sylius\Component\Taxation\Model\TaxableInterface;
|
||||
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
|
||||
|
|
@ -19,7 +20,7 @@ use Sylius\Component\Taxation\Model\TaxCategoryInterface;
|
|||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
interface ShippingMethodInterface extends BaseShippingMethodInterface, TaxableInterface
|
||||
interface ShippingMethodInterface extends BaseShippingMethodInterface, TaxableInterface, ChannelsAwareInterface
|
||||
{
|
||||
/**
|
||||
* @return ZoneInterface
|
||||
|
|
|
|||
77
src/Sylius/Component/Core/spec/Model/PaymentMethodSpec.php
Normal file
77
src/Sylius/Component/Core/spec/Model/PaymentMethodSpec.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?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\Core\Model;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Model\PaymentMethod;
|
||||
use Sylius\Component\Core\Model\PaymentMethodInterface;
|
||||
use Sylius\Component\Payment\Model\PaymentMethod as BasePaymentMethod;
|
||||
|
||||
/**
|
||||
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
|
||||
*/
|
||||
final class PaymentMethodSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType(PaymentMethod::class);
|
||||
}
|
||||
|
||||
function it_is_payment_method()
|
||||
{
|
||||
$this->shouldHaveType(BasePaymentMethod::class);
|
||||
}
|
||||
|
||||
function it_implements_payment_method_interface()
|
||||
{
|
||||
$this->shouldImplement(PaymentMethodInterface::class);
|
||||
}
|
||||
|
||||
function it_has_channels_collection(ChannelInterface $firstChannel, ChannelInterface $secondChannel)
|
||||
{
|
||||
$this->addChannel($firstChannel);
|
||||
$this->addChannel($secondChannel);
|
||||
|
||||
$this->getChannels()->shouldBeSameAs(new ArrayCollection([$firstChannel, $secondChannel]));
|
||||
}
|
||||
|
||||
function it_can_add_and_remove_channels(ChannelInterface $channel)
|
||||
{
|
||||
$this->addChannel($channel);
|
||||
$this->hasChannel($channel)->shouldReturn(true);
|
||||
|
||||
$this->removeChannel($channel);
|
||||
$this->hasChannel($channel)->shouldReturn(false);
|
||||
}
|
||||
|
||||
public function getMatchers()
|
||||
{
|
||||
return [
|
||||
'beSameAs' => function ($subject, $key) {
|
||||
if (!$subject instanceof Collection || !$key instanceof Collection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $subject->count(); $i++) {
|
||||
if ($subject->get($i) !== $key->get($i)->getWrappedObject()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -11,8 +11,11 @@
|
|||
|
||||
namespace spec\Sylius\Component\Core\Model;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Addressing\Model\ZoneInterface;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Model\ShippingMethod;
|
||||
use Sylius\Component\Core\Model\ShippingMethodInterface;
|
||||
use Sylius\Component\Shipping\Model\ShippingMethod as BaseShippingMethod;
|
||||
|
|
@ -51,4 +54,40 @@ final class ShippingMethodSpec extends ObjectBehavior
|
|||
$this->setTaxCategory($category);
|
||||
$this->getTaxCategory()->shouldReturn($category);
|
||||
}
|
||||
|
||||
function it_has_channels_collection(ChannelInterface $firstChannel, ChannelInterface $secondChannel)
|
||||
{
|
||||
$this->addChannel($firstChannel);
|
||||
$this->addChannel($secondChannel);
|
||||
|
||||
$this->getChannels()->shouldBeSameAs(new ArrayCollection([$firstChannel, $secondChannel]));
|
||||
}
|
||||
|
||||
function it_can_add_and_remove_channels(ChannelInterface $channel)
|
||||
{
|
||||
$this->addChannel($channel);
|
||||
$this->hasChannel($channel)->shouldReturn(true);
|
||||
|
||||
$this->removeChannel($channel);
|
||||
$this->hasChannel($channel)->shouldReturn(false);
|
||||
}
|
||||
|
||||
public function getMatchers()
|
||||
{
|
||||
return [
|
||||
'beSameAs' => function ($subject, $key) {
|
||||
if (!$subject instanceof Collection || !$key instanceof Collection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $subject->count(); $i++) {
|
||||
if ($subject->get($i) !== $key->get($i)->getWrappedObject()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +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\Payment\Model;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
interface PaymentMethodsAwareInterface
|
||||
{
|
||||
/**
|
||||
* @return Collection|PaymentMethodInterface[]
|
||||
*/
|
||||
public function getPaymentMethods();
|
||||
|
||||
/**
|
||||
* @param PaymentMethodInterface $paymentMethod
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPaymentMethod(PaymentMethodInterface $paymentMethod);
|
||||
|
||||
/**
|
||||
* @param PaymentMethodInterface $paymentMethod
|
||||
*/
|
||||
public function addPaymentMethod(PaymentMethodInterface $paymentMethod);
|
||||
|
||||
/**
|
||||
* @param PaymentMethodInterface $paymentMethod
|
||||
*/
|
||||
public function removePaymentMethod(PaymentMethodInterface $paymentMethod);
|
||||
}
|
||||
|
|
@ -1,42 +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\Shipping\Model;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
interface ShippingMethodsAwareInterface
|
||||
{
|
||||
/**
|
||||
* @return Collection|ShippingMethodInterface[]
|
||||
*/
|
||||
public function getShippingMethods();
|
||||
|
||||
/**
|
||||
* @param ShippingMethodInterface $shippingMethod
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasShippingMethod(ShippingMethodInterface $shippingMethod);
|
||||
|
||||
/**
|
||||
* @param ShippingMethodInterface $shippingMethod
|
||||
*/
|
||||
public function addShippingMethod(ShippingMethodInterface $shippingMethod);
|
||||
|
||||
/**
|
||||
* @param ShippingMethodInterface $shippingMethod
|
||||
*/
|
||||
public function removeShippingMethod(ShippingMethodInterface $shippingMethod);
|
||||
}
|
||||
|
|
@ -28,8 +28,6 @@ Sylius\Component\Core\Model\Channel:
|
|||
enabled: true
|
||||
taxCalculationStrategy: "order_items_based"
|
||||
currencies: ["@currency"]
|
||||
shippingMethods: ["@ups", "@dhl"]
|
||||
paymentMethods: ["@cash_on_delivery", "@pay_by_check"]
|
||||
|
||||
Sylius\Component\Core\Model\Product:
|
||||
product1:
|
||||
|
|
@ -77,6 +75,7 @@ Sylius\Component\Core\Model\ShippingMethod:
|
|||
zone: "@zone_eu"
|
||||
currentLocale: en_US
|
||||
currentTranslation: "@upsTranslation1"
|
||||
channels: ['@channel']
|
||||
dhl:
|
||||
code: DHL
|
||||
enabled: true
|
||||
|
|
@ -84,6 +83,7 @@ Sylius\Component\Core\Model\ShippingMethod:
|
|||
configuration:
|
||||
amount: 20
|
||||
zone: "@zone_eu"
|
||||
channel: ['@channel']
|
||||
|
||||
Sylius\Component\Shipping\Model\ShippingMethodTranslation:
|
||||
upsTranslation1:
|
||||
|
|
@ -95,17 +95,19 @@ Sylius\Component\Shipping\Model\ShippingMethodTranslation:
|
|||
locale: 'en_US'
|
||||
translatable: "@dhl"
|
||||
|
||||
Sylius\Component\Payment\Model\PaymentMethod:
|
||||
Sylius\Component\Core\Model\PaymentMethod:
|
||||
cash_on_delivery:
|
||||
code: cod
|
||||
enabled: true
|
||||
gateway: 'offline'
|
||||
currentLocale: en_US
|
||||
currentTranslation: "@cash_on_delivery_translation1"
|
||||
channels: ['@channel']
|
||||
pay_by_check:
|
||||
code: pbc
|
||||
enabled: true
|
||||
gateway: 'offline'
|
||||
channels: ['@channel']
|
||||
|
||||
Sylius\Component\Payment\Model\PaymentMethodTranslation:
|
||||
cash_on_delivery_translation1:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue