Giter Site home page Giter Site logo

syliuspickuppointplugin's Introduction

Sylius Pickup Point Plugin

Latest Version Software License Build Status

Add a <select> that contains pickup points to your select shipping checkout step.

List of pickup points

Supported providers

  • DAO
  • GLS
  • PostNord
  • Fake provider (for development/playing purposes)

Screenshots

Shop

This is the shipping method step in the checkout process where you can choose a pickup point.

Screenshot showing checkout select shipping step with pickup points available

On the complete order step in checkout you can see the pickup point you have chosen.

Screenshot showing checkout complete step with pickup point address

Admin

On the order you can see what pickup point the customer has chosen.

Screenshot showing admin order shipping page with pickup point address

When you edit shipping method you can associate a pickup point provider to that shipping method.

Screenshot showing admin shipping method with some pickup point providers

Installation

Step 1: Install and enable plugin

Open a command console, enter your project directory and execute the following command to download the latest stable version of this plugin:

$ composer require setono/sylius-pickup-point-plugin

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Add bundle to your config/bundles.php:

<?php
# config/bundles.php

return [
    // ...
    Setono\SyliusPickupPointPlugin\SetonoSyliusPickupPointPlugin::class => ['all' => true],
    // ...
];

Step 2: Import routing and configs

Import routing

# config/routes/setono_sylius_pickup_point.yaml
setono_sylius_pickup_point_plugin:
    resource: "@SetonoSyliusPickupPointPlugin/Resources/config/routing.yaml"

Import application config

# config/packages/setono_sylius_pickup_point.yaml
imports:
    - { resource: "@SetonoSyliusPickupPointPlugin/Resources/config/app/config.yaml" }    

(Optional) Import fixtures to play in your app

# config/packages/setono_sylius_pickup_point.yaml
imports:
    - { resource: "@SetonoSyliusPickupPointPlugin/Resources/config/app/fixtures.yaml" }    

Step 3: Update templates

Add the following to the admin template SyliusAdminBundle/ShippingMethod/_form.html.twig

{{ form_row(form.pickupPointProvider) }}

See an example here.

Next add the following to the shop template SyliusShopBundle/Checkout/SelectShipping/_shipment.html.twig

{% form_theme form.pickupPointId '@SetonoSyliusPickupPointPlugin/Form/theme.html.twig' %}

{{ form_row(form.pickupPointId) }}

See an example here.

Next add the following to the shop template SyliusShopBundle/Common/Order/_shipments.html.twig after shipment method header:

{% include "@SetonoSyliusPickupPointPlugin/Shop/Label/Shipment/pickupPoint.html.twig" %}

See an example here.

Next add the following to the admin template SyliusAdminBundle/Order/Show/_shipment.html.twig after shipment header:

{% include "@SetonoSyliusPickupPointPlugin/Shop/Label/Shipment/pickupPoint.html.twig" %}

See an example here.

Step 4: Customize resources

Shipment resource

If you haven't extended the shipment resource yet, here is what it should look like:

<?php
// src/Entity/Shipment.php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Setono\SyliusPickupPointPlugin\Model\PickupPointAwareTrait;
use Setono\SyliusPickupPointPlugin\Model\ShipmentInterface;
use Sylius\Component\Core\Model\Shipment as BaseShipment;

/**
 * @ORM\Entity()
 * @ORM\Table(name="sylius_shipment")
 */
class Shipment extends BaseShipment implements ShipmentInterface
{
    use PickupPointAwareTrait;
}

Shipping method resource

If you haven't extended the shipping method resource yet, here is what it should look like:

<?php
// src/Entity/ShippingMethod.php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Setono\SyliusPickupPointPlugin\Model\PickupPointProviderAwareTrait;
use Setono\SyliusPickupPointPlugin\Model\ShippingMethodInterface;
use Sylius\Component\Core\Model\ShippingMethod as BaseShippingMethod;

/**
 * @ORM\Entity()
 * @ORM\Table(name="sylius_shipping_method")
 */
class ShippingMethod extends BaseShippingMethod implements ShippingMethodInterface
{
    use PickupPointProviderAwareTrait;
}

