سؤال

لقد تم العمل على المشروع الذي يتطلب العملاء للحصول على الخصم التلقائي رمز تطبيقها على سلة على أساس البنود التي هي في هناك.

ظننت أن هذا العمل تماما مع قانون المنطق أدناه.كنت أرى رمز الحصول على ولدت (في الخلفية وأظهرت خصم على عربة).لكن اليوم وقد أثار هذا العميل الائتمان لا يمكن أن يكون حصرا لدفع النظام.

لدي بنجاح ضاقت عليه إلى هذه الوحدة التي عند تعطيل المشكلة ليست في الوقت الحاضر.فإنني أعتقد أنه بما أننا توليد رمز على الطاير و السماح الماجنتو التعامل مع الخصم الفعلي هذا يجب أن تعمل بشكل طبيعي.التصحيح تبين أن المجموع الكلي لا يزال السعر الأصلي عند التحقق من إذا كان ذلك متوفرا في الخروج.

هل هناك منطق إضافية التي لا تحتاج إلى إدخال هذا متوافق ؟

يرجى أن يكون على علم بأن لدي ملثمين مساحة الاسم/اسم الوحدة النمطية قليلا بسبب سرية العميل الأسباب لذلك قد بقعة بعض الأخطاء الواردة في هذا ولكن الرجاء تجاهل مثل قانون تنفيذ وتشغيل ما كنت أتوقع أن.

التوقعات:

إذا كان العميل يفي بمعايير خصم رمز الخصم يتم إنشاؤها والحصول على خصم ضد عربة.

إذا كان العميل لديه ما يكفي من رصيد الدفع ينبغي أن تكون قادرة على دفع بالكامل مع مخزن الائتمان.

الفعلية:

رمز الخصم يتم إنشاء (عند الاقتضاء)

العميل غير قادر على استخدام متجر الائتمان لدفع كامل مبلغ الشراء.

المراقب:checkout_cart_product_add_after

public function checkout_cart_product_add_after($observer)
{
    if (!Mage::helper('core')->isModuleOutputEnabled('Namespace_WholesaleDiscount')) {
        return;
    }

    /*
     * When emptying the cart this observer is updated
     * due to the setting of it to 0 for deletion.
     * This prevents running the observer and thus resetting items in quote.
     */
    $request = Mage::app()->getRequest()->getParam('update_cart_action');
    if ($request == 'empty_cart') {
        return;
    }



    try {
        $model = Mage::getModel('salesrule/rule')
            ->getCollection()
            ->addFieldToSelect('*')
            ->addFieldToFilter('name', array('eq' => sprintf('WHOLESALE AUTO_%s', Mage::getSingleton('customer/session')->getSessionId())))
            ->load();

        if ($model->count() < 1) {
            // No coupon yet.
            $helper = Mage::helper('wholesalediscount');
            $helper->createDiscountCode($helper->getDiscountAmount(), Mage::getSingleton('customer/session')->getSessionId());

            $model = Mage::getModel('salesrule/rule')
                ->getCollection()
                ->addFieldToFilter('name', array('eq' => sprintf('WHOLESALE AUTO_%s', Mage::getSingleton('customer/session')->getSessionId())))
                ->getFirstItem();

        } else {
            $helper = Mage::helper('wholesalediscount');

            $model = $model->getFirstItem();


            $model->setDiscountAmount($helper->getDiscountAmount());
            $code = Mage::helper('core')->getRandomString(16);

            // Magento initializes the coupon_code, but on model load it is code.
            $model->setCouponCode($code);
            $model->setCode($code);

            $model->save();
        }

        $couponCode = $model->getCode();
        /* END This part is my extra, just to load our coupon for this specific customer */

        Mage::getSingleton('checkout/cart')
            ->getQuote()
            ->getShippingAddress()
            ->setCollectShippingRates(true);

        Mage::getSingleton('checkout/cart')
            ->getQuote()
            ->setCouponCode(strlen($couponCode) ? $couponCode : '')
            ->collectTotals()
            ->save();

    } catch (Exception $e) {
        Mage::logException($e);
    }

    return $this;
}

مساعد المنطق:مرة أخرى قبل ملثمين أي شيء أشعر أن تكشف عن أي منطق الأعمال أو أي خرق سرية العميل.كما كان من قبل ، طريقتين هنا ببساطة توليد خصم رمز القسيمة (الذي أرى أن العمل في الادارة و لا تنطبق على خصم) ويحسب الخصم (هذا هو تماما منطق الأعمال)

