小编use*_*921的帖子

Magento - 单笔优惠券标记为待付款时使用

我遇到了Magento单一优惠券代码的问题,该代码被标记为在客户点击"下订单"按钮时使用.如果Paypal付款失败或客户在订单完成之前离开页面,他将无法返回并重新订购此优惠券,该优惠券设置为仅使用一次,并且已标记已被使用.

我找到了一段代码,减少了用户使用优惠券的次数,并允许他重复使用优惠券.不幸的是,他在单击下订单按钮时​​尝试连接Paypal页面时出错.为了能够再次使用优惠券并访问Paypal页面,我必须使用此客户的ID 删除表salesrule_coupon_usagesalesrule_customer中SQL数据库中的行.

以下是我需要更改以自动删除客户ID的优惠券使用信息的代码:

public function cancel($observer)
{
    $order = $observer->getEvent()->getPayment()->getOrder();
    if ($order->canCancel()) {
        if ($code = $order->getCouponCode()) {
            $coupon = Mage::getModel('salesrule/coupon')->load($code, 'code');
            if ($coupon->getTimesUsed() > 0) {
                $coupon->setTimesUsed($coupon->getTimesUsed() - 1);
                $coupon->save();
            }

            $rule = Mage::getModel('salesrule/rule')->load($coupon->getRuleId());
            error_log("\nrule times used=" . $rule->getTimesUsed(), 3, "var/log/debug.log");
            if ($rule->getTimesUsed() > 0) {
                $rule->setTimesUsed($rule->getTimesUsed()-1);
                $rule->save();
            }

            if ($customerId = $order->getCustomerId()) {
                if ($customerCoupon = Mage::getModel('salesrule/rule_customer')->loadByCustomerRule($customerId, $rule->getId())) {
                    $couponUsage = new Varien_Object();
                    Mage::getResourceModel('salesrule/coupon_usage')->loadByCustomerCoupon($couponUsage, $customerId, $coupon->getId());

                    if ($couponUsage->getTimesUsed() > 0) { …
Run Code Online (Sandbox Code Playgroud)

php sql paypal magento coupon

15
推荐指数
1
解决办法
3262
查看次数

标签 统计

coupon ×1

magento ×1

paypal ×1

php ×1

sql ×1