Please, there is no reason to"jerry-rigg" a gift certificate or coupon for tax calculation - they are just forms of payment, not unlike any other payment mechanism. Tax calculation happens before payment, not as part of payment.
Please, there is no reason to"jerry-rigg" a gift certificate or coupon for tax calculation - they are just forms of payment, not unlike any other payment mechanism. Tax calculation happens before payment, not as part of payment.
Let me explain... By default, Gift Certificates are processed through TaxCloud, with a sales tax assigned to them unless you take all Gift Certificates and assign them 10005 as their TIC. Under the default module, you have to include the five digit code as part of the description to the Tax Class. The change that I made is that you don't have to add it this way but instead by adding a field to /admin/tax_class.php and database whereof and adding it there. When the function func_taxcloud_get_tic($product_id) is called, it will see this:
This function reads as, pull up the tax class TIC AND product model of the item in question. If the Product Model contains the ZenCart keyword of "GIFT" in the beginning of the product model, this is a Gift Certificate and should be assigned a TIC of 10005. All others, continue to search and bring up the TIC of the tax class in question and assign that. (If all else fails, assign it to zero.) So far in my testing of the above, it does return 10005. Essentially this does nothing different from the original function that was made except two things: I make all GIFT models have a TIC of 10005 and I use the TIC field I made instead of the description to look it up. If someone does something silly like put a letter in the TIC field, it still returns 0 as intended.PHP Code:
function func_taxcloud_get_tic($product_id) {
global $db;
$query = "SELECT tc.tax_class_tic, p.products_model FROM " . TABLE_PRODUCTS . " as p LEFT JOIN " . TABLE_TAX_CLASS . " as tc ON p.products_tax_class_id = tc.tax_class_id WHERE products_id = " . $product_id;
$result = $db->Execute($query);
if (preg_match("/^(GIFT)/",trim($result->fields['products_model']))) {
$tic = 10005;
return $tic;
} else {
$tic = $result->fields['tax_class_tic'];
$i = preg_match("/^(\d+)/", $tic);
if($i != 0)
return $tic;
else
return $i;
}
}
However making an order with a Gift Certificate alone, meaning that no other items are presented during checkout, ZenCart flags the entire transaction as "virtual". (In fact, anything involving downloads and etc, flags the entire transation as "virtual" or "mixed" in the case of something that's NOT downloadable being in the same cart of something is otherwise virtual.) Upon completion of checkout and going back to TaxCloud's Control Panel, this transaction will NOT register in the Transaction listing when its just by itself. That is, if only a gift certificate was purchased, this transaction will NOT be listed in TaxCloud. Let me prove my case:
First, let's start off with just buying a $5 Gift Certificate:
So far so good, Gift Certificates should NOT be taxed... Transaction finally finishes.... We have an Order Number and email
However, going over to the TaxCloud Panel... this order is NOT listed. At first I thought it was a problem that TaxCloud wouldn't list non-taxable sales. However, during a series of botches with the coding... I discovered that is not the case. TaxCloud would still show non-taxable sales.
The only difference between two instances is that one has a delivery address (the one with the non-downloadable stuff) and one didn't. (the one with just the gift certificate).
Let's try another set. It was suggested that I give the items the proper TIC code... not sure what that has to but sure, lets try that. So this time I will add an item that has a download and a gift certificate:
Here we can see that General Digital Goods has a TIC of 93101.
No tax is charged for this... not sure if thats because 93101 has a 0% rate or not:
Order is completed, an order number assigned:
Once again, no listing on TaxCloud. (The $0.00's listed were ones I eventually deleted.
So lets try a third case, this time I'm going to add in a Document Product Type. Again, here to show that all items have been setup:
Here's the full cart: A gift certificate (no mailing), a virtual item require downloads (Multiple Downloads) assigned a TIC, a tangible item (the Die Hard DVD), and again a non-tangible item.
We get the Shipping Method due to there being a physical item needing to be mailed:
Here we can see step 2 of 3, and its coming nicely:
Moment of truth time, confirmation of the cart:
Alas, this time, the order is listed... all with the correct TICs:
So after all of this goes on... I REALLY do not know why the orders are not appearing in TaxCloud. They appear in ZenCart okay, minus a few formatting errors which I can resolve... The coding as you can see by the last panel, doesn't affect the TIC look ups. They are still being assigned (off panel is the shipping line which works still.) I don't know if I can go ahead and just call this a non-issue since the taxes are being calculated I guess, but I'm just lost at this. Barring anything, let's just say there is a jurisdiction that charges sales tax on downloadables (there are a few). Shouldn't the transaction still register and show in TaxCloud? Shouldn't all transactions show in TaxCloud if this was the case? But instead, I get nothing.
Last edited by retched; 6 May 2014 at 08:27 PM.
Have you tried adjusting your transaction display settings --> options?
By default, if you don't issue an Auth/Capture call, TaxCloud does not display the transaction in the list, because as far as TaxCloud knows, the purchase wasn't completed. If you adjust your display options, your can unckeck the Auth and Cap checkboxes, then you will see all lookups - and you should see your lookup.
Question: Is it possible that auth and capture (or authWithCap) are not getting called if no tax was collected?
After two days of nearly pulling my hair out, I have submitted a patch to the TaxCloud GitHub. It requires a change to /includes/classes/observers/class.taxcloudObserver.php to solve the problem of transactions with no delivery addresses from being posted to TaxCloud. You get this bug with transactions in which no deliverable items are found. This is due to the inner workings of ZenCart not assigning a delivery address for any non-physical items or items in which the store owner says "does not need a delivery address". Since there was no delivery address captured, the $TAXCLOUD_ENABLE check would always fail since there is no delivery address and the function func_taxcloud_authorized_with_capture wouldn't run.
The changes will now tell TaxCloud/ZenCart to pull up an order's country code from the delivery_country, billing_country, and customers_country fields. If the order does not have a delivery_country, the program will look to the billing_country. If the order does not have a billing_country either, go to the customers_country. Since it is possible to not require a customers_country on account creation, the penultimate fall back would be to use the STORE_COUNTRY definition defined in the Configuration > My Store area. If all of that fails, I just assigned a number of 0 like it was in default.
Make the changes as follows in /catalog/includes/classes/observers/class.taxcloudObserver.php:
Near line 24 FIND:
REPLACE with:PHP Code:
$results = $db->Execute("select delivery_country from " . TABLE_ORDERS . "
where orders_id = '" . (int)$insert_id . "'");
Near line 27, FIND:PHP Code:
$order_details = $db->Execute("select c1.countries_id AS delivery_lid, c2.countries_id AS billing_lid, c3.countries_id AS customer_lid
FROM " . TABLE_ORDERS . " o
LEFT JOIN " . TABLE_COUNTRIES . " c1
ON c1.countries_name = o.delivery_country
LEFT JOIN " . TABLE_COUNTRIES . " c2
ON c2.countries_name = o.billing_country
LEFT JOIN " . TABLE_COUNTRIES . " c3
ON c3.countries_name = o.customers_country
WHERE o.orders_id = " . (int)$insert_id);
REPLACE with:PHP Code:
$country_id = 0;
if ( $results->fields['delivery_country'] == 'United States' ) {
$country_id = 223;
}
This should fix any problem with transactions not being posted onto TaxCloudPHP Code:
if (is_numeric($order_details->fields['delivery_lid'])) {
// Is the delivery country id from the select query a number? If so, assign it to $country_id
$country_id = $order_details->fields['delivery_lid'];
} else if (is_numeric($order_details->fields['billing_lid'])) {
// The number wasn't a number, it was likely a null value. Instead, assign it to the BILLING address
$country_id = $order_details->fields['billing_lid'];
} else if (is_numeric($order_details->fields['customer_lid'])) {
$country_id = $order_details->fields['customer_lid'];
} else if (is_numeric(STORE_COUNTRY)) {
$country_id = STORE_COUNTRY; // So we don't have an id for delivery, billing, OR the customer, use the store ID
} else { // If all else fails, just use 0.
$country_id = 0;
}
The full edit is made available here.
https://github.com/retched/ZenCart/c...bdac1fd05613a3
Last edited by retched; 9 May 2014 at 10:54 PM. Reason: formatting
Bookmarks