You can read about extending resources here.

Update shipping resources config

Next you need to tell Sylius that you will use your own extended resources:

# config/packages/_sylius.yaml

sylius_shipping:
    resources:
        shipment:
            classes:
                model: App\Entity\Shipment
        shipping_method:
            classes:
                model: App\Entity\ShippingMethod

Step 5: Configure plugin

Enable desired providers

Note that:

  • faker provider will not work on prod environment
  • budbee provider require setono/budbee-bundle to be installed
  • coolrunner provider require setono/coolrunner-bundle to be installed
  • gls provider require setono/gls-webservice-bundle to be installed
  • dao provider require setono/dao-bundle to be installed
  • post_nord provider require setono/post-nord-bundle to be installed
# config/packages/setono_sylius_pickup_point.yaml
setono_sylius_pickup_point:
    providers:
        faker: true
        budbee: true
        coolrunner: true
        gls: true
        post_nord: true
        dao: true

If you want to use cache

Cache disabled by default. To enable it, make next configuration:

# config/packages/setono_sylius_pickup_point.yaml
framework:
    cache:
        pools:
            setono_sylius_pickup_point.provider_cache_pool:
                adapter: cache.app

setono_sylius_pickup_point:
    cache:
        enabled: true
        pool: setono_sylius_pickup_point.provider_cache_pool

Step 6: Update database schema

bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate 

Step 7: Update validation groups

Add checkout_select_shipping to sylius.form.type.checkout_select_shipping.validation_groups:

# config/packages/_sylius.yaml

parameters:
    sylius.form.type.checkout_select_shipping.validation_groups: ['sylius', 'checkout_select_shipping']

Step 8: Install assets

bin/console sylius:install:assets  
bin/console sylius:theme:assets:install

Play

To see pickup points list, use next example address at checkout:

Dannebrogsgade 1
9000 Aalborg
DK
Hämeentie 1
00350 Helsinki
FI
Vasterhaninge 1
137 94 Stockholm
SE

Note, that providers have their pickup points only at given countries:

So, to play with all 3 providers at once - use DK address.

Troubleshooting

  • At /en_US/checkout/select-shipping step you see No results found at Pickup point id field.

    • Check your browser's developer console and make sure JS scripts loaded correctly. Also make sure setono-pickup-point.js compiled (read as you not forgot to run sylius:install:assets).

    • Make sure content of plugin's src/Resources/views/_javascripts.html.twig actually rendered. If not - probably, you erased {{ sonata_block_render_event('sylius.shop.layout.javascripts') }} from your custom layout.html.twig.

    Also, make sure {{ sonata_block_render_event('sylius.admin.layout.javascripts') }} in place at your admin's layout.html.twig if it was customized.

    • If you're using themes, make sure you executed sylius:theme:assets:install after plugin installation.
  • The service "setono_sylius_pickup_point.registry.provider" has a dependency on a non-existent service "setono_post_nord.http_client".

    You should specify setono_post_nord.http_client configuration or define Buzz\Client\BuzzClientInterface service to use as default http client. See Setono/PostNordBundle#1

    You should add config/packages/buzz.yaml and config/packages/nyholm_psr7.yaml configs.

  • You're facing Pickup point cannot be blank. validation error at /checkout/address step at your application

    Make sure you're followed instructions from Installation step 7.

syliuspickuppointplugin's People

Contributors

bitbager avatar dependabot[bot] avatar ehibes avatar igormukhingmailcom avatar jaisdk avatar leflings avatar loevgaard avatar roshyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

syliuspickuppointplugin's Issues

Webpack encore error

Because of missing "var" in JS variable declaration, webpack encore return an error :
self.postMessage is not a function

disabled the local database table ORM

Hello,

Is it possible to not create the database setono_sylius_pickup_point__pickup_point with the configuration?
I tried something like:

setono_sylius_pickup_point:
    local: false 
    providers:
        faker: true

but it is not working.

Js label fetcher is missing

This issue is detailed here as well : #50 (comment)
The following piece of code fixes that, but I think it should be in the main asset too.

