Exemple #1
0
 /**
  * Try to associate reminder rule with matched customers.
  * If customer was added earlier, update is_active column.
  *
  * @param Enterprise_Reminder_Model_Rule $rule
  * @param Mage_SalesRule_Model_Rule $salesRule
  * @param int $websiteId
  * @return Enterprise_Reminder_Model_Mysql4_Rule
  */
 public function saveMatchedCustomers($rule, $salesRule, $websiteId, $threshold = null)
 {
     $rule->setConditions(null);
     $rule->afterLoad();
     $select = $rule->getConditions()->getConditionsSql(null, $websiteId);
     if (!$rule->getConditionSql()) {
         return $this;
     }
     if ($threshold) {
         $select->where('c.emails_failed IS NULL OR c.emails_failed < ? ', $threshold);
     }
     $i = 0;
     $ruleId = $rule->getId();
     $adapter = $this->_getWriteAdapter();
     $currentDate = $this->formatDate(time());
     $dataToInsert = array();
     $stmt = $adapter->query($select, array('rule_id' => $ruleId));
     try {
         $adapter->beginTransaction();
         while ($row = $stmt->fetch()) {
             if (empty($row['coupon_id']) && $salesRule) {
                 $coupon = $salesRule->acquireCoupon();
                 $couponId = $coupon !== null ? $coupon->getId() : null;
             } else {
                 $couponId = $row['coupon_id'];
             }
             $dataToInsert[] = array('rule_id' => $ruleId, 'coupon_id' => $couponId, 'customer_id' => $row['entity_id'], 'associated_at' => $currentDate, 'is_active' => '1');
             $i++;
             if ($i % 1000 == 0) {
                 $this->_saveMatchedCustomerData($dataToInsert);
                 $adapter->commit();
                 $adapter->beginTransaction();
                 $dataToInsert = array();
             }
         }
         $this->_saveMatchedCustomerData($dataToInsert);
         $adapter->commit();
     } catch (Exception $e) {
         $adapter->rollBack();
         throw $e;
     }
     return $this;
 }
 /**
  * Save all website ids associated to rule
  *
  * @deprecated after 1.11.2.0 use $this->bindRuleToEntity() instead
  *
  * @param Enterprise_Reminder_Model_Rule $rule
  * @return Enterprise_Reminder_Model_Resource_Rule
  */
 protected function _saveWebsiteIds($rule)
 {
     if ($rule->hasWebsiteIds()) {
         $websiteIds = $rule->getWebsiteIds();
         if (!is_array($websiteIds)) {
             $websiteIds = explode(',', (string) $websiteIds);
         }
         $this->bindRuleToEntity($rule->getId(), $websiteIds, 'website');
     }
     return $this;
 }
Exemple #3
0
 /**
  * Return url for current row
  *
  * @param Enterprise_Reminder_Model_Rule $row
  * @return string
  */
 public function getRowUrl($row)
 {
     return $this->getUrl('*/*/edit', array('id' => $row->getRuleId()));
 }