Ejemplo n.º 1
0
 /**
  * Get selected merchant country code in system configuration
  *
  * @return string
  */
 public function getConfigurationCountryCode()
 {
     $countryCode = $this->_request->getParam(\Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY);
     if ($countryCode === null || preg_match('/^[a-zA-Z]{2}$/', $countryCode) == 0) {
         $scope = $this->scopeDefiner->getScope();
         if ($scope != ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
             $this->backendConfig->setData($scope, $this->_request->getParam($scope));
         }
         $countryCode = $this->backendConfig->getConfigDataValue(\Magento\Paypal\Block\Adminhtml\System\Config\Field\Country::FIELD_CONFIG_PATH);
     }
     if (empty($countryCode)) {
         $countryCode = $this->directoryHelper->getDefaultCountry();
     }
     return $countryCode;
 }
 /**
  * Substitute payment section with PayPal configs
  *
  * @param \Magento\Config\Model\Config\Structure $subject
  * @param \Closure $proceed
  * @param array $pathParts
  * @return \Magento\Config\Model\Config\Structure\ElementInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGetElementByPathParts(\Magento\Config\Model\Config\Structure $subject, \Closure $proceed, array $pathParts)
 {
     $isSectionChanged = $pathParts[0] == 'payment';
     if ($isSectionChanged) {
         $requestedCountrySection = 'payment_' . strtolower($this->_helper->getConfigurationCountryCode());
         if (in_array($requestedCountrySection, self::getPaypalConfigCountries())) {
             $pathParts[0] = $requestedCountrySection;
         } else {
             $pathParts[0] = 'payment_other';
         }
     }
     /** @var \Magento\Config\Model\Config\Structure\ElementInterface $result */
     $result = $proceed($pathParts);
     if ($isSectionChanged && isset($result)) {
         if ($result instanceof \Magento\Config\Model\Config\Structure\Element\Section) {
             $result->setData(array_merge($result->getData(), ['showInDefault' => true, 'showInWebsite' => true, 'showInStore' => true]), $this->_scopeDefiner->getScope());
         }
     }
     return $result;
 }
 public function testGetScopeReturnsWebsiteScopeIfWebsiteIsSpecified()
 {
     $this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap([['website', null, 'someWebsite'], ['store', null, null]]));
     $this->assertEquals(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, $this->_model->getScope());
 }
Ejemplo n.º 4
0
 /**
  * Prepare backend config for test
  *
  * @param string|null|false $config
  */
 private function configurationCountryCodePrepareConfig($config)
 {
     $this->scopeDefiner->expects($this->once())->method('getScope')->willReturn(self::SCOPE);
     $this->backendConfig->expects($this->once())->method('setData')->with(self::SCOPE, self::SCOPE_ID);
     $this->backendConfig->expects($this->once())->method('getConfigDataValue')->with(\Magento\Paypal\Block\Adminhtml\System\Config\Field\Country::FIELD_CONFIG_PATH)->willReturn($config);
 }