MENU
  • サービス
    • Struccle(ストラクル)
      • スクレイピングテンプレート
    • AI エージェント
  • 事例
  • 料金
  • ブログ
  • FAQ
  • サポート
    • クイックスタート
    • 操作ガイド
    • Struccle コミュニティ
  • 会社概要
    • About us
    • お問い合わせ
  • 資料
上場企業から個人まで、スクレイピングツールの決定版
  • Home
  • General
  • Guides
  • Reviews
  • News
   12/31まで無料相談受付中
   無料で始める
Struccle
  • サービス
    • Struccle(ストラクル)
      • スクレイピングテンプレート
    • AI エージェント
  • 事例
  • 料金
  • ブログ
  • FAQ
  • サポート
    • クイックスタート
    • 操作ガイド
    • Struccle コミュニティ
  • 会社概要
    • About us
    • お問い合わせ
  • 資料
  1. ホーム
  2. Struccle
  3. magento 2 get coupon code programmatically
  4. magento 2 get coupon code programmatically

Magento | 2 Get Coupon Code Programmatically

try $quote = $this->quoteRepository->get($quoteId); return $quote->getCouponCode(); catch (NoSuchEntityException $e) return null;

use Magento\Quote\Model\QuoteFactory; public function getCouponCodeFromQuote(QuoteFactory $quoteFactory, $quoteId)

class GetAllCouponCodes

<?php namespace YourNamespace\YourModule\Controller\Index; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\Controller\Result\JsonFactory; use YourNamespace\YourModule\Model\GetCouponCodeService; magento 2 get coupon code programmatically

try $order = $this->orderRepository->get($orderId); return $order->getCouponCode(); catch (\Exception $e) return null;

$collection = $this->couponCollectionFactory->create(); $collection->addFieldToSelect(['code', 'usage_limit', 'times_used', 'expiration_date']); $coupons = []; foreach ($collection as $coupon) $coupons[] = [ 'code' => $coupon->getCode(), 'usage_limit' => $coupon->getUsageLimit(), 'times_used' => $coupon->getTimesUsed(), 'expires_at' => $coupon->getExpirationDate() ]; return $coupons;

class GetCouponFromOrder

public function __construct( CartRepositoryInterface $quoteRepository, CustomerSession $customerSession, CheckoutSession $checkoutSession ) $this->quoteRepository = $quoteRepository; $this->customerSession = $customerSession; $this->checkoutSession = $checkoutSession;

private GetCouponCodeService $couponService; private JsonFactory $resultJsonFactory;

$this->couponCollectionFactory = $couponCollectionFactory; try $quote = $this-&gt

$result = $this->resultJsonFactory->create(); $couponCode = $this->couponService->fromCurrentSession(); return $result->setData([ 'success' => true, 'coupon_code' => $couponCode ?: 'No coupon applied' ]);

private CartRepositoryInterface $quoteRepository; private CustomerSession $customerSession; private CheckoutSession $checkoutSession;

return $quote->getCouponCode();

カテゴリー
人気記事
  • File
  • Madha Gaja Raja Tamil Movie Download Kuttymovies In
  • Apk Cort Link
  • Quality And All Size Free Dual Audio 300mb Movies
  • Malayalam Movies Ogomovies.ch
新着記事
  • magento 2 get coupon code programmatically
    【ものログスクレイピング】Struccleで商品口コミデータを収集し、競合・市場調査
  • magento 2 get coupon code programmatically
    【決定版】Chromeスクレイピング拡張機能比較!7選
  • magento 2 get coupon code programmatically
    「カスタム収集」の基本的な使い方
目次

Copyright © 2026 Venture Crossroad

目次