how to add shipping charges by date in magento? - php

I want to make an option if the customer want same day delivery the delivery charges will be $10 else it will be standard charges. just want to add check-box for same day delivery.i have that much information only, if someone can help I would be really happy since its been tough for me.

Assuming you have passed deliveryDate in request shipping object.
If we consider code of flat rate.Then in below function
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
If($request->Deliverydate == Today )// replace code for getting today
{
ShippingPrice=10;
}
elseif ($this->getConfigData('type') == 'O') { // per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') { // per item
$shippingPrice = ($request->getPackageQty() * $this->getConfigData('price')) - ($this->getFreeBoxes() * $this->getConfigData('price'));
} else {
$shippingPrice = false;
}

Related

Calculate function definition location in OpenCart

I just started studying OpenCart, downloaded latest version of opencart and reading the documentation about where to find the function definition of tax calculate function.
In the non admin side, opening any Products shows data with tax calculation. Here is code it uses it.
$this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))
Is there any link to check the location of tax class for checking the calculate function definition?
Not quite sure what exactly do you want to achieve. But the calculate function you can find in system/library/cart/tax.php.
public function calculate($value, $tax_class_id, $calculate = true) {
if ($tax_class_id && $calculate) {
$amount = 0;
$tax_rates = $this->getRates($value, $tax_class_id);
foreach ($tax_rates as $tax_rate) {
if ($calculate != 'P' && $calculate != 'F') {
$amount += $tax_rate['amount'];
} elseif ($tax_rate['type'] == $calculate) {
$amount += $tax_rate['amount'];
}
}
return $value + $amount;
} else {
return $value;
}
}
Although in this file you will find a lot of interesting connected with tax processing in OpenCart.
If this information not enough - please, describe the desired result with more details and I will try to help.

Magento 1.9 remove tax on checkout when user enter VAT

I'm trying to make magento modification when user enter vat number on checkout remove tax from order.
I found a code on stackoverflow which support on magento older version but it not work with new version 1.9,
I made few modifications for work the condition and return 0,even it return 0 checkout still shows tax.
here is my code which is on file
/app/code/core/Mage/Tax/Model/Calculation.php line number 268
public function getRate($request)
{
if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
return 0;
}
//my code
$ctax= Mage::getSingleton('checkout/session')->getQuote()->getCustomerTaxvat();
if ($this->getCustomer() && $ctax !='') {
//echo 'test';
return 0;
}
//end my code
$cacheKey = $this->_getRequestCacheKey($request);
if (!isset($this->_rateCache[$cacheKey])) {
$this->unsRateValue();
$this->unsCalculationProcess();
$this->unsEventModuleId();
Mage::dispatchEvent('tax_rate_data_fetch', array(
'request' => $request));
if (!$this->hasRateValue()) {
$rateInfo = $this->_getResource()->getRateInfo($request);
$this->setCalculationProcess($rateInfo['process']);
$this->setRateValue($rateInfo['value']);
} else {
$this->setCalculationProcess($this->_formCalculationProcess());
}
$this->_rateCache[$cacheKey] = $this->getRateValue();
$this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
}
return $this->_rateCache[$cacheKey];
}
Anyone can help me to make tax 0 when user enters vat number on checkout, Thanks a lot
I've managed to solve my problem by following this thread : Modify tax rate on cart quote items and recalculate
I have added an Observer to the event sales_quote_collect_totals_before.
And here is the content of my observer, very simple :
public function removetax($observer)
{
$customer_id = Mage::getSingleton('customer/session')->getId();
$customer = Mage::getModel("customer/customer")->load($customer_id);
if($customer->getIsTaxExempt() == 1)
{
$items = $observer->getEvent()->getQuote()->getAllVisibleItems();
foreach($items as $item)
$item->getProduct()->setTaxClassId(0);
}
}
If customer is tax exempt, I grab the current cart content and for each item, I set the product tax class to 0. It is mandatory to not save the product or the item. The aim here is to set a value for the following calculation, not to save it in the database. Tax classes need to stay to the initial value in the db.
You can use sales_quote_collect_totals_before event.
then you have to define logic for remove tax on checkout page.
This link you can refer.
Go to Calculation.php and find the calcTaxAmount() and add billing condditions
public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
{
$billing = Mage::getModel('checkout/session')->getQuote()->getCustomerTaxvat();
if($billing !="")
{
return 0;
}
}

