Пример #1
1
 /**
  * Get payment country
  *
  * @param Quote $quote
  * @return int
  */
 public function getCountry(Quote $quote)
 {
     $address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
     return $address ? $address->getCountry() : $this->directoryHelper->getDefaultCountry();
 }
Пример #2
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) {
         $countryCode = $this->_backendConfig->getConfigDataValue(\Magento\Paypal\Block\Adminhtml\System\Config\Field\Country::FIELD_CONFIG_PATH);
     }
     if (empty($countryCode)) {
         $countryCode = $this->directoryHelper->getDefaultCountry();
     }
     return $countryCode;
 }
Пример #3
0
 /**
  * Substitute empty value with Default country.
  *
  * @return void
  */
 protected function _afterLoad()
 {
     $value = (string) $this->getValue();
     if (empty($value)) {
         if ($this->getWebsite()) {
             $defaultCountry = $this->_storeManager->getWebsite($this->getWebsite())->getConfig(\Magento\Directory\Helper\Data::XML_PATH_DEFAULT_COUNTRY);
         } else {
             $defaultCountry = $this->directoryHelper->getDefaultCountry($this->getStore());
         }
         $this->setValue($defaultCountry);
     }
 }
Пример #4
0
 public function testGetDefaultCountry()
 {
     $storeId = 'storeId';
     $country = 'country';
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with(Data::XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)->will($this->returnValue($country));
     $this->assertEquals($country, $this->_object->getDefaultCountry($storeId));
 }
Пример #5
0
 /**
  * @return string
  */
 public function getCountryId()
 {
     $countryId = $this->getData('country_id');
     if ($countryId === null) {
         $countryId = $this->directoryHelper->getDefaultCountry();
     }
     return $countryId;
 }
Пример #6
0
 /**
  * @param string $type
  * @return string
  */
 public function getCountryHtmlSelect($type)
 {
     $countryId = $this->getAddress()->getCountryId();
     if ($countryId === null) {
         $countryId = $this->directoryHelper->getDefaultCountry();
     }
     $select = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setName($type . '[country_id]')->setId($type . ':country_id')->setTitle(__('Country'))->setClass('validate-select')->setValue($countryId)->setOptions($this->getCountryOptions());
     return $select->getHtml();
 }
