You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

复制修改促销活动遇故障:促销码无法兑换问题

复制促销活动后促销码无法兑换问题

我正在复制现有促销活动并进行小幅修改,目前仍有几个问题无法解决:

复制促销活动时的修改项:

  • 将active设为true
  • 生成新的code
  • 将createdAt设为当前日期
  • 将maxRedemptionsGlobal设为1
  • 将validFrom设为当前日期
  • 启用use_codes和useIndividualCodes
  • 将validUntill设为当前时间5分钟后的日期

此外删除了id、orderCount和ordersPerCustomerCount字段。

将修改后的数据传入后端路由,直接插入数据库后仅部分生效:促销活动在管理后台可见,但促销码无法兑换。奇怪的是,代码选项默认被设为「No Promotion code required」,手动改为「Fixed Promotion Code」后,自定义的促销码能正确显示,但仍然无法使用,持续收到「找不到促销码」的错误提示。

插入数据库的PHP代码

class getDiscountsController extends StorefrontController
{
    private EntityRepository $discountRepository;
    private EntityRepository $discountCartRepository;
    private EntityRepository $promotionRepository;

    public function __construct(
        EntityRepository $discountRepository,
        EntityRepository $discountCartRepository,
        EntityRepository $promotionRepository
    ) {
        $this->discountRepository = $discountRepository;
        $this->discountCartRepository = $discountCartRepository;
        $this->promotionRepository = $promotionRepository;
    }

    //other unrelevant code

    public function copyPromotion(string $code, string $promotionData, Context $context): JsonResponse
    {
        $promotionDataArray = json_decode($parsedPromotionData, true);

        unset($promotionDataArray['orderCount']);
        unset($promotionDataArray['ordersPerCustomerCount']);


        $this->promotionRepository->create([$promotionDataArray], $context);
    }
}

Service.xml相关配置

<service id="M28\LuckyDiscounts\Storefront\Controller\getDiscountsController" public="true">
  <argument type="service" id="m28_lucky_discounts.repository" />
  <argument type="service" id="m28_lucky_discounts_per_cart.repository" />
  <argument type="service" id="promotion.repository" />
  <call method="setContainer">
    <argument type="service" id="service_container" />
  </call>
</service>

内容的提问来源于stack exchange,提问作者EntchenEric

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 11:58:07