/** * Get current language * * @return string */ public function getLang() { if (!$this->hasData('lang')) { $this->setData('lang', substr($this->_localeResolver->getLocale(), 0, 2)); } return $this->getData('lang'); }
/** * @param \Magento\Customer\Model\ResourceModel\Customer\Collection $subject * @param \Closure $proceed * @return \Magento\Customer\Model\ResourceModel\Customer\Collection */ public function aroundAddNameToSelect(Collection $subject, \Closure $proceed) { $fields = []; $customerAccount = $this->fieldsetConfig->getFieldset('customer_account'); foreach ($customerAccount as $code => $field) { if (isset($field['name'])) { $fields[$code] = $code; } } $connection = $subject->getConnection(); $concatenate = []; if (isset($fields['prefix'])) { $concatenate[] = $connection->getCheckSql('{{prefix}} IS NOT NULL AND {{prefix}} != \'\'', $connection->getConcatSql(['LTRIM(RTRIM({{prefix}}))', '\' \'']), '\'\''); } if ($this->localeResolver->getLocale() != 'ja_JP') { $concatenate[] = 'LTRIM(RTRIM({{firstname}}))'; } else { $concatenate[] = 'LTRIM(RTRIM({{lastname}}))'; } $concatenate[] = '\' \''; if (isset($fields['middlename'])) { $concatenate[] = $connection->getCheckSql('{{middlename}} IS NOT NULL AND {{middlename}} != \'\'', $connection->getConcatSql(['LTRIM(RTRIM({{middlename}}))', '\' \'']), '\'\''); } if ($this->localeResolver->getLocale() != 'ja_JP') { $concatenate[] = 'LTRIM(RTRIM({{lastname}}))'; } else { $concatenate[] = 'LTRIM(RTRIM({{firstname}}))'; } if (isset($fields['suffix'])) { $concatenate[] = $connection->getCheckSql('{{suffix}} IS NOT NULL AND {{suffix}} != \'\'', $connection->getConcatSql(['\' \'', 'LTRIM(RTRIM({{suffix}}))']), '\'\''); } $nameExpr = $connection->getConcatSql($concatenate); $subject->addExpressionAttributeToSelect('name', $nameExpr, $fields); return $subject; }
/** * @param \Magento\Framework\View\Element\Template\Context $context * @param \Magento\Directory\Model\CurrencyFactory $currencyFactory * @param \Magento\Core\Helper\PostData $postDataHelper * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param array $data */ public function __construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Core\Helper\PostData $postDataHelper, \Magento\Framework\Locale\ResolverInterface $localeResolver, array $data = array()) { $this->_currencyFactory = $currencyFactory; $this->_postDataHelper = $postDataHelper; parent::__construct($context, $data); $this->_locale = $localeResolver->getLocale(); }
/** * Functions returns array with price formatting info * * @return array * @SuppressWarnings(PHPMD.NPathComplexity) */ public function getPriceFormat() { $localeData = (new DataBundle())->get($this->_localeResolver->getLocale()); $format = $localeData['NumberElements']['latn']['patterns']['currencyFormat'] ?: explode(';', $localeData['NumberPatterns'][1])[0]; $decimalSymbol = $localeData['NumberElements']['latn']['symbols']['decimal'] ?: $localeData['NumberElements'][0]; $groupSymbol = $localeData['NumberElements']['latn']['symbols']['group'] ?: $localeData['NumberElements'][1]; $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 = ['pattern' => $this->_scopeResolver->getScope()->getCurrentCurrency()->getOutputFormat(), 'precision' => $totalPrecision, 'requiredPrecision' => $requiredPrecision, 'decimalSymbol' => $decimalSymbol, 'groupSymbol' => $groupSymbol, 'groupLength' => $group, 'integerRequired' => $integerRequired]; return $result; }
/** * Clears cache and updates translations file * * @return array */ public function updateAndGetTranslations() { $this->eventManager->dispatch('adminhtml_cache_flush_system'); $translations = $this->translateResource->getTranslationArray(null, $this->localeResolver->getLocale()); $this->fileManager->updateTranslationFileContent(json_encode($translations)); return $translations; }
/** * Render block HTML * * @return string */ protected function _toHtml() { $localeData = (new DataBundle())->get($this->_localeResolver->getLocale()); // get days names $daysData = $localeData['calendar']['gregorian']['dayNames']; $this->assign('days', ['wide' => $this->encoder->encode(array_values(iterator_to_array($daysData['format']['wide']))), 'abbreviated' => $this->encoder->encode(array_values(iterator_to_array($daysData['format']['abbreviated'])))]); // get months names $monthsData = $localeData['calendar']['gregorian']['monthNames']; $this->assign('months', ['wide' => $this->encoder->encode(array_values(iterator_to_array($monthsData['format']['wide']))), 'abbreviated' => $this->encoder->encode(array_values(iterator_to_array($monthsData['format']['abbreviated'])))]); // get "today" and "week" words $this->assign('today', $this->encoder->encode($localeData['fields']['day']['relative']['0'])); $this->assign('week', $this->encoder->encode($localeData['fields']['week']['dn'])); // get "am" & "pm" words $this->assign('am', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['0'])); $this->assign('pm', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['1'])); // 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(\IntlDateFormatter::MEDIUM))); $this->assign('toolTipFormat', $this->encoder->encode($this->_localeDate->getDateFormat(\IntlDateFormatter::LONG))); // get days and months for en_US locale - calendar will parse exactly in this locale $englishMonths = (new DataBundle())->get('en_US')['calendar']['gregorian']['monthNames']; $enUS = new \stdClass(); $enUS->m = new \stdClass(); $enUS->m->wide = array_values(iterator_to_array($englishMonths['format']['wide'])); $enUS->m->abbr = array_values(iterator_to_array($englishMonths['format']['abbreviated'])); $this->assign('enUS', $this->encoder->encode($enUS)); return parent::_toHtml(); }
/** * 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(); }
public function testGetLocale() { $expected = 'locale'; $this->locale->expects($this->once())->method('getLocaleCode')->will($this->returnValue($expected)); $actual = $this->model->getLocale(); $this->assertSame($expected, $actual); }
/** * return current locale code */ public function getCurrentLocale() { if ($this->_localeResolver->getLocale() == 'ja_JP') { return 'ja'; } return 'en'; }
/** * @param string $locale */ private function mockGridDateRendererBehaviorWithLocale($locale) { $this->resolverMock->expects($this->any())->method('getLocale')->willReturn($locale); $this->localeDate->expects($this->any())->method('getDateFormat')->willReturnCallback(function ($value) use($locale) { return (new \IntlDateFormatter($locale, $value, \IntlDateFormatter::NONE))->getPattern(); }); }
/** * Set up aggregate * * @return \DateTime */ protected function setupAggregate() { $this->localeResolverMock->expects($this->once())->method('emulate')->with(0); $this->localeResolverMock->expects($this->once())->method('revert'); $date = (new \DateTime())->sub(new \DateInterval('PT25H')); $this->localeDateMock->expects($this->once())->method('date')->will($this->returnValue($date)); return $date; }
/** * Initialize select object * * @return $this */ protected function _initSelect() { parent::_initSelect(); $locale = $this->_localeResolver->getLocale(); $this->addBindParam(':region_locale', $locale); $this->getSelect()->joinLeft(['rname' => $this->_regionNameTable], 'main_table.region_id = rname.region_id AND rname.locale = :region_locale', ['name']); return $this; }
/** * @dataProvider getConfigDataProvider */ public function testGetConfig($configData, $locale, $expectedResult) { foreach ($configData as $key => $value) { $this->configMock->expects($this->any())->method($key)->willReturn($value); } $this->localResolverMock->expects($this->any())->method('getLocale')->willReturn($locale); $this->assertEquals($expectedResult, $this->model->getConfig()); }
/** * Returns the result of filtering $value * * @param string $value * @return string */ public function outputFilter($value) { $filterInput = new \Zend_Filter_LocalizedToNormalized(['date_format' => DateTime::DATE_INTERNAL_FORMAT, 'locale' => $this->localeResolver->getLocale()]); $filterInternal = new \Zend_Filter_NormalizedToLocalized(['date_format' => $this->_dateFormat, 'locale' => $this->localeResolver->getLocale()]); $value = $filterInput->filter($value); $value = $filterInternal->filter($value); return $value; }
/** * Refresh sales order report statistics for last day * * @return void */ public function execute() { $this->localeResolver->emulate(0); $currentDate = $this->localeDate->date(); $date = $currentDate->sub(new \DateInterval('PT25H')); $this->orderFactory->create()->aggregate($date); $this->localeResolver->revert(); }
/** * Refresh sales refunded report statistics for last day * * @return void */ public function execute() { $this->localeResolver->emulate(0); $currentDate = $this->localeDate->date(); $date = $currentDate->subHour(25); $this->refundedFactory->create()->aggregate($date); $this->localeResolver->revert(); }
/** * @param Filter $filter * @param TimezoneInterface $localeDate * @param ResolverInterface $localeResolver * @param string $dateFormat * @param array $data */ public function __construct(Filter $filter, TimezoneInterface $localeDate, ResolverInterface $localeResolver, $dateFormat = 'M j, Y H:i:s A', array $data = []) { $this->filter = $filter; $this->localeDate = $localeDate; $this->locale = $localeResolver->getLocale(); $this->dateFormat = $dateFormat; $this->data = $data; }
/** * Refresh sales coupons report statistics for last day * * @return $this */ public function execute() { $this->_localeResolver->emulate(0); $currentDate = $this->_localeDate->date(); $date = $currentDate->modify('-25 hours'); $this->_reportRule->aggregate($date); $this->_localeResolver->revert(); return $this; }
/** * {@inheritdoc} */ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $days = (new DataBundle())->get($this->localeResolver->getLocale())['calendar']['gregorian']['dayNames']['format']['abbreviated']; $select = $setup->getConnection()->select()->from($setup->getTable('core_config_data'), ['config_id', 'value'])->where('path = ?', 'carriers/dhl/shipment_days'); foreach ($setup->getConnection()->fetchAll($select) as $configRow) { $row = ['value' => implode(',', array_intersect_key(iterator_to_array($days), array_flip(explode(',', $configRow['value']))))]; $setup->getConnection()->update($setup->getTable('core_config_data'), $row, ['config_id = ?' => $configRow['config_id']]); } }
/** * Refresh sales shipment report statistics for last day * * @return $this */ public function aggregateSalesReportShipmentData() { $this->_localeResolver->emulate(0); $currentDate = new \DateTime(); $date = $currentDate->modify('-25 hours'); $this->_shippingFactory->create()->aggregate($date); $this->_localeResolver->revert(); return $this; }
public function testUpdateQuoteItemWithZeroQty() { $itemId = 1; $itemQty = 0; $this->resolverMock->expects($this->never())->method('getLocale'); $this->cartMock->expects($this->once())->method('updateItems')->with([$itemId => ['qty' => $itemQty]])->willReturnSelf(); $this->cartMock->expects($this->once())->method('save')->willReturnSelf(); $this->assertEquals($this->sidebar, $this->sidebar->updateQuoteItem($itemId, $itemQty)); }
/** * Refresh sales shipment report statistics for last day * * @return $this */ public function aggregateSalesReportShipmentData() { $this->_localeResolver->emulate(0); $currentDate = $this->_coreLocale->date(); $date = $currentDate->subHour(25); $this->_shippingFactory->create()->aggregate($date); $this->_localeResolver->revert(); return $this; }
/** * @param int $qtyResult * @param int|null $expectedResult * @dataProvider processDataProvider */ public function testProcess($qtyResult, $expectedResult) { $qty = 10; $localCode = 'en_US'; $this->resolver->expects($this->once())->method('getLocale')->willReturn($localCode); $this->filter->expects($this->once())->method('setOptions')->with(['locale' => $localCode])->willReturnSelf(); $this->filter->expects($this->once())->method('filter')->with($qty)->willReturn($qtyResult); $this->assertEquals($expectedResult, $this->processor->process($qty)); }
/** * 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; }
/** * @return array|void */ public function getConfig() { if (!$this->config->isActive()) { return []; } $clientToken = $this->config->getClientToken(); $config = ['payment' => ['braintree_paypal' => ['clientToken' => $clientToken, 'locale' => $this->localeResolver->getLocale(), 'merchantDisplayName' => $this->config->getMerchantNameOverride()]]]; return $config; }
public function testUpdateAndGetTranslations() { $translations = ['phrase1' => 'translated1', 'phrase2' => 'translated2']; $this->eventManagerMock->expects($this->once())->method('dispatch'); $this->translateResourceMock->expects($this->once())->method('getTranslationArray')->willReturn($translations); $this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn('en_US'); $this->fileManagerMock->expects($this->once())->method('updateTranslationFileContent'); $this->assertEquals($translations, $this->model->updateAndGetTranslations()); }
/** * Set up aggregate * * @return \Magento\Framework\Stdlib\DateTime\DateInterface */ protected function setupAggregate() { $date = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\Date', ['emulate', 'revert'], [], '', false); $this->localeResolverMock->expects($this->once())->method('emulate')->with(0); $this->localeResolverMock->expects($this->once())->method('revert'); $dateMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\DateInterface')->disableOriginalConstructor()->getMock(); $dateMock->expects($this->once())->method('subHour')->with(25)->will($this->returnValue($date)); $this->localeDateMock->expects($this->once())->method('date')->will($this->returnValue($dateMock)); return $date; }
/** * Set template and redirect message * * @return null */ protected function _construct() { $this->_config = $this->_paypalConfigFactory->create()->setMethod($this->getMethodCode()); $mark = $this->_getMarkTemplate(); $mark->setPaymentAcceptanceMarkHref($this->_config->getPaymentMarkWhatIsPaypalUrl($this->_localeResolver))->setPaymentAcceptanceMarkSrc($this->_config->getPaymentMarkImageUrl($this->_localeResolver->getLocale())); // known issue: code above will render only static mark image $this->_initializeRedirectTemplateWithMark($mark); parent::_construct(); $this->setRedirectMessage(__('You will be redirected to the PayPal website.')); }
/** * 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(); }
/** * Refresh sales tax report statistics for last day * * @return $this */ public function invoke() { $this->localeResolver->emulate(0); $currentDate = $this->localeDate->date(); $date = $currentDate->modify('-25 hours'); /** @var $reportTax \Magento\Tax\Model\ResourceModel\Report\Tax */ $reportTax = $this->reportTaxFactory->create(); $reportTax->aggregate($date); $this->localeResolver->revert(); return $this; }