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

Fixtures #21

Open
TakesTheBiscuit opened this issue Apr 24, 2024 · 1 comment
Open

Fixtures #21

TakesTheBiscuit opened this issue Apr 24, 2024 · 1 comment

Comments

@TakesTheBiscuit
Copy link

It would be fantastic if you could provide us with an example structure for how we can create a fixture suite which targets webgriffe sylius table rate shipping plugin

This would enable us to set rates for the 10 shipping methods we have all in one go across multiple environments

Thanks!

@LucaGallinari
Copy link
Member

Hi @TakesTheBiscuit thank you for reaching us out.
You should take a look at:

  • "basic fixture" section here for the creation and configuration of the fixture via SyliusFixtureBundle
  • ShippingTableRateContext files in this repo as it has some examples of how to configure table rates and the related shipping method

and do a mix of both.
In the load function of the fixture you should do something like this (just a fast wrap-up i did now, there could be something to adjust):


    public function load(ObjectManager $manager)
    {
        /** @var RepositoryInterface $shippingTableRateRepository */
        $shippingTableRateRepository = $this->entityManager->getRepository(ShippingTableRate::class);

        $rateIt = new ShippingTableRate();
        $rateIt->setName('Tablerate Italy');
        $rateIt->setCode('tablerate_italy');
        $rateIt->addRate(990, 10);
        $rateIt->addRate(1250, 50);
        $rateIt->addRate(1500, 100);
        $rateIt->addRate(1750, 200);
        $shippingTableRateRepository->add($rateIt);

        $rateFr = new ShippingTableRate();
        $rateFr->setName('Tablerate France');
        $rateFr->setCode('tablerate_france');
        $rateFr->addRate(1990, 10);
        $rateFr->addRate(2250, 50);
        $rateFr->addRate(2500, 100);
        $rateFr->addRate(2750, 200);
        $shippingTableRateRepository->add($rateFr);

        /** @var ShippingMethodInterface $shippingMethodIt */
        $shippingMethodIt = $this->shippingMethodFactory->createNew();
        $shippingMethodIt->setCode('tablerate_italy_shipping');
        $shippingMethodIt->setEnabled(true);
        $shippingMethodIt->setZone($this->getItalianShippingZone());
        $shippingMethodIt->setCalculator(TableRateShippingCalculator::TYPE);
        $shippingMethodIt->setConfiguration(['ecommerce' => ['table_rate' => $rateIt]]);

        /** @var ShippingMethodInterface $shippingMethodFr */
        $shippingMethodFr = $this->shippingMethodFactory->createNew();
        $shippingMethodFr->setCode('tablerate_france_shipping');
        $shippingMethodFr->setEnabled(true);
        $shippingMethodFr->setZone($this->getFranceShippingZone());
        $shippingMethodFr->setCalculator(TableRateShippingCalculator::TYPE);
        $shippingMethodFr->setConfiguration(['ecommerce' => ['table_rate' => $rateFr]]);
        
        $this->entityManager->flush();
    }

Let us know if this helped you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants