Example #1
0
 /**
  * Restore old attribute value
  *
  * @param Varien_Object $object
  * @param mixed $oldAttrValue
  */
 protected function _restoreOldAttrValue($object, $oldAttrValue)
 {
     $attrCode = $this->getAttribute();
     if (is_null($oldAttrValue)) {
         $object->unsetData($attrCode);
     } else {
         $object->setData($attrCode, $oldAttrValue);
     }
 }
Example #2
0
 /**
  * Prepare inventory data from custom atribute
  *
  * @param Varien_Object $object
  * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract|void
  */
 public function beforeSave($object)
 {
     /** @var $object Mage_Catalog_Model_Product  */
     $stockData = $object->getData($this->getAttribute()->getAttributeCode());
     if ($object->getStockData() !== null || $stockData !== null) {
         $object->setStockData(array_replace((array) $object->getStockData(), (array) $stockData));
     }
     $object->unsetData($this->getAttribute()->getAttributeCode());
     parent::beforeSave($object);
 }
Example #3
0
 /**
  * Try to unserialize the attribute value
  * @param Varien_Object $object
  */
 protected function _unserialize(Varien_Object $object)
 {
     $attrCode = $this->getAttribute()->getAttributeCode();
     if ($object->getData($attrCode)) {
         try {
             $unserialized = unserialize($object->getData($attrCode));
             $object->setData($attrCode, $unserialized);
         } catch (Exception $e) {
             $object->unsetData($attrCode);
         }
     }
 }
 /**
  * Try to unserialize the attribute value
  *
  * @param Varien_Object $object
  * @return Mage_Eav_Model_Entity_Attribute_Backend_Serialized
  */
 protected function _unserialize(Varien_Object $object)
 {
     $attrCode = $this->getAttribute()->getAttributeCode();
     if ($object->getData($attrCode)) {
         try {
             $unserialized = Mage::helper('core')->jsonDecode($object->getData($attrCode));
             $object->setData($attrCode, $unserialized);
         } catch (Exception $e) {
             $object->unsetData($attrCode);
         }
     }
     return $this;
 }
Example #5
0
 /**
  * Tests Varien_Object->unsetData()
  */
 public function testUnsetData()
 {
     $data = array('key1' => 'value1', 'key2' => 'value2', 'key3' => 3, 'key4' => 4);
     $this->_object->setData($data);
     $this->_object->unsetData('key1');
     unset($data['key1']);
     $this->assertEquals($data, $this->_object->getData());
     $this->_object->unsetData(array('key2', 'key3'));
     unset($data['key2']);
     unset($data['key3']);
     $this->assertEquals($data, $this->_object->getData());
     $this->_object->unsetData();
     $this->assertEquals(array(), $this->_object->getData());
 }
Example #6
0
 /**
  * Serialize specified field in an object
  *
  * @param Varien_Object $object
  * @param string $field
  * @param mixed $defaultValue
  * @param bool $unsetEmpty
  * @return Mage_Core_Model_Resource_Abstract
  */
 protected function _serializeField(Varien_Object $object, $field, $defaultValue = null, $unsetEmpty = false)
 {
     $value = $object->getData($field);
     if (empty($value)) {
         if ($unsetEmpty) {
             $object->unsetData($field);
         } else {
             if (is_object($defaultValue) || is_array($defaultValue)) {
                 $defaultValue = serialize($defaultValue);
             }
             $object->setData($field, $defaultValue);
         }
     } elseif (is_array($value) || is_object($value)) {
         $object->setData($field, serialize($value));
     }
     return $this;
 }
