Opencart Shipping Zip Code Check Before Order - php

I've an extension installed with opencart which helps customers to know whether their zip code is serviceable by logistics partner. But this is not mandatory. Still customers from these zip codes are ordering and it takes a lot of work for cancellation.
I found oc_zip_code table in mySQL is used. In the checkout page, customer enters Billing details and clicks continue button then Shipping details and continue button. On clicking this button, the system should check the entered zip code with the table and if there is a match it should continue else an error message should be displayed saying, "This zip code is non serviceable"
Or after entering shipping details, it should check automatically and give same error message or success.
Please help me to achieve this.

Shouldn't be too difficult to achieve but it requires understanding of OpenCart's controllers and models, some PHP knowledge and MySQL knowledge.
You need to extend your controller and model files.
In the controller/checkout/shipping_method.php I'd add a function named verifyZipCode($zipcode) and same function in the model files.
You'd then need to create a new table of valid zip codes in your database and have the controller call the model to query the database and return true or false if the zipcode exists.
Hope this helps!

Most payment modules have options to do this for you, for example Stripe is a very good module or PayMill - both have the option to select address and postcode checks before the order goes through.

Related

Customization for Payment Gateway in opencart

So I am trying to set up a site on my localhost. I have selected 2 payment gateways from admin end
Online Payment (Free Shipping)
Cash On Delivery(Free Shipping/Flat COD Charge INR 50 )
Now I have customized all the rules for them. I only need one more rule.
I wish to have a functionality wherein I can enter some pincode/postcode values (through admin panel or maybe in some array in a javascript file or directly into the database, does not matter) of locations where second method is available)
Whenever someone presses continue before confirming order, the checkout form is validated so as to check from the form data if the value entered in post code matches the data (from any of the above methods) and if yes, only then they can continue or I wish to show an error message that
Following payment gateway is not available in your location
If you give me a hint on how to proceed with this, perhaps, I might be able to take it further. I am a bit or a starter in opencart so not much idea about how to proceed. I have sound knowledge of PHP, JQuery and Javascript although. So any and all help will be appreciated.
There are a few different extensions that already exist to do what you want - allow you to restrict shipping methods by various criteria. This one is my personal favorite: http://www.opencart.com/index.php?route=extension/extension/info&extension_id=1614
I managed it with JQuery for the time being. Edited the submit function in the cart.tpl file in catalog->view->theme->ancart (theme name) ->cart folder.
Used a plugin called "Zipcode COD" to enter zipcodes. Edited the response JQuery to hide and show payment options.
Lots of hard coding but does the trick. I will post the code if someone needs.

add billing address field in magento

I need to add a one new billing address field
which should be shown in frontend and admin both also in packaging slip.
For this I have search on google and I found the below link
http://www.magentocommerce.com/wiki/5_-_modules_and_development/how_to_add_custom_field_in_billing_and_shipping_address_in_frontend_and_backend
I have exactly follow all the steps they have suggested ,
but the new field is not appeared in the admin at the customer address section.
I am using the magento1.7.02 version.
Please suggest me what could be the issue or the changes should be.
I have added fields in magento admin panel
using the steps given in the link, directly in the database.
http://excellencemagentoblog.com/magento-adding-custom-field-to-customer-address
Then insert a record and check.
For checkout page, add the field in the path
/app/design/frontend/base/default/template/persistent/checkout/onepage/billing.phtml
Then you have add the address format using the above url. Kindly let me know, if you have any clarification.

Get notified on stock unavailability

