public function __construct(
            ScopeConfigInterface $scopeConfig,
            RateErrorFactory $rateErrorFactory,
            Session $session,

            LoggerInterface $logger,
            RateResultFactory $rateResultFactory,
            RateMethodFactory $rateMethodFactory,
            ProductFactory $productFactory,
            array $data = []
        ) {
            $this->_productFactory   = $productFactory;
            $this->_rateResultFactory = $rateResultFactory;
            $this->_session = $session;
            $this->_rateMethodFactory = $rateMethodFactory;
            parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);
 public function isActive()

        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/somelog.log');
        $logger = new \Zend\Log\Logger();

        /** @var $item \Magento\Quote\Model\Quote\Item */
        $items = $this->_session->getQuote()->getAllItems();
        foreach ($items as $item) {
            $productid = $item->getProductId();

            $product = $this->_productFactory->create()->load($productid);
            $categoriesIds = $product->getCategoryIds();

here I only get the id of the first product from the basket, how to get all the id products from the basket

  • I don't know about this. But thanks for sharing this useful information. – user78033 Mar 23 '19 at 10:43

Try THis For Get Basket Product :-

protected $_cart;

public function __construct(\Magento\Checkout\Model\Cart $cart)
    $this->_cart = $cart;

public function yourfunction()
    $cartProductList = $this->_cart->getQuote()->getAllItems();

    foreach($cartProductList as $item) {

        echo 'ID: '.$item->getProductId().'<br />';      


try this to get all the basket productId protected $_cart;

public function __construct(\Magento\Checkout\Model\Cart $cart) {

$this->_cart = $cart;


public function yourfunction() {

$cartProductId = $this->_cart->getQuoteProductIds();

//you will get array of product id


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.