Пример #7
0
 /**
  * Prepare Form and add elements to form
  *
  * @return $this
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _prepareForm()
 {
     $fieldset = $this->_form->addFieldset('main', ['no_container' => true]);
     $addressForm = $this->_customerFormFactory->create('customer_address', 'adminhtml_customer_address');
     $attributes = $addressForm->getAttributes();
     $this->_addAttributesToForm($attributes, $fieldset);
     $prefixElement = $this->_form->getElement('prefix');
     if ($prefixElement) {
         $prefixOptions = $this->options->getNamePrefixOptions($this->getStore());
         if (!empty($prefixOptions)) {
             $fieldset->removeField($prefixElement->getId());
             $prefixField = $fieldset->addField($prefixElement->getId(), 'select', $prefixElement->getData(), '^');
             $prefixField->setValues($prefixOptions);
             if ($this->getAddressId()) {
                 $prefixField->addElementValues($this->getAddress()->getPrefix());
             }
         }
     }
     $suffixElement = $this->_form->getElement('suffix');
     if ($suffixElement) {
         $suffixOptions = $this->options->getNameSuffixOptions($this->getStore());
         if (!empty($suffixOptions)) {
             $fieldset->removeField($suffixElement->getId());
             $suffixField = $fieldset->addField($suffixElement->getId(), 'select', $suffixElement->getData(), $this->_form->getElement('lastname')->getId());
             $suffixField->setValues($suffixOptions);
             if ($this->getAddressId()) {
                 $suffixField->addElementValues($this->getAddress()->getSuffix());
             }
         }
     }
     $regionElement = $this->_form->getElement('region_id');
     if ($regionElement) {
         $regionElement->setNoDisplay(true);
     }
     $this->_form->setValues($this->getFormValues());
     if ($this->_form->getElement('country_id')->getValue()) {
         $countryId = $this->_form->getElement('country_id')->getValue();
         $this->_form->getElement('country_id')->setValue(null);
         foreach ($this->_form->getElement('country_id')->getValues() as $country) {
             if ($country['value'] == $countryId) {
                 $this->_form->getElement('country_id')->setValue($countryId);
             }
         }
     }
     if ($this->_form->getElement('country_id')->getValue() === null) {
         $this->_form->getElement('country_id')->setValue($this->directoryHelper->getDefaultCountry($this->getStore()));
     }
     // Set custom renderer for VAT field if needed
     $vatIdElement = $this->_form->getElement('vat_id');
     if ($vatIdElement && $this->getDisplayVatValidationButton() !== false) {
         $vatIdElement->setRenderer($this->getLayout()->createBlock('Magento\\Customer\\Block\\Adminhtml\\Sales\\Order\\Address\\Form\\Renderer\\Vat')->setJsVariablePrefix($this->getJsVariablePrefix()));
     }
     return $this;
 }
Пример #8
0
 /**
  * Render country field considering request parameter
  *
  * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  * @return string
  */
 public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
 {
     $country = $this->getRequest()->getParam(StructurePlugin::REQUEST_PARAM_COUNTRY);
     if ($country) {
         $element->setValue($country);
     }
     if ($element->getCanUseDefaultValue()) {
         $this->_defaultCountry = $this->_scopeConfig->getValue(self::FIELD_CONFIG_PATH);
         if (!$this->_defaultCountry) {
             $this->_defaultCountry = $this->directoryHelper->getDefaultCountry();
         }
         if ($country) {
             $shouldInherit = $country == $this->_defaultCountry && $this->getRequest()->getParam(self::REQUEST_PARAM_DEFAULT_COUNTRY);
             $element->setInherit($shouldInherit);
         }
         if ($element->getInherit()) {
             $this->_defaultCountry = null;
         }
     }
     return parent::render($element);
 }
Пример #9
0
 /**
  * @param string $attributeCode
  * @return null|string
  */
 protected function getDefaultValue($attributeCode)
 {
     switch ($attributeCode) {
         case 'firstname':
             if ($this->getCustomer()) {
                 return $this->getCustomer()->getFirstname();
             }
             break;
         case 'lastname':
             if ($this->getCustomer()) {
                 return $this->getCustomer()->getLastname();
             }
             break;
         case 'country_id':
             return $this->directoryHelper->getDefaultCountry();
     }
     return null;
 }
Пример #10
0
 /**
  * Get default shipping rates
  *
  * @return array
  */
 private function getDefaultShippingRates()
 {
     $output = [];
     $addressKey = null;
     if ($this->checkoutSession->getQuote()->getId()) {
         $quote = $this->quoteRepository->get($this->checkoutSession->getQuote()->getId());
         /** @var \Magento\Quote\Api\Data\EstimateAddressInterface $estimatedAddress */
         $estimatedAddress = $this->estimatedAddressFactory->create();
         $address = $quote->getShippingAddress();
         if ($address && ($address->getCountryId() || $address->getPostcode() || $address->getRegion() || $address->getRegionId())) {
             $estimatedAddress->setCountryId($address->getCountryId());
             $estimatedAddress->setPostcode($address->getPostcode());
             $estimatedAddress->setRegion($address->getRegion());
             $estimatedAddress->setRegionId($address->getRegionId());
         } else {
             $estimatedAddress->setCountryId($this->directoryHelper->getDefaultCountry());
         }
         $rates = $this->shippingMethodManager->estimateByAddress($quote->getId(), $estimatedAddress);
         foreach ($rates as $rate) {
             $output[] = $rate->__toArray();
         }
         if ($address->getCustomerAddressId()) {
             $addressKey = 'customer-address' . $address->getCustomerAddressId();
         }
     }
     return ['key' => $addressKey, 'data' => $output];
 }