I am trying to create a "Notify me" feature if the stock is unavailable.
On search on admin panel, I could find only that a user should sign up / log in to get notified about the stock availability.
But I just want to let the user (a guest) enter only his/her email address to get notified.
How should I do this?
Please give suggestions..
EDIT:
I have got this link, which gives me a way to start.
Till now what I did is added the following code in my template file which is creating a url for redirect (thinking to do it in ajax way, to stop page refreshing).
<?php
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$base64 = strtr(base64_encode($actual_link), '+/=', '-_,');
$postUrl = "http://$_SERVER[HTTP_HOST]/efk/productalert/add/stock/product_id/" . $simpleProduct->getId() . "/uenc/". $base64;
?>
In the above code, efk is my project folder name.
After this, I have gone to productalert/add/stock controller method i.e stockAction() which is calling sign up / login form (I think so) using $model->save();.
How should I disable this save calling and add my own small overlay which holds a textbox to enter a email address?
Magento has "Notify me when product is back in stock" feature out of the box. It can be configured in admin panel: system / configuration / catalog / product alerts and product alerts run settings.
You're right, it works only for registred customers. To make it working for guest users some coding is required. I'd say you need to do the following steps:
Add email column to product_alert_stock table
Create new controller and action (believe me, it's better than you override existing one via config.xml) which extends Mage_ProductAlert_AddController::stockAction(). Your method will have to set guest's email to productalert/stock model.
Create subscription form and make sure it submits data to your new controller/action.
Update (override) Mage_ProductAlert_Model_Observer::_processStock() method to make it respect situations when "customer" has no ID but has email.
When you'll be testing, I suggest you to install SMTP Pro Email extension and mailcatcher to ease the testing process.
We have done this (http://www.alfresia.co.uk/sorrento-side-table.html/). Here we ended up creating a custom module as when we did this magento did not support any product alert system for the guest users (i do not know if this is supported now).
We first created a text box which would appear on product page where the product is out of stock. We were saving this info in one of our custom tables where we the schema was {id, email, product_sku, status} (status had three values Awaiting Stock, In Stock, and Already Notified).
We then wrote an observer which was hooked to cataloginventory_stock_item_save_after event, this helped us get the product sku which has been back in stock, and update all entries in our custom table with status In Stock and send a mail to the user.
This is how we did it, surely there will be a much cleaner way doing this.
You could have work with plugins. MagentoCommerce has loads of plugins/extensions which does the same
Free Version - http://www.magentocommerce.com/magento-connect/product-out-of-stock-subscription-1350.html
I too had similar requirement, and have installed 'http://www.magentocommerce.com/magento-connect/product-out-of-stock-subscription-1350.html' this plugin.
Well this plugin does the job, But they have override complete product view page template instead of simply adding a new block. By this your custom development on product view page development might get reflected on frontend.
Or else this plugin definitely does the job.
This http://www.magentocommerce.com/magento-connect/product-out-of-stock-subscription-1350.html plugin is really good but it breaks for configurable product types and it completely overrides the product controller which makes your system vulnerable to future upgrades. I think observers should be hooked to events where the product is back in stock and should update the users.

After Placing Order, Customer Does Not Redirect to “Order Placed Successfully” and is Returned to Cart

I have create a magento website, in this when we place order of an item then,
strong textAfter Placing Order, Customer Does Not Redirect to “Order Placed Successfully” and is Returned to Cart.
Order also gone in magento admin section under "Sales > order".
I have tried check/money order, authorize.net etc for order place but no positive results found,
under this they also not checked correct payment details for order in authorize.net.
It seems there is problem related with Payment method.
You can check this using other Payment method like Cash on Delivery etc.
Also please make sure you are entering correct information for Address like ZIP Code etc.
Can you list what extensions you have installed for your Magento install?
I've experienced this problem before when I had a custom module that observes the checkout event, when something has gone wrong with the code itself.
Chances are either one of your extensions or a custom built module that's listening to the checkout events is causing the problem.

Magento - How to set Payment Information in backend for a custom Payment module

I have created a custom Payment module but I could only display the following information in the admin side of Magento
Type of Card
Card Number : xxxx-last 4 digits
Order was placed using USD
But how can I get other details just liek in case pf Paypal like,
Card Validation Status:
Address Validation Status:
Last Transaction ID:
etc. I am getting all these response from my custom payment gateway but I don't know what function to call or how to display it in the back-end for the store owner to see.
Can any one help me with this? Right now my payment module is doing authorize_capture as the payment action so I have Model/PaymentMethod.php which has function capture(Varien Object payment, amount) to deal with the logic. So can I set the Payment Information from there or do I need to create any other files?
Please let me know.
EDIT: I found partial answer to what I need doing.
http://nicholas.piasecki.name/blog/2009/10/add-avs-and-cvn-to-magentos-admin-screen-in-just-637-easy-steps/#comment-1043
But I am not able to override a default admin template file. This link tells to create a Block file which overrides Mage/Payment/Block/Info and set a template in there to be used.
But its not reading it. Can some one tell me the correct way to override an admin template file so that future upgrades don't overwrite it.
I hope some one must be familiar with this bit now.
it isn't taking the code from my overriden module Block file. The template file I need to over ride is app/design/adminhtml/default/default/template/payment/default/info.phtml. Using the link mentioned I have already overridden Mage/Payment/Block/Info and wrote my own code but am not able to set and point towards my template. Any Ideas?
Here is a good article by Alan Storm which will show you how to add settings to the backend:
http://alanstorm.com/custom_magento_system_configuration

Categories