本文整理汇总了PHP中Mage_SalesRule_Model_Rule::acquireCoupon方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_SalesRule_Model_Rule::acquireCoupon方法的具体用法?PHP Mage_SalesRule_Model_Rule::acquireCoupon怎么用?PHP Mage_SalesRule_Model_Rule::acquireCoupon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_SalesRule_Model_Rule
的用法示例。
在下文中一共展示了Mage_SalesRule_Model_Rule::acquireCoupon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveMatchedCustomers
/**
* 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
* @param int $threshold
*
* @return Enterprise_Reminder_Model_Resource_Rule
*/
public function saveMatchedCustomers($rule, $salesRule, $websiteId, $threshold = null)
{
$rule->setConditions(null);
$rule->afterLoad();
/** @var $select Zend_Db_Select */
$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();
$couponsTable = $this->getTable('enterprise_reminder/coupon');
$currentDate = $this->formatDate(time());
$dataToInsert = array();
$stmt = $adapter->query($select, array('rule_id' => $ruleId));
$adapter->beginTransaction();
try {
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) {
$adapter->insertOnDuplicate($couponsTable, $dataToInsert, array('is_active'));
$dataToInsert = array();
}
}
if (!empty($dataToInsert)) {
$adapter->insertOnDuplicate($couponsTable, $dataToInsert, array('is_active'));
}
} catch (Exception $e) {
$adapter->rollBack();
throw $e;
}
$adapter->commit();
return $this;
}
示例2: saveMatchedCustomers
/**
* Try to associate reminder rule with matched customers.
* If customer was added earlier, update is_active column.
*
* @param Bronto_Reminder_Model_Rule $rule
* @param null|Mage_SalesRule_Model_Rule $salesRule
* @param int $websiteId
* @param null $threshold
*
* @return $this
* @throws Exception
*/
public function saveMatchedCustomers(Bronto_Reminder_Model_Rule $rule, $salesRule, $websiteId, $threshold = null)
{
$select = $rule->getConditions()->getConditionsSql($rule, $websiteId);
$interval = Mage::helper('bronto_reminder')->getCronInterval();
if (!$rule->getConditionSql()) {
return $this;
}
if ($threshold) {
$select->where('c.emails_failed IS NULL OR c.emails_failed < ? ', $threshold);
}
// Only pull for reminders not already attached to an active record
$select->where('c.is_active IS NULL OR c.is_active <> 1');
// Handle Send Limit
$sendLimit = $rule->getSendLimit();
if ($sendLimit > 0) {
$subSelect = $this->createSelect()->from(array($this->getTable('bronto_reminder/log')), array('num_send' => 'count(log_id)', 'unique_id'))->group(array('unique_id'));
$select->joinLeft(array('l' => $subSelect), 'c.unique_id=l.unique_id', array())->where('l.num_send IS NULL OR l.num_send < ?', $sendLimit);
}
// Handle Send To Value
switch ($rule->getSendTo()) {
case 'user':
$select->where('`root`.`customer_id` IS NOT NULL AND `root`.`customer_id` != 0');
break;
case 'guest':
$select->where('`root`.`customer_id` IS NULL OR `root`.`customer_id` = 0');
break;
case 'both':
default:
// No need to filter
break;
}
$i = 0;
$ruleId = $rule->getId();
$adapter = $this->_getWriteAdapter();
$currentDate = $this->formatDate(time());
$dataToInsert = array();
Mage::helper('bronto_reminder')->writeDebug('ruleId: ' . $rule->getId() . ' website: ' . $websiteId, 'bronto_reminder_sql.log');
// Log the query with binds replaced
$this->logFullQuery($select, array('rule_id' => $ruleId, 'interval' => $interval));
/* @var $stmt Varien_Db_Statement_Pdo_Mysql */
$stmt = $adapter->query($select, array('rule_id' => $ruleId, 'interval' => $interval));
Mage::helper('bronto_reminder')->writeDebug('saveMatchedCustomers():', 'bronto_reminder_sql.log');
try {
$adapter->beginTransaction();
while ($row = $stmt->fetch()) {
if (empty($row['coupon_id']) && $salesRule) {
if ($salesRule->getCouponType() == Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC && $salesRule->getUseAutoGeneration()) {
$coupons = $salesRule->getCoupons();
if (!$coupons) {
$coupons = array();
}
foreach ($coupons as $couponTemp) {
if ($couponTemp->getUsageLimit() > $couponTemp->getTimesUsed() && (is_null($couponTemp->getExpirationDate()) || $couponTemp->getExpirationDate() > date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), date('d'), date('Y'))))) {
$coupon = $couponTemp;
}
}
} else {
$coupon = $salesRule->acquireCoupon();
}
$couponId = $coupon !== null ? $coupon->getId() : null;
} else {
$couponId = $row['coupon_id'];
}
$dataToInsert[] = array('rule_id' => $ruleId, 'product_recommendation_id' => $rule->getProductRecommendationId(), 'coupon_id' => $couponId, 'unique_id' => $row['unique_id'], 'store_id' => $row['store_id'], 'customer_id' => $row['customer_id'], 'quote_id' => $row['quote_id'], 'wishlist_id' => $row['wishlist_id'], 'customer_email' => $row['customer_email'], '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();
Mage::helper('bronto_reminder')->writeDebug(" Query Matched {$i} customers", 'bronto_reminder_sql.log');
} catch (Exception $e) {
$adapter->rollBack();
throw $e;
}
return $this;
}