Пример #11
0
 /**
  * Return merchant country code, use default country if it not specified in General settings
  *
  * @return string
  */
 public function getMerchantCountry()
 {
     $countryCode = $this->_scopeConfig->getValue($this->_mapGeneralFieldset('merchant_country'));
     if (!$countryCode) {
         $countryCode = $this->directoryHelper->getDefaultCountry($this->_storeId);
     }
     return $countryCode;
 }
Пример #12
0
 public function testGetDefaultCountry()
 {
     $this->assertEquals('US', $this->helper->getDefaultCountry());
 }
 /**
  * Return merchant country code, use default country if it not specified in General settings
  *
  * @return string
  */
 public function getMerchantCountry()
 {
     $countryCode = $this->_scopeConfig->getValue($this->_mapGeneralFieldset('merchant_country'), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->_storeId);
     if (!$countryCode) {
         $countryCode = $this->directoryHelper->getDefaultCountry($this->_storeId);
     }
     return $countryCode;
 }
Пример #14
0
 /**
  * Return merchant country code, use default country if it not specified in General settings
  *
  * @return string
  */
 public function getMerchantCountry()
 {
     return $this->directoryHelper->getDefaultCountry($this->_storeId);
 }
Пример #15
0
 /**
  * {@inheritdoc}
  */
 public function getConfig()
 {
     $quoteId = $this->checkoutSession->getQuote()->getId();
     $output['formKey'] = $this->formKey->getFormKey();
     $output['customerData'] = $this->getCustomerData();
     $output['quoteData'] = $this->getQuoteData();
     $output['quoteItemData'] = $this->getQuoteItemData();
     $output['isCustomerLoggedIn'] = $this->isCustomerLoggedIn();
     $output['selectedShippingMethod'] = $this->getSelectedShippingMethod();
     $output['storeCode'] = $this->getStoreCode();
     $output['isGuestCheckoutAllowed'] = $this->isGuestCheckoutAllowed();
     $output['isCustomerLoginRequired'] = $this->isCustomerLoginRequired();
     $output['registerUrl'] = $this->getRegisterUrl();
     $output['checkoutUrl'] = $this->getCheckoutUrl();
     $output['pageNotFoundUrl'] = $this->pageNotFoundUrl();
     $output['forgotPasswordUrl'] = $this->getForgotPasswordUrl();
     $output['staticBaseUrl'] = $this->getStaticBaseUrl();
     $output['priceFormat'] = $this->localeFormat->getPriceFormat(null, $this->checkoutSession->getQuote()->getQuoteCurrencyCode());
     $output['basePriceFormat'] = $this->localeFormat->getPriceFormat(null, $this->checkoutSession->getQuote()->getBaseCurrencyCode());
     $output['postCodes'] = $this->postCodesConfig->getPostCodes();
     $output['imageData'] = $this->imageProvider->getImages($quoteId);
     $output['defaultCountryId'] = $this->directoryHelper->getDefaultCountry();
     $output['totalsData'] = $this->getTotalsData();
     $output['shippingPolicy'] = ['isEnabled' => $this->scopeConfig->isSetFlag('shipping/shipping_policy/enable_shipping_policy', ScopeInterface::SCOPE_STORE), 'shippingPolicyContent' => nl2br($this->scopeConfig->getValue('shipping/shipping_policy/shipping_policy_content', ScopeInterface::SCOPE_STORE))];
     $output['activeCarriers'] = $this->getActiveCarriers();
     $output['originCountryCode'] = $this->getOriginCountryCode();
     $output['paymentMethods'] = $this->getPaymentMethods();
     $output['autocomplete'] = $this->isAutocompleteEnabled();
     return $output;
 }