document.addEventListener('DOMContentLoaded', () => {
    document.querySelectorAll('.setono-sylius-pickup-point-label').forEach((elt) => {
        fetch(elt.dataset.url)
            .then((response) => response.json())
            .then((response) => {
                elt.innerHTML = `<strong>Livraison point relais</strong><br/>
                ${response.name}<br/>
                ${response.full_address}<br/>
                `
                elt.style.display = 'block';
            })
    })
}) 

Own implementation for PickupPoint model

Related to #47

I want to change the getFullAddress() method of the PickupPoint model, but struggling with the override, extension.
Can you please explain, how can I use my own model class?

Thx!

Resolution of 'setono_sylius_pickup_point.registry.provider' fails if GLS webservice is down

The problem occurs in https://github.com/Setono/GlsWebserviceBundle and/or https://github.com/Setono/gls-webservice-php-sdk but the right course of action to solve problem is unclear.

If the GLS provider is registered (and their webpage is down), resolution will fail like this:

SoapFault: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://www.gls.dk/webservices_v4/wsShopFinder.asmx?WSDL' : failed to load external entity "https://www.gls.dk/webservices_v4/wsShopFinder.asmx?WSDL"

#16 /vendor/setono/gls-webservice-php-sdk/src/Factory/SoapClientFactory.php(26): SoapClient::SoapClient
#15 /vendor/setono/gls-webservice-php-sdk/src/Factory/SoapClientFactory.php(26): Setono\GLS\Webservice\Factory\SoapClientFactory::create
#14 /var/cache/prod/ContainerBZEyIsI/getSetonoSyliusPickupPoint_Registry_ProviderService.php(43): ContainerBZEyIsI\getSetonoSyliusPickupPoint_Registry_ProviderService::do
#13 /var/cache/prod/ContainerBZEyIsI/App_KernelProdContainer.php(2459): ContainerBZEyIsI\App_KernelProdContainer::load
#12 /var/cache/prod/ContainerBZEyIsI/getPickupPointsActionService.php(22): ContainerBZEyIsI\getPickupPointsActionService::do
#11 /var/cache/prod/ContainerBZEyIsI/App_KernelProdContainer.php(2459): ContainerBZEyIsI\App_KernelProdContainer::load
#10 /vendor/symfony/dependency-injection/Container.php(237): Symfony\Component\DependencyInjection\Container::make
#9 /vendor/symfony/dependency-injection/Container.php(219): Symfony\Component\DependencyInjection\Container::get
#8 /vendor/symfony/http-kernel/Controller/ContainerControllerResolver.php(53): Symfony\Component\HttpKernel\Controller\ContainerControllerResolver::instantiateController
#7 /vendor/symfony/framework-bundle/Controller/ControllerResolver.php(29): Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver::instantiateController
#6 /vendor/symfony/http-kernel/Controller/ControllerResolver.php(108): Symfony\Component\HttpKernel\Controller\ControllerResolver::createController
#5 /vendor/symfony/http-kernel/Controller/ContainerControllerResolver.php(42): Symfony\Component\HttpKernel\Controller\ContainerControllerResolver::createController
#4 /vendor/symfony/http-kernel/Controller/ControllerResolver.php(86): Symfony\Component\HttpKernel\Controller\ControllerResolver::getController
#3 /vendor/symfony/http-kernel/HttpKernel.php(139): Symfony\Component\HttpKernel\HttpKernel::handleRaw
#2 /vendor/symfony/http-kernel/HttpKernel.php(78): Symfony\Component\HttpKernel\HttpKernel::handle
#1 /vendor/symfony/http-kernel/Kernel.php(199): Symfony\Component\HttpKernel\Kernel::handle
#0 /public/index.php(25): null

Not sure how to best solve this, but one way might be to allow the "GLS client" to instantiate, but make it throw an exception on usage. Atleast then the control flow would be in the hands of user, rather than failure while building container / resolving services.

Pickup points are not returned, config errors

After I installed the plugin with the recent changes I get

(1/1) InvalidArgumentException
Invalid service "setono.sylius_pickup_point.provider.post_nord": the value of argument "setono_sylius_pickup_point_post_nord.api_key" of method "Setono\SyliusPickupPointPlugin\Provider\PostNordProvider::__construct()" must be null, an instance of Symfony\Component\DependencyInjection\Reference or an instance of Symfony\Component\DependencyInjection\Definition, string given.