public function createDiscountCode($discount, $reference)
    {
        $now = new Zend_Date();
        $now->setTimezone('UTC');
        $data = array(
            'product_ids' => null,
            'name' => sprintf('WHOLESALE AUTO_%s', $reference),
            'description' => null,
            'is_active' => 1,
            'website_ids' => array(Mage::app()->getWebsite()->getId()),
            'customer_group_ids' => array(Mage::getSingleton('customer/session')->getCustomerGroupId()),
            'coupon_type' => 2,
            'coupon_code' => Mage::helper('core')->getRandomString(16),
            'uses_per_coupon' => 1,
            'uses_per_customer' => 1,
            'from_date' => $now->getFullYear() . "-". $now->getMonth() . "-" . $now->getDay(),
            'to_date' => null,
            'sort_order' => null,
            'is_rss' => 1,
            'rule' => array(
                'conditions' => array(
                    array(
                        'type' => 'salesrule/rule_condition_combine',
                        'aggregator' => 'all',
                        'value' => 1,
                        'new_child' => null
                    )
                )
            ),
            'simple_action' => 'cart_fixed',
            'discount_amount' => $this->getDiscountAmount(),
            'discount_qty' => 0,
            'discount_step' => null,
            'apply_to_shipping' => 0,
            'simple_free_shipping' => 0,
            'stop_rules_processing' => 0,
            'rule' => array(
                'actions' => array(
                    array(
                        'type' => 'salesrule/rule_condition_product_combine',
                        'aggregator' => 'all',
                        'value' => 1,
                        'new_child' => null
                    )
                )
            ),
            'store_labels' => array('E-Liquids With Kits')
        );

        $model = Mage::getModel('salesrule/rule');

        $validateResult = $model->validateData(new Varien_Object($data));

        if ($validateResult == true) {

            if (isset($data['simple_action']) && $data['simple_action'] == 'by_percent'
                && isset($data['discount_amount'])) {
                $data['discount_amount'] = min(100, $data['discount_amount']);
            }

            if (isset($data['rule']['conditions'])) {
                $data['conditions'] = $data['rule']['conditions'];
            }

            if (isset($data['rule']['actions'])) {
                $data['actions'] = $data['rule']['actions'];
            }

            unset($data['rule']);

            $model->setData($data);

            $model->save();
        }
    }

    /*
     * Use this to calculate how much money off is allowed based on whats in the cart.
     */
    public function getDiscountAmount()
    {
        $customer   = Mage::getSingleton('customer/session')->getCustomer();
        $cart       = Mage::getModel('checkout/cart');
        $discountItems = array();
        /* Exclude some Business logic here */
        foreach ($cart->getQuote()->getAllVisibleItems() as $_item) {
            $product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());

            /* Business Logic to decide if this item is relevent */
            $discountItems[] = $_item;

        }

        // Calculate Discount
        $appliedDiscounts = 0;
        $discount = 0;
        foreach ($discountitem as $_item) {
            if ($appliedDiscounts < $allowed) {
                $i = 0;
                while ($appliedDiscounts < $allowed && $i < $_item->getQty()) {

                    $appliedDiscounts++;
                    $discount += $_item->getProduct()->getFinalPrice();

                    $i++;

                }
            }
        }
        return $discount;
    }
هل كانت مفيدة؟

المحلول

حتى في حالة أي شخص يأتي عبر مشكلة مماثلة في المستقبل, لقد تمكنت من معرفة ما سبب لي المسألة.جمع المجاميع تم وضع العلم مما تسبب في عدم إعادة العد بعد الخصم تم تطبيقها.

Mage::getSingleton('checkout/cart')
        ->getQuote()
        ->setCouponCode(strlen($couponCode) ? $couponCode : '')
        ->collectTotals()
        ->save();

استبدال أعلاه:

Mage::getSingleton('checkout/cart')
            ->getQuote()
            ->setCouponCode(strlen($couponCode) ? $couponCode : '')
            ->save();

هذا يعني أنه عند محاولة تطبيق الائتمان العملاء ، إعادة يحسب مجموع ويصبح مؤهلا صفر الدفع الخروج.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top