Example #7
0
 /**
  * Serialize specified field in an object
  *
  * @param Varien_Object $object
  * @param string        $field
  * @param null          $defaultValue
  * @param bool          $unsetEmpty
  * @param callable      $callback
  *
  * @return $this
  */
 protected function _serializeField(Varien_Object $object, $field, $defaultValue = null, $unsetEmpty = false, $callback = null)
 {
     if (!is_callable($callback)) {
         $callback = 'serialize';
     }
     $value = $object->getData($field);
     if (empty($value)) {
         if ($unsetEmpty) {
             $object->unsetData($field);
         } else {
             if (is_object($defaultValue) || is_array($defaultValue)) {
                 $defaultValue = call_user_func($callback, $defaultValue);
             }
             $object->setData($field, $defaultValue);
         }
     } elseif (is_array($value) || is_object($value)) {
         $object->setData($field, call_user_func($callback, $value));
     }
     return $this;
 }
 /**
  * Retrieves recent activity for customers (sorted by last visit date)
  */
 function getactivityAction()
 {
     if (!$this->_authenticate()) {
         return;
     }
     try {
         $request = $this->getRequest();
         $helper = Mage::helper('eyehubspot');
         $maxperpage = $request->getParam('maxperpage', self::MAX_CUSTOMER_PERPAGE);
         $maxAssociated = $request->getParam('maxassoc', self::MAX_ASSOC_PRODUCT_LIMIT);
         $start = date('Y-m-d H:i:s', $request->getParam('start', 0));
         $end = date('Y-m-d H:i:s', time() - 300);
         $websiteId = Mage::app()->getWebsite()->getId();
         $store = Mage::app()->getStore();
         $storeId = Mage::app()->getStore()->getId();
         $collection = Mage::getModel('customer/customer')->getCollection();
         $resource = Mage::getSingleton('core/resource');
         $read = $resource->getConnection('core_read');
         $customerData = array();
         try {
             // because of limitations in the log areas of magento, we cannot use the
             // standard collection to retreive the results
             $select = $read->select()->from(array('lc' => $resource->getTableName('log/customer')))->joinInner(array('lv' => $resource->getTableName('log/visitor')), 'lc.visitor_id = lv.visitor_id')->joinInner(array('vi' => $resource->getTableName('log/visitor_info')), 'lc.visitor_id = vi.visitor_id')->joinInner(array('c' => $resource->getTableName('customer/entity')), 'c.entity_id = lc.customer_id', array('email' => 'email', 'customer_since' => 'created_at'))->joinInner(array('p' => $resource->getTableName('log/url_info_table')), 'p.url_id = lv.last_url_id', array('last_url' => 'p.url', 'last_referer' => 'p.referer'))->where('lc.customer_id > 0')->where("lv.last_visit_at >= '{$start}'")->where("lv.last_visit_at < '{$end}'")->order('lv.last_visit_at')->limit($maxperpage);
             $collection = $read->fetchAll($select);
         } catch (Exception $e) {
             $this->_outputError(self::ERROR_CODE_UNSUPPORTED_SQL, 'DB Exception on query', $e);
             return;
         }
         foreach ($collection as $assoc) {
             $log = new Varien_Object($assoc);
             $customerId = $log->getCustomerId();
             // merge and replace older data with newer
             if (isset($customerData[$customerId])) {
                 $temp = $customerData[$customerId];
                 $log->addData($temp->getData());
                 $log->setFirstVisitAt($temp->getFirstVisitAt());
             } else {
                 $log->setViewed($helper->getProductViewedList($customerId, $maxAssociated));
                 $log->setCompare($helper->getProductCompareList($customerId, $maxAssociated));
                 $log->setWishlist($helper->getProductWishlist($customerId, $maxAssociated));
             }
             $log->unsetData('session_id');
             $customerData[$customerId] = $log;
         }
     } catch (Exception $e) {
         $this->_outputError(self::ERROR_CODE_UNKNOWN_EXCEPTION, 'Unknown exception on request', $e);
         return;
     }
     $this->_outputJson(array('visitors' => $helper->convertAttributeData($customerData), 'website' => $websiteId, 'store' => $storeId));
 }
Example #9
0
 /**
  * Executes the task and updates the status.
  *
  * @throws Exception on an unexpected configuration error.
  */
 public function run()
 {
     if ($this->getStatus() != self::STATUS_RUNNING) {
         throw new Exception('Cannot run job when status is not \'running\'.');
     }
     // Mark invalid if task not defined
     if (!$this->getTaskConfig('class')) {
         $this->updateStatus(self::STATUS_INVALID, 'Task not properly defined.')->save();
         return;
     }
     // If task is globally disabled, put job on hold.
     if ($this->isTaskDisabled()) {
         $this->updateStatus(self::STATUS_DISABLED)->save();
         return;
     }
     // Load task
     switch ((string) $this->getTaskConfig('type')) {
         case 'helper':
             $object = Mage::helper((string) $this->getTaskConfig('class'));
             break;
         case 'model':
             $object = Mage::getModel((string) $this->getTaskConfig('class'));
             break;
         case 'resource':
             $object = Mage::getResourceSingleton((string) $this->getTaskConfig('class'));
             break;
         case 'singleton':
         default:
             $object = Mage::getSingleton((string) $this->getTaskConfig('class'));
             break;
     }
     if (!$object) {
         $this->updateStatus(self::STATUS_INVALID, 'Could not get task model.')->save();
         return;
     }
     // Confirm existence of method
     $method = (string) $this->getTaskConfig('method');
     if (!method_exists($object, $method)) {
         $this->updateStatus(self::STATUS_INVALID, 'Cannot call task method.')->save();
         return;
     }
     $data = new Varien_Object($this->getJobData());
     // Run task
     try {
         // Load object if a load_index is specified
         if ($this->getTaskConfig('type') == 'model' && ($loadIndex = $this->getTaskConfig('load_index'))) {
             if (!$data->hasData($loadIndex)) {
                 throw new Exception('No id in job data to load by.');
             }
             $object->load($data->getData($loadIndex), $loadIndex);
             $data->unsetData($loadIndex);
             if (!$object->getId()) {
                 throw new Exception('Object could not be loaded.');
             }
         }
         $object->{$method}($data, $this);
         // If status not changed by task, assume success
         if ($this->getStatus() == self::STATUS_RUNNING || $this->getStatus() == self::STATUS_SUCCESS) {
             // Update or delete?
             if ($this->getTaskConfig()->is('after_success', 'keep')) {
                 $this->updateStatus(self::STATUS_SUCCESS);
             } else {
                 $this->isDeleted(true);
             }
         }
     } catch (Exception $e) {
         if ($this->getStatus() == self::STATUS_RUNNING) {
             $this->logError($e);
             // Retry
             if ($this->canRetry()) {
                 $this->scheduleRetry();
             } else {
                 if ($this->getTaskConfig()->is('after_failure', 'delete')) {
                     $this->isDeleted(true);
                 } else {
                     $this->updateStatus(self::STATUS_FAILED, $e->getMessage());
                 }
             }
         }
     }
     $this->save();
 }