0
{
public function execute(\Magento\Framework\Event\Observer $observer)
     {
         $request = $this->_appRequestInterface->getPost(); 
            
          try
          {
              if($this->_configScopeConfigInterface->getValue('minqty/general/enabled', ScopeInterface::SCOPE_STORE,$this->_modelStoreManagerInterface->getStore())) :
            
              $main_product_id = 0;
              if(array_key_exists('super_group',$request) && array_key_exists('product',$request))
              {
                  $main_product_id = $request['product'];
                  $main_product = $this->_modelProductFactory->create()->load($main_product_id);
                  $allowed_qty = $main_product->getCustomminqty();
                   
                  if($allowed_qty > 0 && $allowed_qty != '')
                  {     
                      $total_qty = 0;
                      foreach($request['super_group'] as $cur_qty)
                      {
                          if($cur_qty != '')
                          {
                              $total_qty = $total_qty + $cur_qty;
                          }
                      }
                        
                      if($total_qty < $allowed_qty)
                      {  
                          $message = "The minimum quantity allowed for purchase is ".$allowed_qty.".";
                          throw new \Magento\Framework\Exception\LocalizedException(__($message));
                          return;
                      }
                  }
              }
              endif;
          }
          catch(Exception $e)
          {
            throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage())); 
            return;
          }}

1 Answer 1

2

Since PHP 7.4 the function array_key_exists allows only array and doesn't support ArrayObject anymore

The method getPost from Request returns \Laminas\Stdlib\Parameters which extends from ArrayObject

You can use Parameters method toArray to receive array or use offsetExists instead of array_key_exists

$postArray = $this->_appRequestInterface->getPost()->toArray();
array_key_exists('key', $postArray);

// or
$post = $this->_appRequestInterface->getPost();
$post->offsetExists('key');

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.