Example #1
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($date = $object->getDateFrom()) {
         $object->setDateFrom($this->dateTime->formatDate($date));
     } else {
         $object->setDateFrom(null);
     }
     if ($date = $object->getDateTo()) {
         $object->setDateTo($this->dateTime->formatDate($date));
     } else {
         $object->setDateTo(null);
     }
     if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && $this->dateTime->toTimestamp($object->getDateFrom()) > $this->dateTime->toTimestamp($object->getDateTo())) {
         throw new \Magento\Framework\Model\Exception(__('Start date cannot be greater than end date.'));
     }
     $check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId());
     if ($check) {
         throw new \Magento\Framework\Model\Exception(__('Your design change for the specified store intersects with another one, please specify another date range.'));
     }
     if ($object->getDateFrom() === null) {
         $object->setDateFrom(new \Zend_Db_Expr('null'));
     }
     if ($object->getDateTo() === null) {
         $object->setDateTo(new \Zend_Db_Expr('null'));
     }
     parent::_beforeSave($object);
 }
Example #2
0
 /**
  * Filters the summaries by some period
  *
  * @param string $periodType
  * @param string|int|null $customStart
  * @param string|int|null $customEnd
  * @return $this
  */
 public function setSelectPeriod($periodType, $customStart = null, $customEnd = null)
 {
     switch ($periodType) {
         case "24h":
             $customStart = $this->dateTime->toTimestamp(true) - 86400;
             $customEnd = $this->dateTime->toTimestamp(true);
             break;
         case "7d":
             $customStart = $this->dateTime->toTimestamp(true) - 604800;
             $customEnd = $this->dateTime->toTimestamp(true);
             break;
         case "30d":
             $customStart = $this->dateTime->toTimestamp(true) - 2592000;
             $customEnd = $this->dateTime->toTimestamp(true);
             break;
         case "1y":
             $customStart = $this->dateTime->toTimestamp(true) - 31536000;
             $customEnd = $this->dateTime->toTimestamp(true);
             break;
         default:
             if (is_string($customStart)) {
                 $customStart = strtotime($customStart);
             }
             if (is_string($customEnd)) {
                 $customEnd = strtotime($customEnd);
             }
             break;
     }
     return $this;
 }
Example #3
0
 /**
  * Populate all static view files for specified root path and list of languages
  *
  * @param ObjectManagerFactory $omFactory
  * @param array $locales
  * @return void
  */
 public function deploy(ObjectManagerFactory $omFactory, array $locales)
 {
     $this->omFactory = $omFactory;
     if ($this->isDryRun) {
         $this->logger->logMessage('Dry run. Nothing will be recorded to the target directory.');
     }
     $langList = implode(', ', $locales);
     $this->logger->logMessage("Requested languages: {$langList}");
     $libFiles = $this->filesUtil->getStaticLibraryFiles();
     list($areas, $appFiles) = $this->collectAppFiles($locales);
     foreach ($areas as $area => $themes) {
         $this->emulateApplicationArea($area);
         foreach ($locales as $locale) {
             foreach ($themes as $themePath) {
                 $this->logger->logMessage("=== {$area} -> {$themePath} -> {$locale} ===");
                 $this->count = 0;
                 $this->errorCount = 0;
                 foreach ($appFiles as $info) {
                     list(, , , $module, $filePath) = $info;
                     $this->deployFile($filePath, $area, $themePath, $locale, $module);
                 }
                 foreach ($libFiles as $filePath) {
                     $this->deployFile($filePath, $area, $themePath, $locale, null);
                 }
                 $this->logger->logMessage("\nSuccessful: {$this->count} files; errors: {$this->errorCount}\n---\n");
             }
         }
     }
     $version = $this->dateTime->toTimestamp(true);
     $this->logger->logMessage("New version of deployed files: {$version}");
     if (!$this->isDryRun) {
         $this->versionStorage->save($version);
     }
 }
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testGetStoreCreateDate()
 {
     $customer = $this->_loadCustomer();
     $date = $this->_context->getLocaleDate()->scopeDate($customer->getStoreId(), $this->dateTime->toTimestamp($customer->getCreatedAt()), true);
     $storeCreateDate = $this->_block->formatDate($date, \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM, true);
     $this->assertEquals($storeCreateDate, $this->_block->getStoreCreateDate());
 }
Example #5
0
 /**
  * Return last login at in Unix time format
  *
  * @return int
  */
 public function getLoginAtTimestamp()
 {
     $loginAt = $this->getLoginAt();
     if ($loginAt) {
         return $this->dateTime->toTimestamp($loginAt);
     }
     return null;
 }