Magento: Change Swiss B2B Customer to specific Magento Customer Group

I need a solution to change the customer group of customers with a default shipping address in Swiss or Norway. We have multiple store views. One of this is the b2b store view. I need a solution only for this store view. Is there a way to define this via Magento Tax Configuration?
I tried to solve this over the event trigger <customer_save_before> but at this point I can't get data from new saved shipping addresses.
Update - what i've tried so far:
public function customerSaveBefore(Varien_Event_Observer $observer)
{
/* #var $customer Mage_Customer_Model_Customer */
$customer = $observer->getCustomer();
if($customer->getPrimaryShippingAddress()) {
$adress = $customer->getDefaultShippingAddress()->getCountryId();
if (Mage::helper('core')->isCountryInEU($adress) === TRUE && $customer->getGroupId() == "5") {
$customer->setGroupId('3');
}
elseif (Mage::helper('core')->isCountryInEU($adress) === FALSE && $customer->getGroupId() == "3") {
$customer->setGroupId('5');
}
}
}

Magento disable tax when customer enter vat number on checkout

I have magento 1.7 site and i'm tiring to remove that tax from customers if they enter an tax number on checkout page.
i have two countries Netherlands and Belgium for tax rules both have 10% taxes.the default country is Belgium.
i need to remove the tax adding when Belgium customer enter there vat number on checkout page.
i tired using tax rules but no luck.
anyone have idea about how to do that using magento backend or using code level.any answers i appreciated.
thank you
Over ride Magento's Tax Model getRate() function is how we did something similar.
class My_Module_Model_Tax_Calculation extends Mage_Tax_Model_Calculation
{
public function getRate($request)
{
if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
return 0;
}
$country_id = $request->getCountryId();
if ($country_id == 'BE' && $this->getCustomer() && $this->getCustomer()->getTaxvat()) {
return 0;
}
$cacheKey = $this->_getRequestCacheKey($request);
if (!isset($this->_rateCache[$cacheKey])) {
$this->unsRateValue();
$this->unsCalculationProcess();
$this->unsEventModuleId();
Mage::dispatchEvent('tax_rate_data_fetch', array('request'=>$request));
if (!$this->hasRateValue()) {
$rateInfo = $this->_getResource()->getRateInfo($request);
$this->setCalculationProcess($rateInfo['process']);
$this->setRateValue($rateInfo['value']);
} else {
$this->setCalculationProcess($this->_formCalculationProcess());
}
$this->_rateCache[$cacheKey] = $this->getRateValue();
$this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
}
return $this->_rateCache[$cacheKey];
}
}

Magento getData from guest on success.phtml

I am trying to get the subtotal amount on checkout success page. It works good for registred users:
$_order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$amount = $_order->getData('subtotal');
$total = number_format($amount, 2);
But when the order is processed by a guest, $total is empty.
What can be done?
P.S.: I am using Magento 1.6.1 CE
Taken from Magento's app/code/core/Mage/Checkout/Block/Onepage.php:
if (!$this->isCustomerLoggedIn()) {
return $this->getQuote()->getShippingAddress();
} else {
return Mage::getModel('sales/quote_address');
}
I am 99% sure you can do exactly the same with getOrder() and with Mage_Checkout_Block_Success =)
Note: the isCustomerLoggedIn() method is defined at Mage_Checkout_Block_Onepage_Abstract which is not inherited by Mage_Checkout_Block_Success. So, you could simply use its implementation:
public function isCustomerLoggedIn()
{
return Mage::getSingleton('customer/session')->isLoggedIn();
}
E.g. your code now shall look like this:
if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
$order = Mage::getSingleton('checkout/session')->getOrder();
} else {
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
}
Sorry for saying non-sense things before...

Categories