Пример #1
0
 /**
  * @param \Magento\Framework\DataObject $request
  * @return $this|bool|false|\Magento\Framework\Model\AbstractModel
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function checkAvailableShipCountries(\Magento\Framework\DataObject $request)
 {
     $speCountriesAllow = $this->getConfigData('sallowspecific');
     /*
      * for specific countries, the flag will be 1
      */
     if ($speCountriesAllow && $speCountriesAllow == 1) {
         $showMethod = $this->getConfigData('showmethod');
         $availableCountries = [];
         if ($this->getConfigData('specificcountry')) {
             $availableCountries = explode(',', $this->getConfigData('specificcountry'));
         }
         if ($availableCountries && in_array($request->getDestCountryId(), $availableCountries)) {
             return $this;
         } elseif ($showMethod && (!$availableCountries || $availableCountries && !in_array($request->getDestCountryId(), $availableCountries))) {
             /** @var Error $error */
             $error = $this->_rateErrorFactory->create();
             $error->setCarrier($this->_code);
             $error->setCarrierTitle($this->getConfigData('title'));
             $errorMsg = $this->getConfigData('specificerrmsg');
             $error->setErrorMessage($errorMsg ? $errorMsg : __('Sorry, but we can\'t deliver to the destination country with this shipping module.'));
             return $error;
         } else {
             /*
              * The admin set not to show the shipping module if the delivery country is not within specific countries
              */
             return false;
         }
     }
     return $this;
 }