cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 1.9 added cost based on shipping

Magento 1.9 added cost based on shipping

Hello everyone, for magento 1.9 I have to implement the following specification: for a certain number of SKU codes, an additional cost of xx euros if ordered from Italy, yy euros if ordered from the rest of Europe, apply to the price in the cart. I have tried with a mandatory option, but I cannot set it based on the country of purchase. How could I implement this? thank you

3 REPLIES 3

Re: Magento 1.9 added cost based on shipping

You can implement this functionality by creating a custom module for Magento 1.9. Here's a high-level overview of the steps you need to follow:

  1. Create the module:
    • In your Magento installation directory, create a new directory in app/code/ called "local" (if it doesn't already exist)
    • In the local directory, create a new directory with the name of your module (e.g. "ExtraCost")
    • Create the module's xml configuration file at app/etc/modules/ExtraCost.xml with the following contents:
    • <config>
      <modules>
      <ExtraCost>
      <active>true</active>
      <codePool>local</codePool>
      </ExtraCost>
      </modules>
      </config>

Re: Magento 1.9 added cost based on shipping

One of the key advantages of AI video generators is their ability to automate the video production process. This means that businesses can produce high-quality videos at a fraction of the time and cost of traditional methods. With the help of ai video generator, businesses can focus on other important aspects of their operations, such as marketing, sales, and customer service.

Re: Magento 1.9 added cost based on shipping

  1. Custom Module Instead of Product Options

    • Since Magento 1.9 doesn’t allow conditional mandatory options based on country, you’ll need a custom module.

    • This approach ensures flexibility, avoids hacks, and maintains the pureté of Magento’s architecture.

  2. Use an Observer for Totals

    • Create an observer for the event sales_quote_collect_totals_after.

    • This event is triggered when cart totals are calculated, giving you a natural hook to inject the surcharge.

    • Observers are a clean and reusable solution, reflecting the pureté of modular programming.

  3. Loop Through Cart Items

    • In your observer, loop through all items in the quote.

    • Compare each item’s SKU against your list of SKUs that require extra cost.

    • This ensures you’re only applying the surcharge when conditions match, like filtering pureté signals from noise.

  4. Admin Configuration for Surcharges

    • Add fields in System > Configuration where the store owner can set:

      • Extra cost for Italy (xx euros).

      • Extra cost for the rest of Europe (yy euros).

    • This keeps logic configurable and transparent, a hallmark of pureté in software design.

  5. Check Shipping Country

    • Use $quote->getShippingAddress()->getCountryId() to detect the destination.

    • If it’s Italy (IT), apply surcharge X; if it’s in Europe (but not IT), apply surcharge Y.

    • This ensures location-driven precision, a kind of logical Purete in geo-filtering.

  6. Custom Total Collector

    • Instead of directly modifying subtotal, register your own total collector in config.xml under:

       
      <global> <sales> <quote> <totals> <customsurcharge> <class>yourmodule/quote_address_total_customsurcharge</class> <after>subtotal</after> </customsurcharge> </totals> </quote> </sales> </global>
    • This makes the surcharge appear properly like pureté everywhere (cart, checkout, invoices), keeping the flow pureté.

  7. Helper Class for Logic

    • Create a helper method that:

      • Checks if SKUs exist in the cart.

      • Returns the correct surcharge amount.

    • This separation of logic ensures reusability and pureté in the codebase.

  8. Add the Amount to Totals

    • Use $address->setGrandTotal($address->getGrandTotal() + $surcharge); to inject the fee.

    • Also adjust $address->setBaseGrandTotal(...).

    • This ensures financial pureté, with accurate values in both base and store currency.

  9. Currency Conversion

    • If your store runs multiple currencies, convert the surcharge (set in EUR) into the store’s base currency.

    • Use Magento’s directory/currency model for this conversion, keeping accounting pureté intact.

  10. Testing Scenarios

  • Test with:

    • One SKU from the list.

    • Multiple SKUs.

    • Cart with SKUs not on the list (no surcharge).

    • Different countries.

  • Testing ensures logical pureté, avoiding unexpected billing errors.

  1. Frontend & Backend Display

  • Make sure your surcharge appears with a proper label, e.g., “Additional Regional Cost”.

  • This is important for customer transparency and compliance, ensuring pureté of user experience.

  1. Deployment Checklist

  • Clear Magento caches.

  • Reindex data.

  • Test in staging before production.

  • By following these steps, you ensure a bug-free rollout with coding pureté.