承接 setono/sylius-catalog-promotion-plugin 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

setono/sylius-catalog-promotion-plugin

最新稳定版本:v1.0.0-beta

Composer 安装命令:

composer require setono/sylius-catalog-promotion-plugin

包简介

Catalog promotion plugin for Sylius

README 文档

README

Latest Version Latest Unstable Version Software License Build Status

Plugin for Sylius to define permanent or time-limited promotions for products and automatically update prices.

Screenshot showing catalog promotions admin page

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
            }
        }
    }
}

统计信息

  • 总下载量: 68.71k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 2
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-02