Пример #16
0
 /**
  * Initialize form object
  *
  * @return $this
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function initForm()
 {
     $customerData = $this->_backendSession->getCustomerData();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $fieldset = $form->addFieldset('address_fieldset', ['legend' => __("Edit Customer's Address")]);
     $account = $customerData['account'];
     $address = $this->addressDataFactory->create();
     if (!empty($account) && isset($account['store_id'])) {
         $address->setCountryId($this->_directoryHelper->getDefaultCountry($this->_storeManager->getStore($account['store_id'])));
     } else {
         $address->setCountryId($this->_directoryHelper->getDefaultCountry());
     }
     $addressForm = $this->_metadataFormFactory->create('customer_address', 'adminhtml_customer_address', $this->addressMapper->toFlatArray($address));
     $attributes = $addressForm->getAttributes();
     if (isset($attributes['street'])) {
         if ($attributes['street']->getMultilineCount() <= 0) {
             $attributes['street']->setMultilineCount(self::DEFAULT_STREET_LINES_COUNT);
         }
     }
     foreach ($attributes as $key => $attribute) {
         $attributes[$key]->setFrontendLabel(__($attribute->getFrontendLabel()))->setIsVisible(false);
     }
     $this->_setFieldset($attributes, $fieldset);
     $regionElement = $form->getElement('region');
     if ($regionElement) {
         $regionElement->setRenderer($this->_regionFactory->create());
     }
     $regionElement = $form->getElement('region_id');
     if ($regionElement) {
         $regionElement->setNoDisplay(true);
     }
     $country = $form->getElement('country_id');
     if ($country) {
         $country->addClass('countries');
     }
     $postcode = $form->getElement('postcode');
     if ($postcode) {
         $postcode->removeClass('required-entry')->setRequired(!$this->_directoryHelper->isZipCodeOptional($address->getCountryId()));
     }
     if ($this->isReadonly()) {
         foreach ($this->_addressMetadataService->getAllAttributesMetadata() as $attribute) {
             $element = $form->getElement($attribute->getAttributeCode());
             if ($element) {
                 $element->setReadonly(true, true);
             }
         }
     }
     $customerStoreId = null;
     if (!empty($account) && isset($account['id']) && isset($account['website_id'])) {
         $customerStoreId = $this->_storeManager->getWebsite($account['website_id'])->getDefaultStore()->getId();
     }
     $prefixElement = $form->getElement('prefix');
     if ($prefixElement) {
         $prefixOptions = $this->options->getNamePrefixOptions($customerStoreId);
         if (!empty($prefixOptions)) {
             $fieldset->removeField($prefixElement->getId());
             $prefixField = $fieldset->addField($prefixElement->getId(), 'select', $prefixElement->getData(), '^');
             $prefixField->setValues($prefixOptions);
         }
     }
     $suffixElement = $form->getElement('suffix');
     if ($suffixElement) {
         $suffixOptions = $this->options->getNameSuffixOptions($customerStoreId);
         if (!empty($suffixOptions)) {
             $fieldset->removeField($suffixElement->getId());
             $suffixField = $fieldset->addField($suffixElement->getId(), 'select', $suffixElement->getData(), $form->getElement('lastname')->getId());
             $suffixField->setValues($suffixOptions);
         }
     }
     $customerDataObject = $this->customerDataFactory->create();
     $this->dataObjectHelper->populateWithArray($customerDataObject, $account, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->assign('customer', $customerDataObject);
     $addressCollection = [];
     foreach ($customerData['address'] as $key => $addressData) {
         $addressDataObject = $this->addressDataFactory->create();
         $this->dataObjectHelper->populateWithArray($addressDataObject, $addressData, '\\Magento\\Customer\\Api\\Data\\AddressInterface');
         $addressCollection[$key] = $addressDataObject;
     }
     $this->assign('addressCollection', $addressCollection);
     $form->setValues($this->addressMapper->toFlatArray($address));
     $this->setForm($form);
     return $this;
 }
Пример #17
0
 /**
  * Get payment country
  *
  * @param Quote $quote
  * @return int
  */
 public function getCountry(Quote $quote)
 {
     return $quote->isVirtual() ? $this->directoryHelper->getDefaultCountry() : $quote->getShippingAddress()->getCountry();
 }