jgrasp / sylius-prestashop-migration-plugin
将Prestashop数据迁移到Sylius
0.5.2
2022-03-25 10:30 UTC
Requires
- php: ^8.0
- sylius/sylius: ^1.10
README
此插件允许您将Prestashop数据迁移到Sylius。它可以重新创建分类的树状结构,导入产品及其变体、商店、产品图片等...
希望您可以根据需要对其进行装饰。
请仅在开发站点上使用此插件,最好在开始工作之前,因为这个插件有能力完全删除数据库以供工作。
我不负责您数据丢失。我创建此插件是为了让开发者生活更轻松,我将尽力使文档尽可能清晰。
希望这个插件能像帮助我一样帮助您。我将继续根据我遇到的新项目(以及您的反馈)使其增长和发展。
要求
- Sylius 1.10最低版本
- PHP 8.0最低版本
安装
- 将插件添加到您的项目中
$ composer require jgrasp/sylius-prestashop-migration-plugin
- 将插件依赖项添加到您的
config/bundles.php
文件中
return [ ... Jgrasp\PrestashopMigrationPlugin\PrestashopMigrationPlugin::class => ['all' => true], ]
- 添加 .env 变量
# Enter the correct Prestashop database login details. PRESTASHOP_DATABASE_URL=mysql://root@127.0.0.1/sylius_%kernel.environment% # Custom the valid URL where product images are stored. If this variable is empty, the plugin will try to find images with the Prestashop database. PRESTASHOP_IMG_DIRECTORY_URL=https://www.example.com/img/p/
- 创建一个新的 doctrine DBAL 连接
doctrine: dbal: connection: prestashop: url: '%env(resolve:PRESTASHOP_DATABASE_URL)%'
- 添加包配置
在 config/packages
中创建一个新的配置文件,例如 prestashop.yaml
并放置此配置
prestashop_migration: # The directory for product images public_directory: "%env(PRESTASHOP_IMG_DIRECTORY_URL)%" # Doctrine DBAL connection to retrieve data from Prestashop connection: prestashop # Read the documentation to see how custom this field. resources: ~
- 自定义实体
添加以下代码
use PrestashopTrait;
在实体
App\Entity\Addressing\Address
App\Entity\Addressing\Country
App\Entity\Addressing\Zone
App\Entity\Channel\Channel
App\Entity\Currency\Currency
App\Entity\Customer\Customer
App\Entity\Locale\Locale
App\Entity\Product\Product
App\Entity\Product\ProductOption
App\Entity\Product\ProductOptionValue
App\Entity\Product\ProductVariant
App\Entity\Shipping\ShippingMethod
App\Entity\Taxation\TaxRate
App\Entity\User\AdminUser
此特质是必要的,并在Sylius和Prestashop实体之间添加链接。
App\Entity\Product\ProductVariant
应实现 Jgrasp\PrestashopMigrationPlugin\Entity\Product\ProductVariantInterface
。因此,添加以下代码
use Jgrasp\PrestashopMigrationPlugin\Entity\Product\ProductVariantInterface; class ProductVariant extends BaseProductVariant implements ProductVariantInterface{ }
- 升级数据库
$ php bin/console doctrine:migrations:diff $ php bin/console doctrine:migrations:migrate
- 配置区域参数
该参数必须是您要迁移的Prestashop中活动语言列表中存在的区域。否则,翻译迁移无法正确完成。
parameters: locale: en_EN
恭喜!您的项目已准备好迁移。让我们开始使用方法!