tags:

views:

28

answers:

1

i am trying to set a tax rate for a guest (not logged in) based on a coupon code.

i have tried every singleton i can think of and am having trouble even manually setting the customertaxrateid that i would like to set.

any ideas?

A: 

so update and answer... i made a really stupid mistake placing my code but after finding a complete lack of information about these subjects on the web... i thought i would share some code... commented instead of the custom solution i am using... but it works!!!

the code needs to be added in: /app/code/core/Mage/Tax/Model/Calculation.php

$couponCode = Mage::getSingleton('checkout/cart')->getQuote()->getCouponCode(); if (!empty($couponCode)) {

    $db = Mage::getSingleton('core/resource')->getConnection('core_read');
    $query = ""//put your sql query here since magento makes it hard to respect MVC when a group of setters and getters think you are running mysql4 even though you are using mysql5
            $result = $db->query($query);

    while ($row = $result->fetch() ) {
        //lazy method to avoid the need for more error handling                 
        $customerTaxClass = $row['class_id'];
    }

}

it should be done in the getRateRequest function before it creates the $request to return.

jkatzer
This is a really poor way to write this code. 1. You are hacking the core code. You should at least copy Calculation.php into `app/code/local/...` before making your changes. Preferably write your own module that rewrites the model, or use an Observer. 2. You shouldn't write raw SQL. Learn and use the Magento data access system, it will save you much pain for maintenance. Read through the questions here, or consult Alan Storm's blog. 3. Be careful about abusing Magento in your code comments when you admit yourself to being new to the architecture. It may be smarter than you first realize!
Jonathan Day
after hours of trying i could not get (and i am paraphrasing the code here) Mage::getResourceModel('tax/class')->getCollection() or any variance to work. for this model object they are not implemented when using mysql4. also i could not find a good resource on how to get magento to realize that i have always been using mysql5. i had the perfect MVC code... with add_field_filters and everything, but i could not get the basic object to work.. they are not implemented for tax classes for mysql4
jkatzer