Example #6
0
 /**
  * Update tax percents for WEEE based on products condition
  *
  * @param Product|ConditionInterface|int $productCondition
  * @return $this
  */
 protected function _updateDiscountPercents($productCondition = null)
 {
     $now = $this->dateTime->toTimestamp($this->dateTime->now());
     $adapter = $this->_getWriteAdapter();
     $select = $this->_getReadAdapter()->select();
     $select->from(array('data' => $this->getTable('catalogrule_product')));
     $deleteCondition = '';
     if ($productCondition) {
         if ($productCondition instanceof Product) {
             $select->where('product_id = ?', (int) $productCondition->getId());
             $deleteCondition = $adapter->quoteInto('entity_id=?', (int) $productCondition->getId());
         } elseif ($productCondition instanceof ConditionInterface) {
             $productCondition = $productCondition->getIdsSelect($adapter)->__toString();
             $select->where("product_id IN ({$productCondition})");
             $deleteCondition = "entity_id IN ({$productCondition})";
         } else {
             $select->where('product_id = ?', (int) $productCondition);
             $deleteCondition = $adapter->quoteInto('entity_id = ?', (int) $productCondition);
         }
     } else {
         $select->where('(from_time <= ? OR from_time = 0)', $now)->where('(to_time >= ? OR to_time = 0)', $now);
     }
     $adapter->delete($this->getTable('weee_discount'), $deleteCondition);
     $select->order(array('data.website_id', 'data.customer_group_id', 'data.product_id', 'data.sort_order'));
     $data = $this->_getReadAdapter()->query($select);
     $productData = array();
     $stops = array();
     $prevKey = false;
     while ($row = $data->fetch()) {
         $key = "{$row['product_id']}-{$row['website_id']}-{$row['customer_group_id']}";
         if (isset($stops[$key]) && $stops[$key]) {
             continue;
         }
         if ($prevKey && $prevKey != $key) {
             foreach ($productData as $product) {
                 $adapter->insert($this->getTable('weee_discount'), $product);
             }
             $productData = array();
         }
         if ($row['action_operator'] == 'by_percent') {
             if (isset($productData[$key])) {
                 $productData[$key]['value'] -= $productData[$key]['value'] / 100 * $row['action_amount'];
             } else {
                 $productData[$key] = array('entity_id' => $row['product_id'], 'customer_group_id' => $row['customer_group_id'], 'website_id' => $row['website_id'], 'value' => 100 - max(0, min(100, $row['action_amount'])));
             }
         }
         if ($row['action_stop']) {
             $stops[$key] = true;
         }
         $prevKey = $key;
     }
     foreach ($productData as $product) {
         $adapter->insert($this->getTable('weee_discount'), $product);
     }
     return $this;
 }
Example #7
0
 /**
  * Add information about product ids to visitor/customer
  *
  * @param \Magento\Framework\Object|\Magento\Reports\Model\Product\Index\AbstractIndex $object
  * @param array $productIds
  * @return $this
  */
 public function registerIds(\Magento\Framework\Object $object, $productIds)
 {
     $row = array('visitor_id' => $object->getVisitorId(), 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId());
     $addedAt = $this->dateTime->toTimestamp(true);
     $data = array();
     foreach ($productIds as $productId) {
         $productId = (int) $productId;
         if ($productId) {
             $row['product_id'] = $productId;
             $row['added_at'] = $this->dateTime->formatDate($addedAt);
             $data[] = $row;
         }
         $addedAt -= $addedAt > 0 ? 1 : 0;
     }
     $matchFields = array('product_id', 'store_id');
     foreach ($data as $row) {
         $this->_resourceHelper->mergeVisitorProductIndex($this->getMainTable(), $row, $matchFields);
     }
     return $this;
 }
Example #8
0
 /**
  * Check if current reset password link token is expired
  *
  * @return bool
  */
 public function isResetPasswordLinkTokenExpired()
 {
     $linkToken = $this->getRpToken();
     $linkTokenCreatedAt = $this->getRpTokenCreatedAt();
     if (empty($linkToken) || empty($linkTokenCreatedAt)) {
         return true;
     }
     $expirationPeriod = $this->_userData->getResetPasswordLinkExpirationPeriod();
     $currentTimestamp = $this->dateTime->toTimestamp($this->dateTime->now());
     $tokenTimestamp = $this->dateTime->toTimestamp($linkTokenCreatedAt);
     if ($tokenTimestamp > $currentTimestamp) {
         return true;
     }
     $dayDifference = floor(($currentTimestamp - $tokenTimestamp) / (24 * 60 * 60));
     if ($dayDifference >= $expirationPeriod) {
         return true;
     }
     return false;
 }
Example #9
0
 /**
  * Get object created at date affected with object store timezone
  *
  * @return \Magento\Framework\Stdlib\DateTime\Date
  */
 public function getCreatedAtStoreDate()
 {
     return $this->_localeDate->scopeDate($this->getStore(), $this->dateTime->toTimestamp($this->getCreatedAt()), true);
 }
Example #10
0
 /**
  * @return string
  */
 public function getStoreCreateDate()
 {
     $date = $this->_localeDate->scopeDate($this->getCustomer()->getStoreId(), $this->dateTime->toTimestamp($this->getCustomer()->getCreatedAt()), true);
     return $this->formatDate($date, TimezoneInterface::FORMAT_TYPE_MEDIUM, true);
 }