error. If I remove the setono.sylius_pickup_point.provider.post_nord service, the problem disapears. However, after I go through the checkout and select a shipping method with a GLS provider, I get no pickup points due to the Soap connection error.

Making a new provider

Hi,

I'm trying to implement a new provider : TNT. I make a new Provider class that allows to display the points (for a given zipcode), that is ok.
However, on the admin part, to display PickupPoint info I need to implement findPickupPoint function but TNT webservice doest not have any function to make that. I don't know how to make this, any ideas ?
Thanks

Add map of pickup points instead of list

Instead of displaying the <select> with pickup points they could be shown on an interactive map.

It should probably be implemented in an extensible way with 'map providers' so that people could choose if they wanted Google Maps, Bing Maps or Open Street Map. The latter has a free library that makes it easier: https://leafletjs.com

Allow/document creation of custom pickup point providers

The plugin only seems to support the few hardcoded pickup point providers, but the list of obviously incomplete, plus, it realistically cannot cover all possible scenarios. For example, I'm considering this plugin in a scenario where I'll be getting a list of pickup points from another internal system on a daily basis. Such functionality wouldn't make any sense as a PR to this project, but there doesn't seem to be any documentation on how this could be implemented.

Allow extending plugin classes

The PickupPoint entity class is currently marked as soft-final, and Doctrine mapping files are automatically applied. This makes the entity particularly difficult to extend. Please make it easier.
My use-case is we want to be able to enable/disable specific pickup points as we see fit.

Even more unexpectedly, the PickupPointRepository class is final, so in order to add new repository methods, I end up having to copy-paste the original ones, and that looks a bit suboptimal.

Radio buttons instead of ajax field with pickup points

Here is my idea for a refactoring of the shipping method step in the checkout:

  1. When you arrive on the page, it will (in the background) find all shipping methods with a pickup point provider. Then for all these shipping methods (with a pickup point provider) it will fetch the relevant pickup points and cache them (in JS).

  2. When the user then clicks a shipping method (with a pickup point provider) it will be possible to render a list of radio buttons with the relevant pickup points instantaneously.

The JS should also be done in vanilla JS or at least only jQuery (not Semantic JS) because this allows the plugin to be easier to use for developers not using Semantic JS.

Cache generation issues

Hi,

While integrating the plugin together with the providers added in #63, we encountered some issues with the caching mechanism:

  1. Enabling the cache completely breaks the provider because in our checkout flow there's no shipping address at that point.
    The customers first enter the billing address, then they either add a shipping address or select a pickup point based on the billing address. Ref:
    private function buildOrderCacheKey(OrderInterface $order): string
    {
    $shippingAddress = $order->getShippingAddress();
    if (!$shippingAddress instanceof AddressInterface) {
    throw new RuntimeException(sprintf(
    'Shipping address was not found for order #%s',
    $order->getNumber()
    ));
    }
  2. It completely breaks because the exceptions thrown during the cache key generation are not caught
  3. Because the cache key generation is in private methods, changing that logic would mean copy-pasting the entire class and replacing the service.
  4. The CacheProvider decorators have a relatively high priority of 256, which created a bit of confusion because we already decorated the providers with the default priority of 0.

To overcome all these issues, I suggest the following changes:

  1. Extract the cache key generation logic in separate classes, so it's easy to change per project or even per provider.
  2. Catch errors from cache key generation, log them and bypass the cache.
  3. Register the cache decorators with a negative priority.
  4. Fallback to the billing address when there's no shipping address on cache key generation.

WDYT?

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:


If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Don't allow the channel to skip shipment step

On the channel level it is possible to skip the shipment state if only one shipping method is available. This feature should be disabled with this plugin because the customer needs to select a pickup point.

Store latitude and longitude as decimal numbers

Hi! I'm wondering if there is any particular reason why latitude and longitude are stored as strings as opposed to fixed-precision decimal numbers. Was that a design decision or an oversight?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.