2

I need to validate custom quote item details, So I am overriding module AdvancedSalesRule "\Magento\AdvancedSalesRule\Model\Rule\Condition\Product" file. But Not getting quote item Id in model object. Below is code of override method.

/**
     * Validate Product Rule Condition
     *
     * @param \Magento\Framework\Model\AbstractModel $model
     * @return bool
     */
    public function validate(\Magento\Framework\Model\AbstractModel $model)
    {
        //@todo reimplement this method when is fixed MAGETWO-5713
        /** @var \Magento\Catalog\Model\Product $product */
        $product = $model->getProduct();
        if (!$product instanceof \Magento\Catalog\Model\Product) {
            $product = $this->productRepository->getById($model->getProductId());
        }

        if ($model instanceof \Magento\Quote\Model\Quote\Item) {
            echo $model->getItemId(); die; // Null
  • Can you please tell on what step you want to validate item detail and an example for it ? – Sunil Verma Feb 12 '18 at 8:05
0

I have replicated the same override on a test server M 2.2.2 with following code.

<?php

  namespace Net\Demo\Model\Rule\Condition;

  class Product extends \Magento\SalesRule\Model\Rule\Condition\Product {

    public function validate(\Magento\Framework\Model\AbstractModel $model)
    {
       //@todo reimplement this method when is fixed MAGETWO-5713
       /** @var \Magento\Catalog\Model\Product $product */
       $product = $model->getProduct();

      if (!$product instanceof \Magento\Catalog\Model\Product) {
        $product = $this->productRepository->getById($model->getProductId());
      }
      echo "<br>------".get_class($model)."---".$model->getItemId();
      $product->setQuoteItemQty($model->getQty())
              ->setQuoteItemPrice($model->getPrice()) // possible bug: need to use $model->getBasePrice()
              ->setQuoteItemRowTotal($model->getBaseRowTotal());

I am correctly getting the quote item id for the product as follows:

enter image description here

$model->getItemId();

so you should check your installation or upgrade it, it should work

Regards

Sunil

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.