定制 cleverage/sylius-dpd-plugin 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cleverage/sylius-dpd-plugin

Composer 安装命令:

composer require cleverage/sylius-dpd-plugin

包简介

Simple DPD REST Plugin for Sylius

README 文档

README

Latest Version Software License

Introduction

This sylius plugin allows you to manage parcel shipments with DPD. You can define DPD pickup points delivery method.

For pickup point deliveries, an interactive map with the list of pickup points is generated according to the delivery address entered the tunnel by the user.

Usage

TODO add screenshots

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 cleverage/sylius-dpd-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 [
    // ...
    CleverAge\SyliusDpdPlugin\CleverAgeSyliusDpdPlugin::class => ['all' => true],
    // ...
];

Step 2: Import routing and configs

Import routing

# config/routes/clerverage_sylius_dpd.yaml
clever_age_sylius_dpd_shop:
  resource: "@CleverAgeSyliusDpdPlugin/Resources/config/shop_routing.yml"

Import application config

# config/packages/_sylius.yaml
imports:
  - { resource: "@CleverAgeSyliusDpdPlugin/Resources/config/config.yaml" }

Step 3: Update templates

Admin section

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

{% include "CleverAgeSyliusDpdPlugin/Shipment/Label/pickupPoint.html.twig" %}

See an example here.

Shop section

Add the following to the shop template SyliusShopBundle/Checkout/SelectShipping/_choice.html.twig

// ...
{% if method.isDpdPickup %}
    {% include '@CleverAgeSyliusDpdPlugin/Shipment/selectedPickupPoint.html.twig' %}
{% endif %}
// ...
{% if method.isDpdPickup %}
    {% include '@CleverAgeSyliusDpdPlugin/Shipment/map.html.twig' with {
        'pickupPoints': [myPickupPoints]
    } %}
{% endif %}

See an example here.

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

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

See an example here.

Step 4 : Update styles, scripts and install assets

Add the following to the shop template SyliusShopBundle/_styles.html.twig

{% include '@SyliusUi/_stylesheets.html.twig' with { 'path': 'bundles/cleveragesyliusdpdplugin/css/dpd-map.css' } %}
{% include '@SyliusUi/_stylesheets.html.twig' with { 'path': 'bundles/cleveragesyliusdpdplugin/css/dpd-popup.css' } %}

{# Important for the map ! #}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css"
      integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
      crossorigin=""
/>

See an example here.

Next the following to the shop template SyliusShopBundle/_scripts.html.twig

<script src="{{ asset('bundles/cleveragesyliusdpsplugin/js/dpd-map.js') }}" type="module"></script>
    {% include '@SyliusUi/_javascripts.html.twig' with { 'path': 'bundles/cleveragesyliusdpdplugin/js/dpd-select-shipping.js' } %}

    {% include '@SyliusUi/_javascripts.html.twig' with { 'path': 'bundles/cleveragesyliusdpdplugin/js/dpd-select-pickup-point.js' } %}
    {% include '@SyliusUi/_javascripts.html.twig' with { 'path': 'bundles/cleveragesyliusdpdplugin/js/dpd-change-pickup-point.js' } %}

See an example here.

Install assets

bin/console assets:install --symlink

Step 5 : Customize resources

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 CleverAge\SyliusDpdPlugin\Contract\DpdShippingMethodInterface;
use CleverAge\SyliusDpdPlugin\Entity\Traits\DpdShippingMethodTrait;
use Sylius\Component\Core\Model\ShippingMethod as BaseShippingMethod;

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

Order resource

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

<?php
// src/Entity/Order.php

declare(strict_types=1);

namespace App\Entity;

use CleverAge\SyliusDpdPlugin\Entity\Traits\DpdOrderTrait;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Order as BaseOrder;

/**
 * @ORM\Entity()
 * @ORM\Table(name="sylius_order")
 */
class Order extends BaseOrder
{
    use DpdOrderTrait;
}

You can read about extending resources here.

Update shipping and order resources config

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

# config/packages/_sylius.yaml

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

sylius_order:
  resources:
    order:
      classes:
        model: App\Entity\Order

Step 6 : Update database schema

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

Step 7 : Configure plugin

// config/packages/cleverage_sylius_dpd.yaml

clever_age_sylius_dpd:
  securityKey: 'security key'

Enjoy now !

cleverage/sylius-dpd-plugin 适用场景与选型建议

cleverage/sylius-dpd-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 746 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 12 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「sylius」 「dpd」 「sylius-plugin」 「sylius-dpd」 「sylius-dpd-plugin」 「dpd-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 cleverage/sylius-dpd-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 cleverage/sylius-dpd-plugin 我们能提供哪些服务?
定制开发 / 二次开发

基于 cleverage/sylius-dpd-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 746
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-30