当前位置: 首页>>代码示例>>PHP>>正文


PHP Data::getDefaultCountry方法代码示例

本文整理汇总了PHP中Magento\Core\Helper\Data::getDefaultCountry方法的典型用法代码示例。如果您正苦于以下问题:PHP Data::getDefaultCountry方法的具体用法?PHP Data::getDefaultCountry怎么用?PHP Data::getDefaultCountry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Core\Helper\Data的用法示例。


在下文中一共展示了Data::getDefaultCountry方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getConfigurationCountryCode

 /**
  * 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 (is_null($countryCode) || 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->_coreHelper->getDefaultCountry();
     }
     return $countryCode;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:16,代码来源:Backend.php

示例2: _afterLoad

 /**
  * 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\Core\Helper\Data::XML_PATH_DEFAULT_COUNTRY);
         } else {
             $defaultCountry = $this->_coreData->getDefaultCountry($this->getStore());
         }
         $this->setValue($defaultCountry);
     }
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:17,代码来源:MerchantCountry.php

示例3: getCountryId

 /**
  * @return string
  */
 public function getCountryId()
 {
     $countryId = $this->getData('country_id');
     if (is_null($countryId)) {
         $countryId = $this->_coreData->getDefaultCountry();
     }
     return $countryId;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:11,代码来源:Data.php

示例4: getCountryHtmlSelect

 /**
  * @param string $type
  * @return string
  */
 public function getCountryHtmlSelect($type)
 {
     $countryId = $this->getAddress()->getCountryId();
     if (is_null($countryId)) {
         $countryId = $this->_coreData->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();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:13,代码来源:AbstractOnepage.php

示例5: _prepareForm

 /**
  * Prepare Form and add elements to form
  *
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _prepareForm()
 {
     $fieldset = $this->_form->addFieldset('main', array('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->_customerHelper->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->_customerHelper->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 (is_null($this->_form->getElement('country_id')->getValue())) {
         $this->_form->getElement('country_id')->setValue($this->_coreData->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;
 }
开发者ID:zhangjiachao,项目名称:magento2,代码行数:61,代码来源:Address.php

示例6: render

 /**
  * 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->_coreHelper->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);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:27,代码来源:Country.php

示例7: getMerchantCountry

 /**
  * 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->_coreData->getDefaultCountry($this->_storeId);
     }
     return $countryCode;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:13,代码来源:Config.php

示例8: testGetDefaultCountry

 public function testGetDefaultCountry()
 {
     $this->assertEquals('US', $this->_helper->getDefaultCountry());
 }
开发者ID:,项目名称:,代码行数:4,代码来源:

示例9: initForm

 /**
  * 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', array('legend' => __("Edit Customer's Address")));
     $account = $customerData['account'];
     $this->_addressBuilder->populateWithArray(array());
     if (!empty($account) && isset($account['store_id'])) {
         $this->_addressBuilder->setCountryId($this->_coreData->getDefaultCountry($this->_storeManager->getStore($account['store_id'])));
     } else {
         $this->_addressBuilder->setCountryId($this->_coreData->getDefaultCountry());
     }
     $address = $this->_addressBuilder->create();
     $addressForm = $this->_metadataFormFactory->create('customer_address', 'adminhtml_customer_address', AddressConverter::toFlatArray($address));
     $attributes = $addressForm->getAttributes();
     if (isset($attributes['street'])) {
         if ($attributes['street']->getMultilineCount() <= 0) {
             $attributes['street'] = $this->_attributeMetadataBuilder->populate($attributes['street'])->setMultilineCount(self::DEFAULT_STREET_LINES_COUNT)->create();
         }
     }
     foreach ($attributes as $key => $attribute) {
         $attributes[$key] = $this->_attributeMetadataBuilder->populate($attribute)->setFrontendLabel(__($attribute->getFrontendLabel()))->setVisible(false)->create();
     }
     $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');
     }
     if ($this->isReadonly()) {
         foreach ($this->_metadataService->getAllAddressAttributeMetadata() 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->_customerHelper->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->_customerHelper->getNameSuffixOptions($customerStoreId);
         if (!empty($suffixOptions)) {
             $fieldset->removeField($suffixElement->getId());
             $suffixField = $fieldset->addField($suffixElement->getId(), 'select', $suffixElement->getData(), $form->getElement('lastname')->getId());
             $suffixField->setValues($suffixOptions);
         }
     }
     $this->assign('customer', $this->_customerBuilder->populateWithArray($account)->create());
     $addressCollection = array();
     foreach ($customerData['address'] as $key => $addressData) {
         $addressCollection[$key] = $this->_addressBuilder->populateWithArray($addressData)->create();
     }
     $this->assign('addressCollection', $addressCollection);
     $form->setValues(AddressConverter::toFlatArray($address));
     $this->setForm($form);
     return $this;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:86,代码来源:Addresses.php


注:本文中的Magento\Core\Helper\Data::getDefaultCountry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。