Ejemplo n.º 1
0
 protected function _create(array $data)
 {
     try {
         if (!empty($data)) {
             foreach ($data['items'] as $cmspages) {
                 $identifier = trim($cmspages['identifier']);
                 $cmsPage = Mage::getModel('cms/page');
                 $cmsCheck = $cmsPage->getResource()->checkIdentifier($identifier, $cmspages['store_ids']);
                 if ($cmsCheck) {
                     $cmsPage->load($cmsCheck);
                 }
                 if ($cmsPage->isObjectNew()) {
                     $cmsPage->setIdentifier($identifier)->setCreationTime(Varien_Date::now());
                 }
                 $cmsPage->setUpdateTime(Varien_Date::now())->setStores(array($cmspages['store_ids']))->setIsActive($cmspages['is_active'])->setTitle($cmspages['title'])->setContent($cmspages['content'])->setRootTemplate($cmspages['root_template'])->setMetaKeywords($cmspages['meta_keywords'])->setMetaDescription($cmspages['meta_description'])->setContentHeading($cmspages['content_heading'])->setSortOrder($cmspages['sort_order'])->setLayoutUpdateXml($cmspages['layout_update_xml'])->setCustomTheme($cmspages['custom_theme'])->setCustomRootTemplate($cmspages['custom_root_template'])->setCustomLayoutUpdateXml($cmspages['custom_layout_update_xml'])->setCustomThemeFrom($cmspages['custom_theme_from'])->setCustomThemeTo($cmspages['custom_theme_to'])->save();
             }
         } else {
             $this->_critical('Empty data found');
         }
     } catch (Mage_Eav_Model_Entity_Attribute_Exception $e) {
         $this->_critical(sprintf('Invalid attribute "%s": %s', $e->getAttributeCode(), $e->getMessage()), Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
     } catch (Mage_Core_Exception $e) {
         $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
     } catch (Exception $e) {
         $this->_critical(self::RESOURCE_UNKNOWN_ERROR);
     }
 }
Ejemplo n.º 2
0
 /**
  * Start edit order initialization
  */
 public function startAction()
 {
     $this->_getSession()->clear();
     $orderId = $this->getRequest()->getParam('order_id');
     $order = Mage::getModel('sales/order')->load($orderId);
     if ($order->getId()) {
         $this->_getSession()->setUseOldShippingMethod(true);
         $this->_getOrderCreateModel()->initFromOrder($order);
         /**
          * Lock Order Here
          */
         $write = Mage::getSingleton('core/resource')->getConnection('core_write');
         $condition = array($write->quoteInto('order_id=?', $order->getIncrementId()));
         $write->delete('lockorder', $condition);
         $sql = "INSERT INTO lockorder values (?,?,?,?,?)";
         //insert query
         $write->query($sql, array('', $order->getIncrementId(), '1', Varien_Date::now(), ''));
         //write to database
         /**
          * End of Lock Order Here
          */
         $this->_redirect('*/*');
     } else {
         $this->_redirect('*/sales_order/');
     }
 }
Ejemplo n.º 3
0
 /**
  * Update Customer from visitor (Customer logged in)
  *
  * @param Mage_Reports_Model_Product_Index_Abstract $object
  * @return Mage_Reports_Model_Resource_Product_Index_Abstract
  */
 public function updateCustomerFromVisitor(Mage_Reports_Model_Product_Index_Abstract $object)
 {
     /**
      * Do nothing if customer not logged in
      */
     if (!$object->getCustomerId() || !$object->getVisitorId()) {
         return $this;
     }
     $adapter = $this->_getWriteAdapter();
     $select = $adapter->select()->from($this->getMainTable())->where('visitor_id = ?', $object->getVisitorId());
     $rowSet = $select->query()->fetchAll();
     foreach ($rowSet as $row) {
         /* We need to determine if there are rows with known
              customer for current product.
            */
         $select = $adapter->select()->from($this->getMainTable())->where('customer_id = ?', $object->getCustomerId())->where('product_id = ?', $row['product_id']);
         $idx = $adapter->fetchRow($select);
         if ($idx) {
             /* If we are here it means that we have two rows: one with known customer, but second just visitor is set
              * One row should be updated with customer_id, second should be deleted
              *
              */
             $adapter->delete($this->getMainTable(), array('index_id = ?' => $row['index_id']));
             $where = array('index_id = ?' => $idx['index_id']);
             $data = array('visitor_id' => $object->getVisitorId(), 'store_id' => $object->getStoreId(), 'added_at' => Varien_Date::now());
         } else {
             $where = array('index_id = ?' => $row['index_id']);
             $data = array('customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId(), 'added_at' => Varien_Date::now());
         }
         $adapter->update($this->getMainTable(), $data, $where);
     }
     return $this;
 }
Ejemplo n.º 4
0
 protected function _create(array $data)
 {
     try {
         if (!empty($data)) {
             foreach ($data['items'] as $cmsblocks) {
                 $storeArray = array();
                 $storeArray = explode(',', $cmsblocks['store_ids']);
                 $identifier = trim($cmsblocks['identifier']);
                 $cmsBlock = Mage::getModel('cms/block');
                 $collection = Mage::getModel('cms/block')->getCollection()->addStoreFilter($storeArray, false)->addFieldToFilter('identifier', $identifier);
                 //->toArray();
                 $collectionData = $collection->getData();
                 if (isset($collectionData[0]['block_id'])) {
                     $cmsBlock->load($collectionData[0]['block_id']);
                 }
                 if ($cmsBlock->isObjectNew()) {
                     $cmsBlock->setIdentifier($identifier)->setCreationTime(Varien_Date::now());
                 }
                 $cmsBlock->setUpdateTime(Varien_Date::now())->setStores(array($cmsblocks['store_ids']))->setIsActive($cmsblocks['is_active'])->setTitle($cmsblocks['title'])->setContent($cmsblocks['content'])->save();
             }
         } else {
             $this->_critical('Empty data found');
         }
     } catch (Mage_Eav_Model_Entity_Attribute_Exception $e) {
         $this->_critical(sprintf('Invalid attribute "%s": %s', $e->getAttributeCode(), $e->getMessage()), Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
     } catch (Mage_Core_Exception $e) {
         $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
     } catch (Exception $e) {
         $this->_critical(self::RESOURCE_UNKNOWN_ERROR);
     }
 }
Ejemplo n.º 5
0
 protected function setDate()
 {
     $currentTime = Varien_Date::now();
     if ((!$this->getId() || $this->isObjectNew()) && !$this->getCreatedAt()) {
         $this->setCreatedAt($currentTime);
     }
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Set created date
  *
  * @param Mage_Core_Model_Object $object
  * @return Mage_Eav_Model_Entity_Attribute_Backend_Time_Created
  */
 public function beforeSave($object)
 {
     $attributeCode = $this->getAttribute()->getAttributeCode();
     if ($object->isObjectNew() && is_null($object->getData($attributeCode))) {
         $object->setData($attributeCode, Varien_Date::now());
     }
     return $this;
 }
Ejemplo n.º 7
0
 /**
  * If object is new adds creation date
  *
  * @return NoPro_Bluemoon_Model_Bluemoon
  */
 protected function _beforeSave()
 {
     parent::_beforeSave();
     if ($this->isObjectNew()) {
         $this->setData('created_at', Varien_Date::now());
     }
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * Return the current date in internal format.
  *
  * @param bool $withoutTime day only flag
  *
  * @return string
  */
 public function now($withoutTime = false)
 {
     if (method_exists("Varien_Date", "now")) {
         return Varien_Date::now($withoutTime);
     } else {
         $format = $withoutTime ? "Y-m-d" : "Y-m-d H:i:s";
         return date($format);
     }
 }
Ejemplo n.º 9
0
 /**
  * Update tax percents for WEEE based on products condition
  *
  * @param mixed $productCondition
  * @return Mage_Weee_Model_Resource_Tax
  */
 protected function _updateDiscountPercents($productCondition = null)
 {
     $now = Varien_Date::toTimestamp(Varien_Date::now());
     $adapter = $this->_getWriteAdapter();
     $select = $this->_getReadAdapter()->select();
     $select->from(array('data' => $this->getTable('catalogrule/rule_product')));
     $deleteCondition = '';
     if ($productCondition) {
         if ($productCondition instanceof Mage_Catalog_Model_Product) {
             $select->where('product_id = ?', (int) $productCondition->getId());
             $deleteCondition = $adapter->quoteInto('entity_id=?', (int) $productCondition->getId());
         } elseif ($productCondition instanceof Mage_Catalog_Model_Product_Condition_Interface) {
             $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 - $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;
 }
Ejemplo n.º 10
0
 /**
  * Processing object before save data
  *
  * @return Mage_Core_Model_Abstract
  */
 protected function _beforeSave()
 {
     if (!$this->hasTrackCode()) {
         $this->_dataSaveAllowed = false;
     } else {
         $this->setCreatedAt(Varien_Date::now());
         $this->setRemoteIp(Mage::helper('core/http')->getRemoteAddr());
     }
     return parent::_beforeSave();
 }
Ejemplo n.º 11
0
 /**
  * Prepare data for save
  *
  * @param Mage_Core_Model_Abstract $object
  * @return array
  */
 protected function _prepareDataForSave(Mage_Core_Model_Abstract $object)
 {
     $currentTime = Varien_Date::now();
     if ((!$object->getId() || $object->isObjectNew()) && !$object->getCreatedAt()) {
         $object->setCreatedAt($currentTime);
     }
     $object->setUpdatedAt($currentTime);
     $data = parent::_prepareDataForSave($object);
     return $data;
 }
Ejemplo n.º 12
0
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     foreach ($this->_serializedAttr as $attrCode) {
         if (is_array($object->getData($attrCode))) {
             $object->setData($attrCode, serialize($object->getData($attrCode)));
         }
     }
     $now = Varien_Date::now(false);
     $object->setUpdatedAt($now);
 }
Ejemplo n.º 13
0
 /**
  * Setup the prepared design change collection.
  * 
  * @param int    $storeId The current store ID.
  * @param string $date    The current date.
  * 
  * @return Mage_Core_Model_Resource_Design_Collection
  */
 protected function _initCollection($storeId, $date = null)
 {
     if (!$this->_preparedCollection) {
         if (is_null($date)) {
             $date = Varien_Date::now();
         }
         $collection = $this->getCollection()->addStoreFilter($storeId);
         $collection->getSelect()->where('enabled = 1')->where('date_from <= ? or date_from IS NULL', $date)->where('date_to >= ? or date_to IS NULL', $date);
         $this->_preparedCollection = $collection;
     }
     return $this->_preparedCollection;
 }
Ejemplo n.º 14
0
 /**
  * Prepare some data before save processing
  *
  * @param Mage_Core_Model_Abstract $object
  *
  * @return MatheusGontijo_EasyShippingRules_Model_Resource_Custommethod
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if (!$object->getPricePercentage()) {
         $object->setPricePercentage(null);
     }
     if (!$object->getId()) {
         $object->setCreatedAt(Varien_Date::now());
     } else {
         $object->setUpdatedAt(Varien_Date::now());
     }
     return $this;
 }
Ejemplo n.º 15
0
 /**
  *
  * @param <type> $observer
  * @return <type>
  * @desciption After saving credit memo, Relase Lock
  */
 public function sales_order_creditmemo_refund($observer)
 {
     $orderId = Mage::app()->getFrontController()->getRequest()->getParam('order_id');
     $order = Mage::getModel('sales/order')->load($orderId);
     $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
     $connection->beginTransaction();
     $fields = array();
     $fields['status'] = '0';
     $fields['lock_released'] = Varien_Date::now();
     $where = $connection->quoteInto('order_id =?', $order->getIncrementId());
     $connection->update('lockorder', $fields, $where);
     $connection->commit();
     return;
 }
Ejemplo n.º 16
0
 /**
  * Set created date
  * Set created date in UTC time zone
  *
  * @param Mage_Core_Model_Object $object
  * @return Mage_Eav_Model_Entity_Attribute_Backend_Time_Created
  */
 public function beforeSave($object)
 {
     $attributeCode = $this->getAttribute()->getAttributeCode();
     $date = $object->getData($attributeCode);
     if (is_null($date)) {
         if ($object->isObjectNew()) {
             $object->setData($attributeCode, Varien_Date::now());
         }
     } else {
         // convert to UTC
         $zendDate = Mage::app()->getLocale()->utcDate(null, $date, true);
         $object->setData($attributeCode, $zendDate->getIso());
     }
     return $this;
 }
Ejemplo n.º 17
0
 /**
  * Before save actions
  *
  * @return Mage_Api2_Model_Acl_Global_Role
  */
 protected function _beforeSave()
 {
     if ($this->isObjectNew() && null === $this->getCreatedAt()) {
         $this->setCreatedAt(Varien_Date::now());
     } else {
         $this->setUpdatedAt(Varien_Date::now());
     }
     //check and protect guest role
     if (Mage_Api2_Model_Acl_Global_Role::isSystemRole($this) && $this->getRoleName() != $this->getOrigData('role_name')) {
         /** @var $helper Mage_Core_Helper_Data */
         $helper = Mage::helper('core');
         Mage::throwException(Mage::helper('api2')->__('%s role is a special one and can\'t be changed.', $helper->escapeHtml($this->getRoleName())));
     }
     parent::_beforeSave();
     return $this;
 }
 /**
  * Prepare some data before save processing
  *
  * @param Mage_Core_Model_Abstract $object
  *
  * @return MatheusGontijo_EasyShippingRules_Model_Resource_Existingmethod
  */
 protected function _beforeSave(Mage_Core_Model_Abstract $object)
 {
     if ($object->hasShippingMethodCodes()) {
         $shippingMethodCodes = implode(',', $object->getShippingMethodCodes());
         $object->setShippingMethodCodes($shippingMethodCodes);
     }
     if (!$object->getPricePercentage()) {
         $object->setPricePercentage(null);
     }
     if (!$object->getId()) {
         $object->setCreatedAt(Varien_Date::now());
     } else {
         $object->setUpdatedAt(Varien_Date::now());
     }
     return $this;
 }
Ejemplo n.º 19
0
 public function messagePostAction()
 {
     if ($_ticket = $this->_initTicket()) {
         try {
             $data = $this->getRequest()->getPost();
             $message = Mage::getModel('inchoo_tickets/messages')->setData($data);
             $currentTime = Varien_Date::now();
             $message->setTicketId($_ticket->getTicketId())->setAdminId(Mage::getSingleton('admin/session')->getUser()->getUserId())->setCreatedAt($currentTime)->save();
             $this->loadLayout('empty');
             $this->renderLayout();
         } catch (Mage_Core_Exception $e) {
             Mage::logException($e->getMessage());
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
         }
     }
 }
Ejemplo n.º 20
0
 public function registerAbandonedCart($minDelay, $maxDelay)
 {
     $quotes = Mage::getModel('sales/quote')->getCollection()->addFieldToFilter('main_table.is_active', 1)->addFieldToFilter('main_table.items_count', array('gt' => 0))->addFieldToFilter('main_table.customer_email', array('notnull' => true))->addFieldToFilter('main_table.updated_at', array('lt' => $this->_getDateSubTime($minDelay)))->addFieldToFilter('main_table.updated_at', array('gt' => $this->_getDateSubTime($maxDelay)));
     if (!$this->_getHelper()->followVirtual()) {
         $quotes->addFieldToFilter('main_table.is_virtual', 0);
     }
     $quotes->getSelect()->joinLeft(array('followup' => $this->getMainTable()), 'followup.quote_id=main_table.entity_id', array())->where('followup.followup_id is null');
     Mage::dispatchEvent('adm_abandonedcart_quote_collection_load_before', array('collection' => $quotes));
     if ($quotes->getSize() > 0) {
         $folloupRows = array();
         foreach ($quotes as $quote) {
             $folloupRows[] = array('quote_id' => $quote->getId(), 'store_id' => $quote->getStoreId(), 'abandoned_at' => $quote->getUpdatedAt(), 'customer_id' => $quote->getCustomerId(), 'customer_email' => $quote->getCustomerEmail(), 'secret_code' => md5(uniqid()), 'currency' => $quote->getQuoteCurrencyCode(), 'base_grand_total' => $quote->getBaseGrandTotal(), 'coupon_code' => $quote->getCouponCode(), 'mail_scheduled_at' => Varien_Date::now());
         }
         $affectedRows = $this->_getWriteAdapter()->insertMultiple($this->getMainTable(), $folloupRows);
     } else {
         $affectedRows = 0;
     }
     return $affectedRows;
 }
Ejemplo n.º 21
0
 public function create_with_subscription($store = null, $subscription_id = false)
 {
     $storeId = $this->_getStoreId($store);
     try {
         $currentTime = Varien_Date::now();
         /*@var $quote Mage_Sales_Model_Quote*/
         $quote = Mage::getModel('sales/quote');
         $quote->setStoreId($storeId)->setIsActive(false)->setIsMultiShipping(false);
         if ($subscription_id) {
             $quote->setSubscriptionId($subscription_id);
             $subscription = Mage::getModel("pixsubscription/subscription")->load($subscription_id);
             $subscription->setUpdatedAt($currentTime);
             $subscription->save();
             $subscription->activate();
         }
         $quote->save();
     } catch (Mage_Core_Exception $e) {
         $this->_fault('create_quote_fault', $e->getMessage());
     }
     return (int) $quote->getId();
 }
Ejemplo n.º 22
0
 /**
  * @magentoDataFixture Mage/Core/_files/design_change.php
  * @magentoConfigFixture current_store general/locale/timezone UTC
  */
 public function testLoadChangeCache()
 {
     $date = Varien_Date::now(true);
     $storeId = Mage::app()->getAnyStoreView()->getId();
     // fixture design_change
     $cacheId = 'design_change_' . md5($storeId . $date);
     $design = new Mage_Core_Model_Design();
     $design->loadChange($storeId, $date);
     $cachedDesign = Mage::app()->loadCache($cacheId);
     $cachedDesign = unserialize($cachedDesign);
     $this->assertInternalType('array', $cachedDesign);
     $this->assertArrayHasKey('design', $cachedDesign);
     $this->assertEquals($cachedDesign['design'], $design->getDesign());
     $design->setDesign('default/default/default')->save();
     $design = new Mage_Core_Model_Design();
     $design->loadChange($storeId, $date);
     $cachedDesign = Mage::app()->loadCache($cacheId);
     $cachedDesign = unserialize($cachedDesign);
     $this->assertTrue(is_array($cachedDesign));
     $this->assertEquals($cachedDesign['design'], $design->getDesign());
 }
 /**
  *  Save donation when the order reach specified status
  */
 function orderSaveAfter(Varien_Event_Observer $observer)
 {
     // Get order from event
     $order = $observer->getEvent()->getOrder();
     // Get old and new data for comparing
     $original_data = $order->getOrigData();
     $new_data = $order->getData();
     // Detect order reach configured status
     $status = Mage::getSingleton('donations/config')->getOrderStatus();
     if ($original_data['status'] != $status && $new_data['status'] == $status) {
         // Check if donation was done
         $donatedAmount = 0;
         $pid = Mage::getSingleton('donations/config')->getProductId();
         foreach ($order->getAllVisibleItems() as $item) {
             if ($item->getProductId() == $pid) {
                 $donatedAmount += $item->getBaseRowTotal();
             }
         }
         // If donation was made, add to the table
         if ($donatedAmount > 0) {
             // Try to load donation or new object
             $donation = Mage::getModel('donations/donations')->getCollection()->addFieldToFilter('order_id', $order->getId())->getFirstItem();
             if (!is_object($donation) || $donation->getId() == '') {
                 $donation = Mage::getModel('donations/donations');
             }
             // Set data and save
             $donation->setOrderId($order->getId());
             $donation->setIncrementId($order->getIncrementId());
             $donation->setStoreId($order->getStoreId());
             $donation->setCustomerFirstname($order->getCustomerFirstname());
             $donation->setCustomerLastname($order->getCustomerLastname());
             $donation->setCustomerEmail($order->getCustomerEmail());
             $donation->setAmount($donatedAmount);
             $donation->setCurrency($order->getOrderCurrencyCode());
             $donation->setCreatedAt(Varien_Date::now());
             $donation->save();
         }
     }
 }
Ejemplo n.º 24
0
 public function __construct()
 {
     $this->localFolder = Mage::getBaseDir('var') . DS . 'lecom';
     $this->localOutbound = $this->localFolder . DS . 'outbound';
     $this->localOutboundOtf = $this->localOutbound . DS . 'ordtofulfill' . DS;
     $this->localOutboundOtfArcv = $this->localOutbound . DS . 'ordtofulfill_arcv' . DS;
     $this->localOutboundOtfErr = $this->localOutbound . DS . 'ordtofulfill_err' . DS;
     $remoteOutboundOtf = Mage::getStoreConfig('orders/paths/otf');
     $this->remoteOutboundOtf = trim($remoteOutboundOtf);
     Mage::getModel('logger/logger')->saveLogger("order_fulfillment", "Information", __FILE__, "DB Outbound Path:" . $this->remoteOutboundOtf);
     if (empty($this->remoteOutboundOtf)) {
         $this->remoteOutboundOtf = '/mnt/lecomotf/outbound/ordtofulfill/';
     }
     if (!is_dir($this->localFolder)) {
         mkdir($this->localFolder, 0777);
         chmod($this->localFolder, 0777);
     }
     if (!is_dir($this->localOutbound)) {
         mkdir($this->localOutbound, 0777);
         chmod($this->localOutbound, 0777);
     }
     if (!is_dir($this->localOutboundOtf)) {
         mkdir($this->localOutboundOtf, 0777);
         chmod($this->localOutboundOtf, 0777);
     }
     if (!is_dir($this->localOutboundOtfArcv)) {
         mkdir($this->localOutboundOtfArcv, 0777);
         chmod($this->localOutboundOtfArcv, 0777);
     }
     if (!is_dir($this->localOutboundOtfErr)) {
         mkdir($this->localOutboundOtfErr, 0777);
         chmod($this->localOutboundOtfErr, 0777);
     }
     $this->lockPeriod = Mage::getStoreConfig('lockorder/time_setting/release_after');
     if (empty($this->lockPeriod)) {
         $this->lockPeriod = 1;
     }
     $this->ctime = Varien_Date::now();
 }
Ejemplo n.º 25
0
 public function run()
 {
     $orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('state', array(array('eq' => Mage_Sales_Model_Order::STATE_PENDING_PAYMENT), array('eq' => Mage_Sales_Model_Order::STATE_HOLDED)));
     foreach ($orders as $order) {
         if (!Mage::getStoreConfigFlag(self::XML_PATH_CANCEL_PENDING, $order->getStoreId())) {
             continue;
         }
         if (!intval(Mage::getStoreConfig(self::XML_PATH_CANCEL_AFTER, $order->getStoreId()))) {
             continue;
         }
         if (strtotime(Varien_Date::now()) - strtotime($order->getCreatedAt()) < Mage::getStoreConfig(self::XML_PATH_CANCEL_AFTER, $order->getStoreId()) * 60) {
             continue;
         }
         if (Mage_Sales_Model_Order::STATE_HOLDED == $order->getState()) {
             if (!Mage::getStoreConfigFlag(self::XML_PATH_CANCEL_SEQURA, $order->getStoreId())) {
                 continue;
             }
             if (in_array($order->getPayment()->getMethod(), $this->sequra_methods)) {
                 if ($order->canUnhold()) {
                     $order->unhold()->save();
                 }
             }
         }
         if (!$order->canCancel() || $order->hasInvoices() || $order->hasShipments()) {
             continue;
         }
         try {
             $order->cancel();
             if ($status = Mage::getStoreConfig(self::XML_PATH_CANCEL_STATUS, $order->getStoreId())) {
                 $order->addStatusHistoryComment('', $status)->setIsCustomerNotified(null);
             }
             $order->save();
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
 }
Ejemplo n.º 26
0
 /**
  * @param string        $token
  * @param HpsCreditCard $cardData
  * @param string        $cardType
  * @param integer|null  $customerId
  * @return Hps_Securesubmit_Model_Storedcard
  */
 public function saveMultiToken($token, $cardData, $cardType, $customerId = null)
 {
     $_session = Mage::getSingleton('customer/session');
     $_loggedIn = $_session->isLoggedIn();
     if ($_loggedIn || $customerId != null) {
         if ($customerId == null) {
             $_customerId = $_session->getCustomer()->getId();
         } else {
             $_customerId = $customerId;
         }
         $storedCard = Mage::getModel('hps_securesubmit/storedcard');
         $storedCard->setDt(Varien_Date::now())->setCustomerId($_customerId)->setTokenValue($token)->setCcType($cardType)->setCcLast4($cardData->number)->setCcExpMonth(str_pad($cardData->expMonth, 2, '0', STR_PAD_LEFT))->setCcExpYear($cardData->expYear);
         try {
             $storedCard->removeDuplicates();
             $storedCard->save();
             return $storedCard;
         } catch (Exception $e) {
             if ($e->getCode() == '23000') {
                 Mage::throwException($this->__('Customer Not Found  : Card could not be saved.'));
             }
             Mage::throwException($e->getMessage());
         }
     }
 }
Ejemplo n.º 27
0
 /**
  * Check if current reset password link token is expired
  *
  * @return boolean
  */
 public function isResetPasswordLinkTokenExpired()
 {
     $resetPasswordLinkToken = $this->getRpToken();
     $resetPasswordLinkTokenCreatedAt = $this->getRpTokenCreatedAt();
     if (empty($resetPasswordLinkToken) || empty($resetPasswordLinkTokenCreatedAt)) {
         return true;
     }
     $tokenExpirationPeriod = Mage::helper('admin')->getResetPasswordLinkExpirationPeriod();
     $currentDate = Varien_Date::now();
     $currentTimestamp = Varien_Date::toTimestamp($currentDate);
     $tokenTimestamp = Varien_Date::toTimestamp($resetPasswordLinkTokenCreatedAt);
     if ($tokenTimestamp > $currentTimestamp) {
         return true;
     }
     $dayDifference = floor(($currentTimestamp - $tokenTimestamp) / (24 * 60 * 60));
     if ($dayDifference >= $tokenExpirationPeriod) {
         return true;
     }
     return false;
 }
Ejemplo n.º 28
0
 /**
  * Set modified date
  *
  * @param Varien_Object $object
  * @return Mage_Eav_Model_Entity_Attribute_Backend_Time_Updated
  */
 public function beforeSave($object)
 {
     $object->setData($this->getAttribute()->getAttributeCode(), Varien_Date::now());
     return $this;
 }
 public function pushbackAction()
 {
     $oAuthClient = Mage::getModel('transfer/oauth_client');
     $params = $oAuthClient->getConfigFromSession();
     $oAuthClient->init($params);
     $state = $oAuthClient->authenticate();
     $acessToken = $oAuthClient->getAuthorizedToken();
     if ($state == Wage_Transfer_Model_OAuth_Client::OAUTH_STATE_NO_TOKEN) {
         Mage::getSingleton('adminhtml/session')->addError('Authorization has been rejected.');
         $redirectUrl = Mage::helper("adminhtml")->getUrl("adminhtml/cms_page");
         Mage::app()->getResponse()->setRedirect($redirectUrl);
         return;
     }
     if ($state == Wage_Transfer_Model_OAuth_Client::OAUTH_STATE_ACCESS_TOKEN) {
         $accessToken = $oAuthClient->getAuthorizedToken();
         $tokenArray = explode('&', $accessToken);
         $oauth_token = explode('=', $tokenArray[0])[1];
         $oauth_token_secret = explode('=', $tokenArray[1])[1];
         $consumerKey = $params['consumerKey'];
         $consumerSecret = $params['consumerSecret'];
     }
     if (isset($oauth_token) && isset($oauth_token_secret) && isset($consumerKey) && isset($consumerSecret)) {
         $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
         $oauthClient->setToken($oauth_token, $oauth_token_secret);
         $resourceUrl = $this->livehost . '/api/rest/cpages/';
         $cmsSession = Mage::getSingleton('core/session');
         $getCmsSession = $cmsSession->getPushcms();
         $cpagesData = array();
         if (Mage::getStoreConfig('transfer/general/log')) {
             Mage::log(print_r($getCmsSession, true), null, 'TransferLog.log');
         }
         $collection = Mage::getModel('cms/page')->getCollection()->addFieldToFilter('main_table.page_id', array('in' => $getCmsSession));
         $collection->getSelect()->columns("GROUP_CONCAT(page_store.store_id SEPARATOR ',') AS store_ids")->join(array('page_store' => $collection->getTable('cms/page_store')), 'main_table.page_id = page_store.page_id', array())->group('main_table.page_id');
         foreach ($collection as $key => $value) {
             $cpagesData['items'][] = $value->getData();
         }
         if (Mage::getStoreConfig('transfer/general/log')) {
             Mage::log(print_r($cpagesData, true), null, 'TransferLog.log');
         }
         $oauthClient->fetch($resourceUrl, json_encode($cpagesData), OAUTH_HTTP_METHOD_POST, array('Accept' => 'application/json', 'Content-Type' => 'application/json'));
         $getCmsSessionData = implode(',', $getCmsSession);
         $nowTimestamp = Varien_Date::now();
         $write = Mage::getSingleton('core/resource')->getConnection('core_write');
         $write->update("cms_page", array("push_to_live" => $nowTimestamp), "page_id IN ({$getCmsSessionData})");
         Mage::getSingleton('core/session')->unsPushcms();
     }
     //$pushpageData = json_decode($oauthClient->getLastResponse(), true);
     Mage::getSingleton('adminhtml/session')->addSuccess('CMS Pages updated successfully in live.');
     $redirectUrl = Mage::helper("adminhtml")->getUrl("adminhtml/cms_page");
     Mage::app()->getResponse()->setRedirect($redirectUrl);
 }
Ejemplo n.º 30
0
 /**
  * Load changes for specific store and date
  *
  * @param int $storeId
  * @param string $date
  * @return array
  */
 public function loadChange($storeId, $date = null)
 {
     if (is_null($date)) {
         $date = Varien_Date::now();
     }
     $select = $this->_getReadAdapter()->select()->from(array('main_table' => $this->getTable('design_change')))->where('store_id = :store_id')->where('date_from <= :required_date or date_from IS NULL')->where('date_to >= :required_date or date_to IS NULL');
     $bind = array('store_id' => (int) $storeId, 'required_date' => $date);
     return $this->_getReadAdapter()->fetchRow($select, $bind);
 }