I am currently developing a small shopping cart where payment options are cash on delivery and other prepaid payment options using a payment gateway. Now my cart's flow chart is like
Places order,enters address
Selects payment options ( COD or Prepaid )
If COD confirm order
If prepaid, redirect to the payment gateway page
So when the customer selects an option , the controller function handlePayment() checks if its COD or Prepaid. If its COD it shows a view page, or if its prepaid, it should redirect to the payment gateway with all necessary data in POST.
So how will I be able to accomplish this task?
You have to write if COD then $this->view->load('pagename); else you have to call another function $this->functionname($_POST);
Try this, Its a rough assumption of what you need:
function handlePayment(){
if($this->input->post('type') == "COD"){
$data = array();
$data = $this->input->post(null);
$this->load->view('cod', $data);
}else if($this->input->post('type') == "prepaid"){
$data = array();
$data = $this->input->post(null);
$this->prepaidPayment($data);
}
}
function prepaidPayment($data){
//do something with the data which contains all the post variables
}
different angle -- can you ask them the COD or Prepaid question -- first?
and then make each 'path' completely separate.
Long term that could be better for your application especially if it grows.
and might help if you can do more stringent form validation on the Prepaid track,
( like if some of that information is used as part of the credit card validation )
versus COD where the payment happens in person
Related
I'm a beginner at using Custom Function on the Zoho desk. I'm trying to update a field in the ticket template.
I have 2 fields in the ticket template [KM, COST]. The cost should equal 2*KM. For example, if KM = 100, then Cost = 200.
I created a workflow that works if the KM is updated and attached the following custom function code, but the field doesn't update.
orgId = "718524341";
response = zoho.desk.getRecordById(orgId,"tickets",TicketID,"zohodesk");
cid = response.get('cf_km');
km_cost = cid * 2;
zoho.desk.update(orgId,"tickets",TicketID,{"cf":{"cf_cost":km_cost}},"zohodesk");
The correct API Name for the tickets module in zoho desk is Tickets.
If you still can't get it to work, then try executing the function independent of the workflow with fixed parameters. Make sure to do info response and post the output here.
I want to disable a card payment method if a product has the stock below a threshold or is 0 because i have a lot of products that can be put on backorder but i don't want to allow payment by debit or credit card because there have been a lot of clients that canceled the order and payment after placing the order even if it was clearly stated that the product is on backorder.
Does anyone have any idea how i could do that ?
I'd suggest edit or override of hookPaymentOption in your module.
Check for $this->context->cart->getProducts(), loop through products and if there's something wrong just return;
This is the solution i used after to suggestion from Krystian Podemski
$products = $this->context->cart->getProducts();
foreach($products as $product){
//var_dump($product);
if($product['quantity_available'] == 0){
return;
}
}
I want to disable cash on delivery payment method option for some specific products. I want to show cash on delivery method only for specific products and need to hide other payment options.
How can I do this? I read
this other question but it did not solve my problem.
you can use following free extension to solve your problem
http://www.magentocommerce.com/magento-connect/shipping-and-payment-filters.html
Using payment_method_is_active observer you could load the current checkout session quote and check what city the order is be shipped to.
$checkout = Mage::getSingleton('checkout/session')->getQuote();
$shipping = $checkout->getShippingAddress();
$cashOnDeliveryCities = array('city name 1','city name 2',..)
if(in_array($shipping->getCity(), $cashOnDeliveryCities)){
$result->isAvailable = true;
}else{
$result->isAvailable = false;
}
Here's how to do it without an extension.
Just go to admin > per motions > Shopping Cart Price Rule and create rules for this "cash on delivery payment method option for some specific products".
First in conditions select payment method "COD" in options. After that in "Action" add product SKU, for multiple using add SKU by comma. Activate the rule and check your payment method for those products to ensure it's working.
I am writing a custom Magento module that gives rate quotes (based on an external API) on the product page. After I get the response on the product page, it adds some of the info from the response into the product view's form.
The goal is to save the address (as well as some other things, but those can be in the session for now). The address needs to be saved to the quote, so that the checkout (onestepcheckout, free version) will automatically fill those values in (city, state, zip, country, shipping method [of which there are 3]) and load the rate quote via ajax (which it's already doing).
I have gone about this by using an Observer, and watching for the cart events. I fill in the address and save it. When I end up on the cart page or checkout page ~4/5 times the data is lost, and the sql table shows that the quote_address is getting save with no address info, even though there is an explicit save.
The observer method's I've used are:
checkout_cart_update_item_complete
checkout_cart_product_add_after
The code saving is: (I've tried this with the address, quote and cart all not calling save() with the same results, as well as not calling setQuote()
// $params = Mage::app()->getRequest()->getParams()
// $quote = Mage::getSingleton('checkout/cart')->getQuote()
// or
// $quote = observer->getProduct()->getQuoteItem()->getQuote();
// where applicable, but both methods seemed to === each other
$quote->getShippingAddress()
->setCountryId($params['estimate_to_country'])
->setCity($params['estimate_to_city'])
->setPostcode($params['estimate_to_zip_code'])
->setRegionId($params['estimate_to_state_code'])
->setRegion($params['estimate_to_state'])
->setCollectShippingRates(true)
->setShippingMethod($params['carrier_method'])
->setQuote($quote)
->save();
$quote->getBillingAddress()
->setCountryId($params['estimate_to_country'])
->setCity($params['estimate_to_city'])
->setPostcode($params['estimate_to_zip_code'])
->setRegionId($params['estimate_to_state_code'])
->setRegion($params['estimate_to_state'])
->setCollectShippingRates(true)
->setShippingMethod($params['carrier_method'])
->setQuote($quote)
->save();
$quote->save();
$cart->save();
// I also tried:
Mage::getSingleton('checkout/session')->setQuote($quote);
I imagine there's a good chance this is not the best place to save this info, but I am not quite sure. I was wondering if there is a good place to do this without overriding a whole controller to save the address on the add to cart action.
Thanks so much, let me know if I need to clarify
In Magento you can create your own events wherever you need but in this case you can use checkout_cart_product_add_after event to update the quore address details.
So here is the code for the same
$quote = Mage::getSingleton('checkout/session')->getQuote();
$billingAddress = Mage::getModel('sales/quote_address')
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
->setCustomerId(('Your_Value_Here'))
->setCustomerAddressIpd(('Your_Value_Here'))
->setCustomer_address_id(('Your_Value_Here'))
->setPrefix(('Your_Value_Here'))
->setFirstname(('Your_Value_Here'))
->setMiddlename(('Your_Value_Here'))
->setLastname(('Your_Value_Here'))
->setSuffix(('Your_Value_Here'))
->setCompany(('Your_Value_Here'))
->setStreet(('Your_Value_Here'))
->setCity(('Your_Value_Here'))
->setCountry_id(('Your_Value_Here'))
->setRegion(('Your_Value_Here'))
->setRegion_id(('Your_Value_Here'))
->setPostcode(('Your_Value_Here'))
->setTelephone(('Your_Value_Here'))
->setFax(('Your_Value_Here'));
$quote->setBillingAddress($billingAddress);
$shippingAddress = Mage::getModel('sales/quote_address')
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
->setCustomerId(('Your_Value_Here'))
->setCustomerAddressId(('Your_Value_Here'))
->setCustomer_address_id(('Your_Value_Here'))
->setPrefix(('Your_Value_Here'))
->setFirstname(('Your_Value_Here'))
->setMiddlename(('Your_Value_Here'))
->setLastname(('Your_Value_Here'))
->setSuffix(('Your_Value_Here'))
->setCompany(('Your_Value_Here'))
->setStreet(('Your_Value_Here'))
->setCity(('Your_Value_Here'))
->setCountry_id(('Your_Value_Here'))
->setRegion(('Your_Value_Here'))
->setRegion_id(('Your_Value_Here'))
->setPostcode(('Your_Value_Here'))
->setTelephone(('Your_Value_Here'))
->setFax(('Your_Value_Here'));
$quote->setShippingAddress($shippingAddress)
->setShipping_method('flatrate_flatrate')
->setShippingDescription($this->getCarrierName('flatrate'));
$quote->save();
I'm trying to get the tax rate (percentage, not currency) for a given postcode so I can display it in a third-party quote PDF printout (no relation to the "quote" Magento uses as the shopping cart pre-checkout). While I'm still relatively new to Magento it appears that getRateRequest() and getRate() are the two main functions which get the tax rate based on all the variables (product tax class, customer tax class, etc.).
Since this is for a third-party extension and all our products are taxable I figured I would just use getRate() with the correct Varien Object input and it would return the tax rate. After a week of trial and error I can't figure out why I'm always getting a rate of zero. I've confirmed I'm calling the getRate() function and that it's not returning zero from the first if() statement checking for Country and Customer/Product class ID. In addition I've confirmed all the variables are being passed on and accessible in the getRate() function itself.
I've created an object with the below input (based on the output of getRateRequest()) that I call with getRate() and am hoping someone can shed light on what is wrong with my data input or why the getRate() function is always returning a result of zero. (I'm actually setting with $variables below, they are just defined earlier up and one of my test case values are below)
// UPDATED CODE (variable values come from 3rd party quote extension)
$country = 'US'; // use short country code
$region = '12'; // must be numeric!
$postcode = '95050';
// our quote extension stores the customer id ('2') which we use to get the tax class
$customer = Mage::getModel('customer/customer')->load( '2' );
$custTax = $customer->getTaxClassId();
$TaxRequest = new Varien_Object();
$TaxRequest->setCountryId( $country );
$TaxRequest->setRegionId( $region );
$TaxRequest->setPostcode( $postcode );
$TaxRequest->setStore( Mage::app()->getStore() );
$TaxRequest->setCustomerClassId( $custTax );
$TaxRequest->setProductClassId(2); // 2=taxable id (all our products are taxable)
$taxCalculationModel = Mage::getSingleton('tax/calculation');
$rate = $taxCalculationModel->getRate($TaxRequest);
My backup plan is to just do a direct SQL lookup formula although that will probably get a bit messy. Since our web development team didn't exactly follow good coding standards an eventual site re-write is in my future anyway once the initial launch fixes are in (all 4 pages of them).
Thanks for any help and taking the time to read this.
EDIT - Stack Overflow is awesome :)
You can also try this
$store = Mage::app()->getStore('default');
$request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store);
$taxclassid = $product->getData('tax_class_id');
$percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));
If you change:
$TaxRequest->setRegionId(California);
to
$TaxRequest->setRegionId($stateId);
where $stateId is numeric region id. Your code should work then.