/** * Render block HTML * * @return string */ protected function _toHtml() { $localeCode = $this->_localeResolver->getLocaleCode(); // get days names $days = \Zend_Locale_Data::getList($localeCode, 'days'); $this->assign('days', array('wide' => $this->encoder->encode(array_values($days['format']['wide'])), 'abbreviated' => $this->encoder->encode(array_values($days['format']['abbreviated'])))); // get months names $months = \Zend_Locale_Data::getList($localeCode, 'months'); $this->assign('months', array('wide' => $this->encoder->encode(array_values($months['format']['wide'])), 'abbreviated' => $this->encoder->encode(array_values($months['format']['abbreviated'])))); // get "today" and "week" words $this->assign('today', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'relative', 0))); $this->assign('week', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'field', 'week'))); // get "am" & "pm" words $this->assign('am', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'am'))); $this->assign('pm', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'pm'))); // get first day of week and weekend days $this->assign('firstDay', (int) $this->_scopeConfig->getValue('general/locale/firstday', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $this->assign('weekendDays', $this->encoder->encode((string) $this->_scopeConfig->getValue('general/locale/weekend', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))); // define default format and tooltip format $this->assign('defaultFormat', $this->encoder->encode($this->_localeDate->getDateFormat(TimezoneInterface::FORMAT_TYPE_MEDIUM))); $this->assign('toolTipFormat', $this->encoder->encode($this->_localeDate->getDateFormat(TimezoneInterface::FORMAT_TYPE_LONG))); // get days and months for en_US locale - calendar will parse exactly in this locale $days = \Zend_Locale_Data::getList('en_US', 'days'); $months = \Zend_Locale_Data::getList('en_US', 'months'); $enUS = new \stdClass(); $enUS->m = new \stdClass(); $enUS->m->wide = array_values($months['format']['wide']); $enUS->m->abbr = array_values($months['format']['abbreviated']); $this->assign('enUS', $this->encoder->encode($enUS)); return parent::_toHtml(); }
/** * Get current language * * @return string */ public function getLang() { if (!$this->hasData('lang')) { $this->setData('lang', substr($this->_localeResolver->getLocaleCode(), 0, 2)); } return $this->getData('lang'); }
/** * Initialize select object * * @return $this */ protected function _initSelect() { parent::_initSelect(); $locale = $this->_localeResolver->getLocaleCode(); $this->addBindParam(':region_locale', $locale); $this->getSelect()->joinLeft(array('rname' => $this->_regionNameTable), 'main_table.region_id = rname.region_id AND rname.locale = :region_locale', array('name')); return $this; }
/** * Process localized quantity to internal format * * @param float $qty * @return array|string */ public function process($qty) { $this->localFilter->setOptions(array('locale' => $this->localeResolver->getLocaleCode())); $qty = $this->localFilter->filter((double) $qty); if ($qty < 0) { $qty = null; } return $qty; }
/** * Disable block output if logo turned off *M * @return string */ protected function _toHtml() { $type = $this->getLogoType(); // assigned in layout etc. $logoUrl = $this->_getConfig()->getAdditionalOptionsLogoUrl($this->_localeResolver->getLocaleCode(), $type); if (!$logoUrl) { return ''; } $this->setLogoImageUrl($logoUrl); return parent::_toHtml(); }
/** * Process localized quantity to internal format * * @param float $qty * @return array|string */ public function process($qty) { if (!$this->localFilter) { $this->localFilter = new \Zend_Filter_LocalizedToNormalized(array('locale' => $this->localeResolver->getLocaleCode())); } $qty = $this->localFilter->filter((double) $qty); if ($qty < 0) { $qty = null; } return $qty; }
/** * Save translation * * @param String $string * @param String $translate * @param String $locale * @param int|null $storeId * @return $this */ public function saveTranslate($string, $translate, $locale = null, $storeId = null) { $write = $this->_getWriteAdapter(); $table = $this->getMainTable(); if (is_null($locale)) { $locale = $this->_localeResolver->getLocaleCode(); } if (is_null($storeId)) { $storeId = $this->getStoreId(); } $select = $write->select()->from($table, array('key_id', 'translate'))->where('store_id = :store_id')->where('locale = :locale')->where('string = :string')->where('crc_string = :crc_string'); $bind = array('store_id' => $storeId, 'locale' => $locale, 'string' => $string, 'crc_string' => crc32($string)); if ($row = $write->fetchRow($select, $bind)) { $original = $string; if (strpos($original, '::') !== false) { list(, $original) = explode('::', $original); } if ($original == $translate) { $write->delete($table, array('key_id=?' => $row['key_id'])); } elseif ($row['translate'] != $translate) { $write->update($table, array('translate' => $translate), array('key_id=?' => $row['key_id'])); } } else { $write->insert($table, array('store_id' => $storeId, 'locale' => $locale, 'string' => $string, 'translate' => $translate, 'crc_string' => crc32($string))); } return $this; }
/** * Load backup file info * * @param string $fileName * @param string $filePath * @return $this */ public function load($fileName, $filePath) { $backupData = $this->_helper->extractDataFromFilename($fileName); $this->addData(array('id' => $filePath . '/' . $fileName, 'time' => (int) $backupData->getTime(), 'path' => $filePath, 'extension' => $this->_helper->getExtensionByType($backupData->getType()), 'display_name' => $this->_helper->nameToDisplayName($backupData->getName()), 'name' => $backupData->getName(), 'date_object' => new \Magento\Framework\Stdlib\DateTime\Date((int) $backupData->getTime(), $this->_localeResolver->getLocaleCode()))); $this->setType($backupData->getType()); return $this; }
/** * Convert collection items to select options array * * @param string|boolean $emptyLabel * @return array */ public function toOptionArray($emptyLabel = ' ') { $options = $this->_toOptionArray('country_id', 'name', array('title' => 'iso2_code')); $sort = array(); foreach ($options as $data) { $name = (string) $this->_localeLists->getCountryTranslation($data['value']); if (!empty($name)) { $sort[$name] = $data['value']; } } $this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocaleCode()); foreach (array_reverse($this->_foregroundCountries) as $foregroundCountry) { $name = array_search($foregroundCountry, $sort); unset($sort[$name]); $sort = array($name => $foregroundCountry) + $sort; } $options = array(); foreach ($sort as $label => $value) { $options[] = array('value' => $value, 'label' => $label); } if (count($options) > 0 && $emptyLabel !== false) { array_unshift($options, array('value' => '', 'label' => $emptyLabel)); } return $options; }
/** * Functions returns array with price formatting info * * @return array */ public function getPriceFormat() { $format = \Zend_Locale_Data::getContent($this->_localeResolver->getLocaleCode(), 'currencynumber'); $symbols = \Zend_Locale_Data::getList($this->_localeResolver->getLocaleCode(), 'symbols'); $pos = strpos($format, ';'); if ($pos !== false) { $format = substr($format, 0, $pos); } $format = preg_replace("/[^0\\#\\.,]/", "", $format); $totalPrecision = 0; $decimalPoint = strpos($format, '.'); if ($decimalPoint !== false) { $totalPrecision = strlen($format) - (strrpos($format, '.') + 1); } else { $decimalPoint = strlen($format); } $requiredPrecision = $totalPrecision; $t = substr($format, $decimalPoint); $pos = strpos($t, '#'); if ($pos !== false) { $requiredPrecision = strlen($t) - $pos - $totalPrecision; } if (strrpos($format, ',') !== false) { $group = $decimalPoint - strrpos($format, ',') - 1; } else { $group = strrpos($format, '.'); } $integerRequired = strpos($format, '.') - strpos($format, '0'); $result = array('pattern' => $this->_scopeResolver->getScope()->getCurrentCurrency()->getOutputFormat(), 'precision' => $totalPrecision, 'requiredPrecision' => $requiredPrecision, 'decimalSymbol' => $symbols['decimal'], 'groupSymbol' => $symbols['group'], 'groupLength' => $group, 'integerRequired' => $integerRequired); return $result; }
/** * Apply locale of the specified store * * @param integer $storeId * @param string $area * @return string initial locale code */ protected function _emulateLocale($storeId, $area = \Magento\Framework\App\Area::AREA_FRONTEND) { $initialLocaleCode = $this->_localeResolver->getLocaleCode(); $newLocaleCode = $this->_scopeConfig->getValue($this->_localeResolver->getDefaultLocalePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $this->_localeResolver->setLocaleCode($newLocaleCode); $this->_translate->setLocale($newLocaleCode)->loadData($area, true); return $initialLocaleCode; }
/** * Get Key pieces for caching block content * * @return array */ public function getCacheKeyInfo() { $cacheKeyInfo = array('admin_top_nav', $this->getActive(), $this->_authSession->getUser()->getId(), $this->_localeResolver->getLocaleCode()); // Add additional key parameters if needed $newCacheKeyInfo = $this->getAdditionalCacheKeyInfo(); if (is_array($newCacheKeyInfo) && !empty($newCacheKeyInfo)) { $cacheKeyInfo = array_merge($cacheKeyInfo, $newCacheKeyInfo); } return $cacheKeyInfo; }
/** * Set session locale, * process force locale set through url params * * @return $this */ protected function _processLocaleSettings() { $forceLocale = $this->getRequest()->getParam('locale', null); if ($this->_objectManager->get('Magento\\Framework\\Locale\\Validator')->isValid($forceLocale)) { $this->_getSession()->setSessionLocale($forceLocale); } if (is_null($this->_getSession()->getLocale())) { $this->_getSession()->setLocale($this->_localeResolver->getLocaleCode()); } return $this; }
/** * Create \Zend_Currency object for current locale * * @param string $currency * @return \Magento\Framework\Currency */ public function getCurrency($currency) { \Magento\Framework\Profiler::start('locale/currency'); if (!isset(self::$_currencyCache[$this->_localeResolver->getLocaleCode()][$currency])) { $options = array(); try { $currencyObject = $this->_currencyFactory->create(array('options' => $currency, 'locale' => $this->_localeResolver->getLocale())); } catch (\Exception $e) { $currencyObject = $this->_currencyFactory->create(array('options' => $this->getDefaultCurrency(), 'locale' => $this->_localeResolver->getLocale())); $options['name'] = $currency; $options['currency'] = $currency; $options['symbol'] = $currency; } $options = new \Magento\Framework\Object($options); $this->_eventManager->dispatch('currency_display_options_forming', array('currency_options' => $options, 'base_code' => $currency)); $currencyObject->setFormat($options->toArray()); self::$_currencyCache[$this->_localeResolver->getLocaleCode()][$currency] = $currencyObject; } \Magento\Framework\Profiler::stop('locale/currency'); return self::$_currencyCache[$this->_localeResolver->getLocaleCode()][$currency]; }
/** * Load object by country id and code or default name * * @param \Magento\Framework\Model\AbstractModel $object * @param int $countryId * @param string $value * @param string $field * @return $this */ protected function _loadByCountry($object, $countryId, $value, $field) { $adapter = $this->_getReadAdapter(); $locale = $this->_localeResolver->getLocaleCode(); $joinCondition = $adapter->quoteInto('rname.region_id = region.region_id AND rname.locale = ?', $locale); $select = $adapter->select()->from(array('region' => $this->getMainTable()))->joinLeft(array('rname' => $this->_regionNameTable), $joinCondition, array('name'))->where('region.country_id = ?', $countryId)->where("region.{$field} = ?", $value); $data = $adapter->fetchRow($select); if ($data) { $object->setData($data); } $this->_afterLoad($object); return $this; }
/** * Prepare data for save * * @return $this * @throws Exception */ protected function _beforeSave() { // prevent overriding product data if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) { throw new Exception(__('The attribute code \'%1\' is reserved by system. Please try another attribute code', $this->_data['attribute_code'])); } /** * Check for maximum attribute_code length */ if (isset($this->_data['attribute_code']) && !\Zend_Validate::is($this->_data['attribute_code'], 'StringLength', array('max' => self::ATTRIBUTE_CODE_MAX_LENGTH))) { throw new Exception(__('Maximum length of attribute code must be less than %1 symbols', self::ATTRIBUTE_CODE_MAX_LENGTH)); } $defaultValue = $this->getDefaultValue(); $hasDefaultValue = (string) $defaultValue != ''; if ($this->getBackendType() == 'decimal' && $hasDefaultValue) { if (!\Zend_Locale_Format::isNumber($defaultValue, array('locale' => $this->_localeResolver->getLocaleCode()))) { throw new Exception(__('Invalid default decimal value')); } try { $filter = new \Zend_Filter_LocalizedToNormalized(array('locale' => $this->_localeResolver->getLocaleCode())); $this->setDefaultValue($filter->filter($defaultValue)); } catch (\Exception $e) { throw new Exception(__('Invalid default decimal value')); } } if ($this->getBackendType() == 'datetime') { if (!$this->getBackendModel()) { $this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\Datetime'); } if (!$this->getFrontendModel()) { $this->setFrontendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\Datetime'); } // save default date value as timestamp if ($hasDefaultValue) { $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); try { $defaultValue = $this->_localeDate->date($defaultValue, $format, null, false)->toValue(); $this->setDefaultValue($defaultValue); } catch (\Exception $e) { throw new Exception(__('Invalid default date')); } } } if ($this->getBackendType() == 'gallery') { if (!$this->getBackendModel()) { $this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\DefaultBackend'); } } return parent::_beforeSave(); }
/** * @return string */ public function getHtml() { $htmlId = $this->mathRandom->getUniqueHash($this->_getHtmlId()); $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); $html = '<div class="range" id="' . $htmlId . '_range"><div class="range-line date">' . '<input type="text" name="' . $this->_getHtmlName() . '[from]" id="' . $htmlId . '_from"' . ' value="' . $this->getEscapedValue('from') . '" class="input-text no-changes" placeholder="' . __('From') . '" ' . $this->getUiId('filter', $this->_getHtmlName(), 'from') . '/>' . '</div>'; $html .= '<div class="range-line date">' . '<input type="text" name="' . $this->_getHtmlName() . '[to]" id="' . $htmlId . '_to"' . ' value="' . $this->getEscapedValue('to') . '" class="input-text no-changes" placeholder="' . __('To') . '" ' . $this->getUiId('filter', $this->_getHtmlName(), 'to') . '/>' . '</div></div>'; $html .= '<input type="hidden" name="' . $this->_getHtmlName() . '[locale]"' . ' value="' . $this->_localeResolver->getLocaleCode() . '"/>'; $html .= '<script type="text/javascript"> require(["jquery", "mage/calendar"], function($){ $("#' . $htmlId . '_range").dateRange({ dateFormat: "' . $format . '", buttonImage: "' . $this->getViewFileUrl('images/grid-cal.gif') . '", buttonText: "' . $this->escapeHtml(__('Date selector')) . '", from: { id: "' . $htmlId . '_from" }, to: { id: "' . $htmlId . '_to" } }) }); </script>'; return $html; }
/** * @param string|null $url * @return $this */ public function setPageHelpUrl($url = null) { if (is_null($url)) { $request = $this->_request; $frontModule = $request->getControllerModule(); if (!$frontModule) { $frontModule = $this->_routeConfig->getModulesByFrontName($request->getModuleName()); if (empty($frontModule) === false) { $frontModule = $frontModule[0]; } else { $frontModule = null; } } $url = 'http://www.magentocommerce.com/gethelp/'; $url .= $this->_locale->getLocaleCode() . '/'; $url .= $frontModule . '/'; $url .= $request->getControllerName() . '/'; $url .= $request->getActionName() . '/'; $this->_pageHelpUrl = $url; } $this->_pageHelpUrl = $url; return $this; }
/** * Get locale * * @return string */ public function getLocale() { return $this->_locale->getLocaleCode(); }
/** * Checkout with PayPal image URL getter * Spares API calls of getting "pal" variable, by putting it into cache per store view * * @return string */ public function getCheckoutShortcutImageUrl() { // get "pal" thing from cache or lookup it via API $pal = null; if ($this->_config->areButtonsDynamic()) { $cacheId = self::PAL_CACHE_ID . $this->_storeManager->getStore()->getId(); $pal = $this->_configCacheType->load($cacheId); if (self::PAL_CACHE_ID == $pal) { $pal = null; } elseif (!$pal) { $pal = null; $this->_getApi(); try { $this->_api->callGetPalDetails(); $pal = $this->_api->getPal(); $this->_configCacheType->save($pal, $cacheId); } catch (\Exception $e) { $this->_configCacheType->save(self::PAL_CACHE_ID, $cacheId); $this->_logger->logException($e); } } } return $this->_config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocaleCode(), $this->_quote->getBaseGrandTotal(), $pal); }
/** * Current locale code getter * * @return string */ public function getLocaleCode() { return $this->_localeResolver->getLocaleCode(); }
/** * Collect needed information from buy request * Then filter data * * @param \Magento\Framework\Object $buyRequest * @return $this * @throws \Magento\Framework\Model\Exception * @throws \Exception */ public function importBuyRequest(\Magento\Framework\Object $buyRequest) { $startDate = $buyRequest->getData(self::BUY_REQUEST_START_DATETIME); if ($startDate) { if (!$this->_localeDate || !$this->_store) { throw new \Exception('Locale and store instances must be set for this operation.'); } $dateFormat = $this->_localeDate->getDateTimeFormat(TimezoneInterface::FORMAT_TYPE_SHORT); $localeCode = $this->_localeResolver->getLocaleCode(); if (!\Zend_Date::isDate($startDate, $dateFormat, $localeCode)) { throw new \Magento\Framework\Model\Exception(__('The recurring payment start date has invalid format.')); } $utcTime = $this->_localeDate->utcDate($this->_store, $startDate, true, $dateFormat)->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); $this->setStartDatetime($utcTime)->setImportedStartDatetime($startDate); } return $this->_filterValues(); }
/** * Retrieve locale * * @return string */ public function getLocale() { if (null === $this->_localeCode) { $this->_localeCode = $this->_locale->getLocaleCode(); } return $this->_localeCode; }
/** * Check set locale * * @param string $localeCodeToCheck * @return void */ protected function _checkSetLocale($localeCodeToCheck) { $this->_model->setLocale(); $localeCode = $this->_model->getLocaleCode(); $this->assertEquals($localeCode, $localeCodeToCheck); }
/** * @return \Magento\Framework\View\Element\AbstractBlock */ protected function _beforeToHtml() { $result = parent::_beforeToHtml(); /** @var \Magento\Paypal\Model\Config $config */ $config = $this->_paypalConfigFactory->create(); $config->setMethod($this->_paymentMethodCode); $isInCatalog = $this->getIsInCatalogProduct(); if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) { $this->_shouldRender = false; return $result; } $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote(); // set misc data $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction)); // use static image if in catalog if ($isInCatalog || null === $quote) { $this->setImageUrl($config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocaleCode())); } else { /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */ $parameters = array('params' => array('quote' => $quote, 'config' => $config)); $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters); $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl()); } // ask whether to create a billing agreement $customerId = $this->currentCustomer->getCustomerId(); // potential issue for caching if ($this->_paypalData->shouldAskToCreateBillingAgreement($config, $customerId)) { $this->setConfirmationUrl($this->getUrl($this->_startAction, array(\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1))); $this->setConfirmationMessage(__('Would you like to sign a billing agreement ' . 'to streamline further purchases with PayPal?')); } return $result; }
/** * Prepare params array to send it to gateway page via POST * * @param \Magento\Sales\Model\Order $order * @return array */ public function getFormFields($order) { if (empty($order)) { if (!($order = $this->getOrder())) { return array(); } } /** @var \Magento\Sales\Model\Quote\Address $billingAddress */ $billingAddress = $order->getBillingAddress(); $formFields = array(); $formFields['PSPID'] = $this->getConfig()->getPSPID(); $formFields['orderID'] = $order->getIncrementId(); $formFields['amount'] = round($order->getBaseGrandTotal() * 100); $formFields['currency'] = $this->_storeManager->getStore()->getBaseCurrencyCode(); $formFields['language'] = $this->_localeResolver->getLocaleCode(); $formFields['CN'] = $this->_translate($billingAddress->getFirstname() . ' ' . $billingAddress->getLastname()); $formFields['EMAIL'] = $order->getCustomerEmail(); $formFields['ownerZIP'] = $billingAddress->getPostcode(); $formFields['ownercty'] = $billingAddress->getCountry(); $formFields['ownertown'] = $this->_translate($billingAddress->getCity()); $formFields['COM'] = $this->_translate($this->_getOrderDescription($order)); $formFields['ownertelno'] = $billingAddress->getTelephone(); $formFields['owneraddress'] = $this->_translate(implode(' ', $billingAddress->getStreet())); $paymentAction = $this->_getOgonePaymentOperation(); if ($paymentAction) { $formFields['operation'] = $paymentAction; } $formFields['homeurl'] = $this->getConfig()->getHomeUrl(); $formFields['catalogurl'] = $this->getConfig()->getHomeUrl(); $formFields['accepturl'] = $this->getConfig()->getAcceptUrl(); $formFields['declineurl'] = $this->getConfig()->getDeclineUrl(); $formFields['exceptionurl'] = $this->getConfig()->getExceptionUrl(); $formFields['cancelurl'] = $this->getConfig()->getCancelUrl(); if ($this->getConfig()->getConfigData('template') == 'ogone') { $formFields['TP'] = ''; $formFields['PMListType'] = $this->getConfig()->getConfigData('pmlist'); } else { $formFields['TP'] = $this->getConfig()->getPayPageTemplate(); } $formFields['TITLE'] = $this->_translate($this->getConfig()->getConfigData('html_title')); $formFields['BGCOLOR'] = $this->getConfig()->getConfigData('bgcolor'); $formFields['TXTCOLOR'] = $this->getConfig()->getConfigData('txtcolor'); $formFields['TBLBGCOLOR'] = $this->getConfig()->getConfigData('tblbgcolor'); $formFields['TBLTXTCOLOR'] = $this->getConfig()->getConfigData('tbltxtcolor'); $formFields['BUTTONBGCOLOR'] = $this->getConfig()->getConfigData('buttonbgcolor'); $formFields['BUTTONTXTCOLOR'] = $this->getConfig()->getConfigData('buttontxtcolor'); $formFields['FONTTYPE'] = $this->getConfig()->getConfigData('fonttype'); $formFields['LOGO'] = $this->getConfig()->getConfigData('logo'); $formFields['SHASign'] = $this->getHash($formFields, $this->getConfig()->getShaOutCode(), self::HASH_DIR_OUT, (int) $this->getConfig()->getConfigData('shamode'), $this->getConfig()->getConfigData('hashing_algorithm')); return $formFields; }
/** * Retrieve locale code * * @return string */ public function getLocale() { return substr($this->_localeResolver->getLocaleCode(), 0, 2); }