setono/sylius-catalog-promotion-plugin
Composer 安装命令:
composer require setono/sylius-catalog-promotion-plugin
包简介
Catalog promotion plugin for Sylius
README 文档
README
Plugin for Sylius to define permanent or time-limited promotions for products and automatically update prices.
Install
Add plugin to composer.json
composer require setono/sylius-catalog-promotion-plugin
NOTICE that this plugin uses the twig/string-extra and twig/extra-bundle internally to do string manipulation in Twig.
It should work out of the box with the Symfony Flex recipe, but if you're not using Symfony Flex, you should install the bundle manually.
Register plugin
<?php # config/bundles.php return [ // ... Setono\SyliusCatalogPromotionPlugin\SetonoSyliusCatalogPromotionPlugin::class => ['all' => true], Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], // ... ];
Note, that we MUST define SetonoSyliusCatalogPromotionPlugin BEFORE SyliusGridBundle.
Otherwise, you'll see exception like this:
You have requested a non-existent parameter "setono_sylius_catalog_promotion.model.catalog_promotion.class".
Add routing
# config/routes/setono_sylius_catalog_promotion.yaml setono_sylius_catalog_promotion: resource: "@SetonoSyliusCatalogPromotionPlugin/Resources/config/routes.yaml"
Extend core classes
TODO: Extend Product class
Create migration
php bin/console doctrine:migrations:diff php bin/console doctrine:migrations:migrate
Install assets
bin/console sylius:install:assets
Configure cron (optional)
# Will process _all_ catalog promotions for _all_ products # You can run this once a day as a fallback for events triggering the update process php bin/console setono:sylius-catalog-promotion:process # Will prune/remove catalog promotion updates older then the given threshold php bin/console setono:sylius-catalog-promotion:prune-catalog-promotion-updates
Apply catalog promotions outside request/response life cycle
Most likely you need to apply catalog promotions outside a request/response lifecycle at some point. A good example could be the generation of product feeds. To do that you need to set the channel context to the respective channel you are processing.
You do this using the \Setono\SyliusCatalogPromotionPlugin\Context\StaticChannelContext:
<?php use Setono\SyliusCatalogPromotionPlugin\Context\StaticChannelContext; use Sylius\Component\Channel\Model\ChannelInterface; class YourFeedProcessor { public function __construct(private readonly StaticChannelContext $staticChannelContext) { } public function process(): void { /** * A list of channels you need to process * * @var list<ChannelInterface> $channels */ $channels = []; foreach ($channels as $channel) { $this->staticChannelContext->setChannel($channel); // do your processing... } } }
Check if a product is on sale
If you want to check if a product is on sale, e.g. if you want to have a Sale category on your store, we have included
a \Setono\SyliusCatalogPromotionPlugin\Checker\OnSale\OnSaleCheckerInterface service that checks exactly that:
<?php use Setono\SyliusCatalogPromotionPlugin\Checker\OnSale\OnSaleCheckerInterface; use Setono\SyliusCatalogPromotionPlugin\Model\ProductInterface; class YourFeedProcessor { public function __construct(private readonly OnSaleCheckerInterface $onSaleChecker) { } public function process(): void { /** * A list of products you are processing * * @var list<ProductInterface> $products */ $products = []; foreach ($products as $product) { if($this->onSaleChecker->onSale($product)) { // the product is on sale } } } }
setono/sylius-catalog-promotion-plugin 适用场景与选型建议
setono/sylius-catalog-promotion-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 69.63k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2019 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「catalog」 「sylius」 「promotions」 「sylius-plugin」 「setono」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 setono/sylius-catalog-promotion-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 setono/sylius-catalog-promotion-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 setono/sylius-catalog-promotion-plugin 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Promotions for Purchases
Implementation of the Omnibus Directive for Sylius application.
Bulk export of sylius resources
Sylius plugin that integrates Addwish
Manage ecommerce promotions system in your Symfony2 application.
Setono example plugin for Sylius.
统计信息
- 总下载量: 69.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-02
