/** * Retrieve attribute value * * @param \Magento\Framework\DataObject $object * @return mixed */ public function getValue(\Magento\Framework\DataObject $object) { $data = ''; $value = parent::getValue($object); if ($value) { $data = $this->_localeDate->formatDateTime(new \DateTime($value), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE); } return $data; }
/** * Get date value as string. * Format can be specified, or it will be taken from $this->getFormat() * * @param string $format (compatible with \DateTime) * @return string */ public function getValue($format = null) { if (empty($this->_value)) { return ''; } if (null === $format) { $format = $this->getDateFormat(); $format .= $format && $this->getTimeFormat() ? ' ' : ''; $format .= $this->getTimeFormat() ? $this->getTimeFormat() : ''; } return $this->localeDate->formatDateTime($this->_value, null, null, null, $this->_value->getTimezone(), $format); }
/** * Return formatted option value for quote option * * @param string $optionValue Prepared for cart option value * @return string * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function getFormattedOptionValue($optionValue) { if ($this->_formattedOptionValue === null) { if ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE) { $result = $this->_localeDate->formatDateTime(new \DateTime($optionValue), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE); } elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE_TIME) { $result = $this->_localeDate->formatDateTime(new \DateTime($optionValue), \IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT); } elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_TIME) { $result = $this->_localeDate->formatDateTime(new \DateTime($optionValue), \IntlDateFormatter::NONE, \IntlDateFormatter::SHORT); } else { $result = $optionValue; } $this->_formattedOptionValue = $result; } return $this->_formattedOptionValue; }
/** * Send email id payment was failed * * @param \Magento\Quote\Model\Quote $checkout * @param string $message * @param string $checkoutType * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage') { $this->inlineTranslation->suspend(); $template = $this->scopeConfig->getValue('checkout/payment_failed/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()); $copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId()); $copyMethod = $this->scopeConfig->getValue('checkout/payment_failed/copy_method', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()); $bcc = []; if ($copyTo && $copyMethod == 'bcc') { $bcc = $copyTo; } $_receiver = $this->scopeConfig->getValue('checkout/payment_failed/receiver', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()); $sendTo = [['email' => $this->scopeConfig->getValue('trans_email/ident_' . $_receiver . '/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()), 'name' => $this->scopeConfig->getValue('trans_email/ident_' . $_receiver . '/name', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId())]]; if ($copyTo && $copyMethod == 'copy') { foreach ($copyTo as $email) { $sendTo[] = ['email' => $email, 'name' => null]; } } $shippingMethod = ''; if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) { $data = explode('_', $shippingInfo); $shippingMethod = $data[0]; } $paymentMethod = ''; if ($paymentInfo = $checkout->getPayment()) { $paymentMethod = $paymentInfo->getMethod(); } $items = ''; foreach ($checkout->getAllVisibleItems() as $_item) { /* @var $_item \Magento\Quote\Model\Quote\Item */ $items .= $_item->getProduct()->getName() . ' x ' . $_item->getQty() . ' ' . $checkout->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n"; } $total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal(); foreach ($sendTo as $recipient) { $transport = $this->_transportBuilder->setTemplateIdentifier($template)->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $checkout->getStoreId()])->setTemplateVars(['reason' => $message, 'checkoutType' => $checkoutType, 'dateAndTime' => $this->_localeDate->formatDateTime(new \DateTime(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::MEDIUM), 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(), 'customerEmail' => $checkout->getCustomerEmail(), 'billingAddress' => $checkout->getBillingAddress(), 'shippingAddress' => $checkout->getShippingAddress(), 'shippingMethod' => $this->scopeConfig->getValue('carriers/' . $shippingMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'paymentMethod' => $this->scopeConfig->getValue('payment/' . $paymentMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'items' => nl2br($items), 'total' => $total])->setFrom($this->scopeConfig->getValue('checkout/payment_failed/identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()))->addTo($recipient['email'], $recipient['name'])->addBcc($bcc)->getTransport(); $transport->sendMessage(); } $this->inlineTranslation->resume(); return $this; }
/** * Retrieve Date value for store * * @param int $storeId * @param string $date * @return string|null */ protected function getStoreDate($storeId, $date = null) { if (!isset($this->dates[$storeId])) { $timezone = $this->scopeConfig->getValue($this->localeDate->getDefaultTimezonePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $this->localeResolver->emulate($storeId); $dateObj = new \DateTime(); $dateObj->setTimezone(new \DateTimeZone($timezone)); $this->dates[$storeId] = $dateObj; $this->localeResolver->revert(); } if (!$this->dateTime->isEmptyDate($date)) { /** @var \DateTime $dateObj */ $dateObj = $this->dates[$storeId]; return $this->localeDate->formatDateTime($dateObj, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE); } return null; }
/** * Retrieve formatting time * * @param \DateTime|string|null $time * @param int $format * @param bool $showDate * @return string */ public function formatTime($time = null, $format = \IntlDateFormatter::SHORT, $showDate = false) { $time = $time instanceof \DateTimeInterface ? $time : new \DateTime($time); return $this->_localeDate->formatDateTime($time, $showDate ? $format : \IntlDateFormatter::NONE, $format); }
/** * Get interval for a day * * @param \DateTime $dateStart * @return array */ protected function _getDayInterval(\DateTime $dateStart) { $interval = ['period' => $this->_localeDate->formatDateTime($dateStart, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE), 'start' => $dateStart->format('Y-m-d 00:00:00'), 'end' => $dateStart->format('Y-m-d 23:59:59')]; return $interval; }
/** * Format a UTC timestamp (seconds since epoch) to structure expected by frontend * * @param string $syncDate seconds since epoch * @return array */ private function formatSyncDate($syncDate) { return ['date' => $this->timezone->formatDateTime(new \DateTime('@' . $syncDate), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE), 'time' => $this->timezone->formatDateTime(new \DateTime('@' . $syncDate), \IntlDateFormatter::NONE, \IntlDateFormatter::MEDIUM)]; }
/** * Get formatted order created date in store timezone * * @param string $format date format type (short|medium|long|full) * @return string */ public function getCreatedAtFormatted($format) { return $this->timezone->formatDateTime(new \DateTime($this->getCreatedAt()), $format, $format, null, $this->timezone->getConfigTimezone('store', $this->getStore())); }