public function testToHtml() { $fieldSet = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false); $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false); $attributeModel = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false); $entityType = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', [], [], '', false); $formElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Text', ['setDisabled'], [], '', false); $directoryReadInterface = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->registry->expects($this->any())->method('registry')->with('entity_attribute')->willReturn($attributeModel); $this->formFactory->expects($this->any())->method('create')->willReturn($form); $form->expects($this->any())->method('addFieldset')->willReturn($fieldSet); $form->expects($this->any())->method('getElement')->willReturn($formElement); $fieldSet->expects($this->any())->method('addField')->willReturnSelf(); $attributeModel->expects($this->any())->method('getDefaultValue')->willReturn('default_value'); $attributeModel->expects($this->any())->method('setDisabled')->willReturnSelf(); $attributeModel->expects($this->any())->method('getId')->willReturn(1); $attributeModel->expects($this->any())->method('getEntityType')->willReturn($entityType); $attributeModel->expects($this->any())->method('getIsUserDefined')->willReturn(false); $attributeModel->expects($this->any())->method('getAttributeCode')->willReturn('attribute_code'); $this->localeDate->expects($this->any())->method('getDateFormat')->willReturn('mm/dd/yy'); $entityType->expects($this->any())->method('getEntityTypeCode')->willReturn('entity_type_code'); $this->eavData->expects($this->any())->method('getFrontendClasses')->willReturn([]); $formElement->expects($this->exactly(3))->method('setDisabled')->willReturnSelf(); $this->yesNo->expects($this->any())->method('toOptionArray')->willReturn(['yes', 'no']); $this->filesystem->expects($this->any())->method('getDirectoryRead')->willReturn($directoryReadInterface); $directoryReadInterface->expects($this->any())->method('getRelativePath')->willReturn('relative_path'); $this->block->setData(['action' => 'save']); $this->block->toHtml(); }
/** * Apply catalog price rules to product in admin * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $product = $observer->getEvent()->getProduct(); $storeId = $product->getStoreId(); $date = $this->localeDate->scopeDate($storeId); $key = false; $ruleData = $this->coreRegistry->registry('rule_data'); if ($ruleData) { $wId = $ruleData->getWebsiteId(); $gId = $ruleData->getCustomerGroupId(); $pId = $product->getId(); $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}"; } elseif ($product->getWebsiteId() !== null && $product->getCustomerGroupId() !== null) { $wId = $product->getWebsiteId(); $gId = $product->getCustomerGroupId(); $pId = $product->getId(); $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}"; } if ($key) { if (!$this->rulePricesStorage->hasRulePrice($key)) { $rulePrice = $this->resourceRuleFactory->create()->getRulePrice($date, $wId, $gId, $pId); $this->rulePricesStorage->setRulePrice($key, $rulePrice); } if ($this->rulePricesStorage->getRulePrice($key) !== false) { $finalPrice = min($product->getData('final_price'), $this->rulePricesStorage->getRulePrice($key)); $product->setFinalPrice($finalPrice); } } return $this; }
public function processCalendarDetails($carrierRate, $carrierGroupDetail) { $calendarDetails = parent::processCalendarDetails($carrierRate, $carrierGroupDetail); //transform for current locale $calendarDetails['start'] = $this->localeDate->date($calendarDetails['start'], null, true)->getTimestamp(); return $calendarDetails; }
/** * Apply catalog price rules to product on frontend * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $product = $observer->getEvent()->getProduct(); $pId = $product->getId(); $storeId = $product->getStoreId(); if ($observer->hasDate()) { $date = new \DateTime($observer->getEvent()->getDate()); } else { $date = $this->localeDate->scopeDate($storeId); } if ($observer->hasWebsiteId()) { $wId = $observer->getEvent()->getWebsiteId(); } else { $wId = $this->storeManager->getStore($storeId)->getWebsiteId(); } if ($observer->hasCustomerGroupId()) { $gId = $observer->getEvent()->getCustomerGroupId(); } elseif ($product->hasCustomerGroupId()) { $gId = $product->getCustomerGroupId(); } else { $gId = $this->customerSession->getCustomerGroupId(); } $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}"; if (!$this->rulePricesStorage->hasRulePrice($key)) { $rulePrice = $this->resourceRuleFactory->create()->getRulePrice($date, $wId, $gId, $pId); $this->rulePricesStorage->setRulePrice($key, $rulePrice); } if ($this->rulePricesStorage->getRulePrice($key) !== false) { $finalPrice = min($product->getData('final_price'), $this->rulePricesStorage->getRulePrice($key)); $product->setFinalPrice($finalPrice); } return $this; }
public function execute() { $startDate = $this->getHelper('M2ePro')->getCurrentGmtDate(); $synchConfig = $this->modelFactory->getObject('Config\\Manager\\Synchronization'); $synchConfig->setGroupValue('/ebay/templates/revise/total/', 'start_date', $startDate); $synchConfig->setGroupValue('/ebay/templates/revise/total/', 'last_listing_product_id', 0); $this->setAjaxContent(json_encode(array('start_date' => $this->localeDate->formatDate($startDate, \IntlDateFormatter::MEDIUM))), false); }
/** * 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(); }
/** * {@inheritdoc} */ public function build($productId) { $timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore()); $currentDate = $this->dateTime->formatDate($timestamp, false); $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); $productTable = $this->resource->getTableName('catalog_product_entity'); return [$this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $this->resource->getTableName('catalogrule_product_price')], 't.product_id = child.entity_id', [])->where('parent.entity_id = ? ', $productId)->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())->where('t.rule_date = ?', $currentDate)->order('t.rule_price ' . Select::SQL_ASC)->limit(1)]; }
/** * {@inheritDoc} */ protected function setUp() { $this->entityFactoryMock = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\EntityFactory')->disableOriginalConstructor()->getMock(); $this->timezoneMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getMock(); $this->factoryMock = $this->getMockBuilder('Magento\\Reports\\Model\\ResourceModel\\Report\\Collection\\Factory')->disableOriginalConstructor()->getMock(); $this->timezoneMock->expects($this->any())->method('formatDateTime')->will($this->returnCallback([$this, 'formatDateTime'])); $this->collection = new Collection($this->entityFactoryMock, $this->timezoneMock, $this->factoryMock); }
/** * 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(); }
/** * 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; }
/** * @test */ public function testGetYearRange() { $testCurrentYear = 2123; $date = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\DateInterface')->getMock(); $date->expects($this->any())->method('__toString')->will($this->returnValue($testCurrentYear)); $this->localeDate->expects($this->any())->method('date')->with($this->equalTo('Y'))->will($this->returnValue($date)); $this->assertEquals((int) $testCurrentYear - 100 . ':' . $testCurrentYear, $this->block->getYearRange()); }
/** * Returns catalog rule value * * @return float|boolean */ public function getValue() { if (null === $this->value) { $this->value = $this->resourceRuleFactory->create()->getRulePrice($this->dateTime->scopeTimeStamp($this->storeManager->getStore()->getId()), $this->storeManager->getStore()->getWebsiteId(), $this->customerSession->getCustomerGroupId(), $this->product->getId()); $this->value = $this->value ? floatval($this->value) : false; } return $this->value; }
/** * 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; }
/** * 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; }
/** * @param Collection $productCollection * @param bool $printQuery * @param bool $logQuery * @return array */ public function beforeLoad(Collection $productCollection, $printQuery = false, $logQuery = false) { if (!$productCollection->hasFlag('catalog_rule_loaded')) { $connection = $this->resource->getConnection(); $store = $this->storeManager->getStore(); $productCollection->getSelect()->joinLeft(['catalog_rule' => $this->resource->getTableName('catalogrule_product_price')], implode(' AND ', ['catalog_rule.product_id = e.entity_id', $connection->quoteInto('catalog_rule.website_id = ?', $store->getWebsiteId()), $connection->quoteInto('catalog_rule.customer_group_id = ?', $this->customerSession->getCustomerGroupId()), $connection->quoteInto('catalog_rule.rule_date = ?', $this->dateTime->formatDate($this->localeDate->scopeDate($store->getId()), false))]), [CatalogRulePrice::PRICE_CODE => 'rule_price']); $productCollection->setFlag('catalog_rule_loaded', true); } return [$printQuery, $logQuery]; }
/** * @param TimezoneInterface $localeDate * * @deprecated */ public function __construct(TimezoneInterface $localeDate) { $this->_localeDate = $localeDate; $this->_localToNormalFilter = new \Zend_Filter_LocalizedToNormalized( ['date_format' => $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT)] ); $this->_normalToLocalFilter = new \Zend_Filter_NormalizedToLocalized( ['date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT] ); }
/** * 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; }
/** * 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; }
/** * @dataProvider getValueDataProvider */ public function testGetValue(array $data, $expect) { if (isset($data['date_format'])) { $data['date_format'] = $this->_localeDate->getDateFormat($data['date_format']); } if (isset($data['time_format'])) { $data['time_format'] = $this->_localeDate->getTimeFormat($data['time_format']); } /** @var $date \Magento\Framework\Data\Form\Element\Date*/ $date = $this->_elementFactory->create('Magento\\Framework\\Data\\Form\\Element\\Date', $data); $this->assertEquals($expect, $date->getValue()); }
/** * {@inheritDoc} */ protected function setUp() { $this->localeDate = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->disableOriginalConstructor()->getMock(); $this->localeDate->expects($this->once())->method('date')->willReturnArgument(0); $this->contextMock = $this->getMockBuilder('Magento\\Backend\\Block\\Context')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->once())->method('getLocaleDate')->willReturn($this->localeDate); $this->resolverMock = $this->getMockBuilder('Magento\\Framework\\Locale\\ResolverInterface')->getMock(); $this->dateTimeFormatter = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateTimeFormatterInterface'); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->date = $objectManager->getObject('Magento\\Reports\\Block\\Adminhtml\\Sales\\Grid\\Column\\Renderer\\Date', ['context' => $this->contextMock, 'localeResolver' => $this->resolverMock, 'dateTimeFormatter' => $this->dateTimeFormatter]); $this->globalStateLocaleBackup = \Locale::getDefault(); }
/** * Delete completed records older then 30 days from provided table. * * @param $tableName * * @return \Exception|int */ public function cleanup($tableName) { try { $interval = new \DateInterval('P30D'); $date = $this->localeDate->date()->sub($interval)->format('Y-m-d H:i:s'); $conn = $this->getConnection(); $num = $conn->delete($tableName, ['created_at < ?' => $date]); return $num; } catch (\Exception $e) { return $e->getMessage(); } }
/** * @param int $storeId * @return \Magento\Catalog\Model\ResourceModel\Product\Collection */ public function getProductsCollection($storeId) { /** @var $product \Magento\Catalog\Model\Product */ $product = $this->productFactory->create(); $todayStartOfDayDate = $this->localeDate->date()->setTime(0, 0)->format('Y-m-d H:i:s'); $todayEndOfDayDate = $this->localeDate->date()->setTime(23, 59, 59)->format('Y-m-d H:i:s'); /** @var $products \Magento\Catalog\Model\ResourceModel\Product\Collection */ $products = $product->getResourceCollection(); $products->setStoreId($storeId); $products->addStoreFilter()->addAttributeToFilter('news_from_date', ['or' => [0 => ['date' => true, 'to' => $todayEndOfDayDate], 1 => ['is' => new \Zend_Db_Expr('null')]]], 'left')->addAttributeToFilter('news_to_date', ['or' => [0 => ['date' => true, 'from' => $todayStartOfDayDate], 1 => ['is' => new \Zend_Db_Expr('null')]]], 'left')->addAttributeToFilter([['attribute' => 'news_from_date', 'is' => new \Zend_Db_Expr('not null')], ['attribute' => 'news_to_date', 'is' => new \Zend_Db_Expr('not null')]])->addAttributeToSort('news_from_date', 'desc')->addAttributeToSelect(['name', 'short_description', 'description'], 'inner')->addAttributeToSelect(['price', 'special_price', 'special_from_date', 'special_to_date', 'msrp_display_actual_price_type', 'msrp', 'thumbnail'], 'left')->applyFrontendPriceLimitations(); $products->setVisibility($this->visibility->getVisibleInCatalogIds()); return $products; }
/** * @param array $dataSource * @return array */ public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { if (isset($item[$this->getData('name')])) { $date = $this->timezone->date(new \DateTime($item[$this->getData('name')])); $item[$this->getData('name')] = $date->format('Y-m-d H:i:s'); } } } return $dataSource; }
/** * @param string $data * @param string $index * @param string $locale * @param string $period * @param string $result * @dataProvider datesDataProvider * @return void */ public function testRender($data, $index, $locale, $period, $result) { $this->resolverMock->expects($this->any())->method('getLocale')->will($this->returnValue($locale)); $this->localeDate->expects($this->any())->method('getDateFormat')->willReturnCallback(function ($value) use($locale) { return (new \IntlDateFormatter($locale, $value, \IntlDateFormatter::NONE))->getPattern(); }); $objectMock = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['getData'])->getMock(); $objectMock->expects($this->once())->method('getData')->will($this->returnValue($data)); $columnMock = $this->getMockBuilder('Magento\\Backend\\Block\\Widget\\Grid\\Column')->disableOriginalConstructor()->setMethods(['getIndex', 'getPeriodType'])->getMock(); $columnMock->expects($this->once())->method('getIndex')->will($this->returnValue($index)); $columnMock->expects($this->atLeastOnce())->method('getPeriodType')->will($this->returnValue($period)); $this->date->setColumn($columnMock); $this->assertEquals($result, $this->date->render($objectMock)); }
/** * Retrieve attribute value * * @param \Magento\Framework\Object $object * @return mixed */ public function getValue(\Magento\Framework\Object $object) { $data = ''; $value = parent::getValue($object); $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM); if ($value) { try { $data = $this->_localeDate->date($value, \Zend_Date::ISO_8601, null, false)->toString($format); } catch (\Exception $e) { $data = $this->_localeDate->date($value, null, null, false)->toString($format); } } return $data; }
/** * Returns catalog rule value * * @return float|boolean */ public function getValue() { if (null === $this->value) { if ($this->product->hasData(self::PRICE_CODE)) { $this->value = floatval($this->product->getData(self::PRICE_CODE)) ?: false; } else { $this->value = $this->getRuleResource()->getRulePrice($this->dateTime->scopeDate($this->storeManager->getStore()->getId()), $this->storeManager->getStore()->getWebsiteId(), $this->customerSession->getCustomerGroupId(), $this->product->getId()); $this->value = $this->value ? floatval($this->value) : false; if ($this->value) { $this->value = $this->priceCurrency->convertAndRound($this->value); } } } return $this->value; }
/** * @param $dataTime * * @return string */ protected function _getEstimatedDate($dataTime) { $current = new \Zend_Date(); $current->setTime(0); $nextNotificationDate = $current->add($dataTime['shipping'], \Zend_Date::HOUR); return $this->_timezone->formatDate('@' . $nextNotificationDate->getTimestamp()); }
/** * @param string $result * @param string|null $lastLoginAt * @dataProvider getStoreLastLoginDateDataProvider * @return void */ public function testGetStoreLastLoginDate($result, $lastLoginAt) { $this->customerLog->expects($this->once())->method('getLastLoginAt')->willReturn($lastLoginAt); $this->localeDate->expects($this->any())->method('scopeDate')->will($this->returnValue($lastLoginAt)); $this->localeDate->expects($this->any())->method('formatDateTime')->willReturn($lastLoginAt); $this->assertEquals($result, $this->block->getStoreLastLoginDate()); }
/** * Get RSS feed items * * @return array */ protected function getEntries() { /** @var $resourceModel \Magento\Sales\Model\Resource\Order\Rss\OrderStatus */ $resourceModel = $this->orderResourceFactory->create(); $results = $resourceModel->getAllCommentCollection($this->order->getId()); $entries = []; if ($results) { foreach ($results as $result) { $urlAppend = 'view'; $type = $result['entity_type_code']; if ($type && $type != 'order') { $urlAppend = $type; } $type = __(ucwords($type)); $title = __('Details for %1 #%2', $type, $result['increment_id']); $description = '<p>' . __('Notified Date: %1', $this->localeDate->formatDate($result['created_at'])) . '<br/>' . __('Comment: %1<br/>', $result['comment']) . '</p>'; $url = $this->urlBuilder->getUrl('sales/order/' . $urlAppend, ['order_id' => $this->order->getId()]); $entries[] = ['title' => $title, 'link' => $url, 'description' => $description]; } } $title = __('Order #%1 created at %2', $this->order->getIncrementId(), $this->localeDate->formatDate($this->order->getCreatedAt())); $url = $this->urlBuilder->getUrl('sales/order/view', ['order_id' => $this->order->getId()]); $description = '<p>' . __('Current Status: %1<br/>', $this->order->getStatusLabel()) . __('Total: %1<br/>', $this->order->formatPrice($this->order->getGrandTotal())) . '</p>'; $entries[] = ['title' => $title, 'link' => $url, 'description' => $description]; return ['entries' => $entries]; }
/** * Prepare website current dates table * * @return \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction */ protected function _prepareWebsiteDateTable() { $baseCurrency = $this->_config->getValue(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE); $select = $this->_connection->select()->from(['cw' => $this->_defaultIndexerResource->getTable('store_website')], ['website_id'])->join(['csg' => $this->_defaultIndexerResource->getTable('store_group')], 'cw.default_group_id = csg.group_id', ['store_id' => 'default_store_id'])->where('cw.website_id != 0'); $data = []; foreach ($this->_connection->fetchAll($select) as $item) { /** @var $website \Magento\Store\Model\Website */ $website = $this->_storeManager->getWebsite($item['website_id']); if ($website->getBaseCurrencyCode() != $baseCurrency) { $rate = $this->_currencyFactory->create()->load($baseCurrency)->getRate($website->getBaseCurrencyCode()); if (!$rate) { $rate = 1; } } else { $rate = 1; } /** @var $store \Magento\Store\Model\Store */ $store = $this->_storeManager->getStore($item['store_id']); if ($store) { $timestamp = $this->_localeDate->scopeTimeStamp($store); $data[] = ['website_id' => $website->getId(), 'website_date' => $this->_dateTime->formatDate($timestamp, false), 'rate' => $rate]; } } $table = $this->_defaultIndexerResource->getTable('catalog_product_index_website'); $this->_emptyTable($table); if ($data) { foreach ($data as $row) { $this->_connection->insertOnDuplicate($table, $row, array_keys($row)); } } return $this; }