رسالة مخصصة على أساس الإجمالي للتوصيل المجاني

magento.stackexchange https://magento.stackexchange.com//questions/75909

  •  13-12-2019
  •  | 
  •  

سؤال

هل من الممكن عرض رسالة في مربع منبثق أو تنبيه على صفحة سلة التسوق عندما يقترب العميل من حد التوصيل المجاني، أي؟

"أنفق 5 جنيهات إسترلينية أخرى وستكون مؤهلاً للحصول على التوصيل المجاني"

هل كانت مفيدة؟

المحلول

قم بإنشاء الوحدة النمطية الخاصة بك.دعونا نسميها StackExchange_FreeShipping
سوف تحتاج إلى الملفات التالية:

app/etc/modules/StackExchange_FreeShipping.xml - ملف الإقرار

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_FreeShipping>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Shipping />
            </depends>
        </StackExchange_FreeShipping>
    </modules>
</config>

app/code/local/StackExchange/FreeShipping/etc/config.xml - ملف التكوين

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_FreeShipping>
            <version>0.0.1</version>
        </StackExchange_FreeShipping>
    </modules>
    <global>
        <helpers>
            <stackexchange_freeshipping>
                <class>StackExchange_FreeShipping_Helper</class>
            </stackexchange_freeshipping>
        </helpers>
        <models>
            <stackexchange_freeshipping>
                <class>StackExchange_FreeShipping_Model</class>
            </stackexchange_freeshipping>
        </models>
    </global>
    <frontend>
        <translate>
            <modules>
                <StackExchange_FreeShipping>
                    <files>
                        <default>StackExchange_FreeShipping.csv</default>
                    </files>
                </StackExchange_FreeShipping>
            </modules>
        </translate>
        <events>
            <controller_action_predispatch_checkout_cart_index>
                <observers>
                    <stackexchange_freeshipping>
                        <class>stackexchange_freeshipping/observer</class>
                        <method>checkFreeShipping</method>
                    </stackexchange_freeshipping>
                </observers>
            </controller_action_predispatch_checkout_cart_index>
        </events>
    </frontend>
</config>

app/code/local/StackExchange/FreeShipping/Model/Observer.php - المراقب الذي يتحقق مما إذا كنت قريبًا من الشحن المجاني

<?php
class StackExchange_FreeShipping_Model_Observer 
{
    public function checkFreeShipping($observer) 
    {
        //if free shipping is not enabled, do nothing
        if (!Mage::getStoreConfig('carriers/freeshipping/active')) {
            return $this;
        }
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        //if there are no products in the cart, again, do nothing
        if (count($quote->getAllItems()) == 0 ){
            return $this;
        }
        //get the quote subtotal
        $subtotal = $quote->getSubtotal();
        //get the free shipping
        $freeShippingValue = Mage::getStoreConfig('carriers/freeshipping/free_shipping_subtotal');
        //check if the cart is below the free shipping amount
        if ($freeShippingValue > $subtotal) {
            Mage::getSingleton('checkout/session')->addNotice(
                Mage::helper('stackexchange_freeshipping')->__(
                    'Your cart has the has the value of %s. In order to get free shipping you need to order for %s more',
                    '<span style="color:green">'.Mage::helper('core')->currency($subtotal, true, false).'</span>',
                    '<span style="color:red">'.Mage::helper('core')->currency($freeShippingValue - $subtotal, true, false).'</span>'
                )
            );
        }

    }
}

app/locale/en_US/StackExchange_FreeShipping.csv - ملف الترجمة.يمكنك إضافة هذا لكل لغة لديك:

"Your cart has the has the value of %s. In order to get free shipping you need to order for %s more","Your cart has the has the value of %s. In order to get free shipping you need to order for %s more"

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

Your cart has the has the value of 34$. In order to get free shipping you need to order for 15$ more.

نصائح أخرى

عند إكمال إجابة Marius، عليك إضافة المساعد آخر، وإلا سيكون لديك خطأ بدون

التطبيق / الرمز / المحلي / stackexchange / freeshipping / helper / data.php

giveacodicetagpre.

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