How to fetch images from remote server using PHP

We were updating the products on a client website from a new supplier. The supplier provided a CSV file containing the list of products and related information however they did not provide any product images. After browsing their website I found that they had saved all of their product images by the SKU name of the product so this was not going to be difficult at all.

I first uploaded the products into the database and then set about writing the script which would allow me to fetch the product image from the remote server and save it onto our server. The following is the PHP code I wrote to perform the extraction of the images from the remote server.

//code to fetch the SKU code from the database
//loop starts here

$strContents = file_get_contents(<Image URL on the supplier website>);
$fobj = file(“images/”.<SKU code of the product>.”jpg”,”w+”);
fwrite($fobj,$strContents);
fclose($fobj);
$fobj = null;

//loop ends here

Of course the above code would require some changes in your server configuration to allow PHP to extract the image file from the remote server.

Comments? Let me know please.

How to display address details of the customer in Zencart entered on PayPal

The following applies to customers who are using Zencart with PayPal IPN payment module. Customers have the option to change their address on PayPal after leaving the merchant website. When this happens and the customer enters an address which is not covered by the Seller Protection policy the merchant is in danger of facing chargeback in case the transaction turns out to be fraudulent.

To root out any such issues PayPal provides an option of PDT Payment Data Transfer. PDT is defined by PayPal as

Payment Data Transfer is a secure method to retrieve the details about a PayPal transaction so that you can display them to your customer.

To enable PDT:

1. Login to your PayPal account and click on Profile.
2. Click on Website Payment Preferences.
3. Enable Payment Data Transfer and copy the PDT token at the end of the page.

Copy the PDT token you see on the PayPal page and paste it into the Zencart PayPal IPN page as shown in the image below.

That’s it. Now PayPal IPN will send all customer information back to the merchant website. This option is already coded in the PayPal IPN module and it fetches the information and saves it into the “paypal” table in the database.

You can then reference the order_id in the “paypal” table and display the customer information in the admin panel. You can also check whether the address is confirmed or not under the address_status column.

Hope the above helped.

Why shipping address not being passed to PayPal using Zencart PayPal IPN

Zencart provides a number of payment modules by default. One of those is PayPal IPN (Instant Payment Notification) which you can enable from the Zencart admin panel. PayPal IPN works like PayPal Website Payments Standard with the added benefit that PayPal notifies the merchant website when the customer has successfully completed the transaction on the PayPal website. This allows the merchant to update relevant tables in the database in case the customer does not return to the merchant’s website.

By default, the Zencart PayPal IPN module does not pass the shipping address of the customer to the PayPal website. This does not affect the payment transaction of the customer but it does put the merchant in a vulnerable state. PayPal provides “Seller Protection” in case the shipping address of the customer is verified to be safe. If the shipping address is not passed over from the merchant website to PayPal then PayPal will not provide “Seller Protection” to the merchant in case the transaction is found out to be of fraudulent nature.

To enable passing of shipping address details from Zencart to PayPal please do the following steps.

1. Open the paypal.php in the includes/modules/payment folder of your Zencart website.
2. Once opened you will find the following line around line 238-239

'no_shipping' => MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED,

3. Change the above line to

'no_shipping' == 2,

4. Save the file.

That’s it. Now the shipping address will be passed over to PayPal website and hopefully this will have resolved the problem.

Let me know how it went 🙂

Why am I not able to view any images on my PHP website on FastCGI?

Most probably you have .htaccess files in your subfolders which are there to restrict access to files and other resources in those subfolders. FastCGI based web servers sometimes do not serve pages properly in cases where the .htaccess files do not have Options entry in the AllowOverride apache directory configuration. A far simple resolution would be to disable the .htaccess but it’s not recommended at all.

If you are encountering this issue and would like the help of freelance web developer then I would be very happy to help you.

How to add reminder to Outlook from a web page

Have you ever felt the need of buying an item or service while surfing the internet? The answer to that would obviously be YES but maybe you felt that you would like to buy it at some other time due to some constraint like out of money, broke, waiting for special occasion etc. This happens to nearly everyone of us but the other thing that happens as well is that we tend to forget about the item and the event for which we had chosen not to buy in the first place and finally end up with nothing. Ahh! the human mind.

The above scenario happens to most customers while shopping online and this ends up as lost sales for the business owner which is a loss loss situation for all parties. So, how to get out of this situation? The best option for the business owner (in this case a website owner) is to setup a reminder link on his website which will allow the customer to create a reminder on Google, Yahoo, Bing or Outlook (the visitor may use anyone which he/she uses on a regular basis). We will be discussing Outlook here. For the others there is a lot of information on the web. I will discuss them too in due time.

Setting up a reminder on Outlook from a web page may sound complex but it’s really very simple. Just follow the steps below

1. Go to the ICalendar page and copy the code from there.

2. We will make some changes to the code that has been copied to tailor it according to our requirements. Following is the code

BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:Enter a unique id to represent this reminder
DTSTAMP;VALUE=DATE:20100826
DTSTART;VALUE=DATE:20100831  (the start date of the event)
DTEND;VALUE=DATE:20100831     (the end date of the event)
SUMMARY:Give the name of the reminder here
DESCRIPTION:Describe the reminder here. Mention the URL of the page as well
END:VEVENT
END:VCALENDAR

3. Copy the code into notepad and save it with .ics extension

If you double click the file it will open up Outlook and let you review the reminder text and make any sort of changes by which you would like to remember it by. Once saved, Outlook will remind you of the event.

You can also use a script to make the reminder text dynamic and therefore allow you to generate reminders for each product and service on your website.

Hope the above helps. If you need my help then do let me know and I will be more than happy to help you.

How to consume WSDL in PHP using NuSOAP

I recently got a requirement from a client for a facility to display products/categories prices in real time on his website. The client’s website was related to home interiors, blinds and curtains and as he was short on staff he wanted the website to fetch the products, images and prices without any human interference.

He signed up with a major blinds and curtains supplier in the UK to use their API on his website. The API provided information on products, product prices, product images and additional images etc. I had consumed WSDLs in ASP.NET countless times but this was the first time in PHP.

As expected it was not going to be a problem in PHP as well. NuSOAP is an open source package which allows us to consume WSDL online. I downloaded the package from SourceForge and went about my work. After unzipping the package I found that there are 2 folders within it the Lib folder and the Samples folder.

After going through a couple of files in the Samples folder I coded a script which would fetch all the active products in a category. I have not listed sample request data on purpose as it is confidential. I believe the following code would be enough for anyone who has just started.

<?php

// URL is the WSDL url where the request would be sent and received from
// $params is the array which would pass the request parameters to the URL
// SomeMethod is the name of the method where the parameters woule be passed

require_once('lib/nusoap.php');
$client = new soapclient(URL);
$params = array();  
$result = $client->SomeMethod($params);
print_r($result);

?>

Hope the above helped.

How to fetch categories from eBay using GetCategories method

While developing a module for Zencart where the user would be able to list his products on eBay using the Zencart admin panel the client requested that he wanted the list of categories on eBay available in the admin panel so he can list the products into the category he wishes. This would allow the client to set the eBay category against the product from the add/edit product page in the admin panel.

Fortunately eBay provides this facility in their SOAP API. They provide a method called GetCategories which will return the category related information to you. Each eBay site i.e. eBay USA, eBay UK has it’s own set of categories so you need to specify the location in your input to receive the related categories to that location.

GetCategories take an array as input. The array is made up of the following

Version
RequesterCredentials
CategorySiteID
DetailLevel

and returns an array of objects which contains the category information as

BestOfferEnabled
AutoPayEnabled
CategoryID
CategoryLevel
CategoryName
CategoryParentID

Here we are concerned with CategoryID and CategoryName. If you would like more information on the above you can view the information here.

If you would like to view the code for fetching the categories and saving it into the database then you can download the code from here

Hope the above helped.

How to update currency rates in OsCommerce store

A client of mine wanted to display product prices in US dollar, Canadian dollar, British pound and Australian dollar so that the customer could view prices in their own currencies. The default currency was set to Euro. Now anyone who has used Oscommerce or developed modules in it would know that this is quite a simple task and was not a lot of work. However the client wanted the currencies to be updated in real time.

I first browsed through the Oscommerce website add-on section and surely there were some good modules there for this purpose. However, after seeing some of the code which had been written in earlier versions of PHP I decided to write my own.

The rates were to be fetched from the European Central Bank website. The rates are updated on the website every couple of hours and people could use them to display the most recent rates to their customers. As the output was in XML I decided to use the SimpleXML object which allowed you to process the XML as an object in PHP.

The code fetches the currency rates and updates them in the currency table. You can even setup a cron job which can fetch the rates on a timely basis and update your database.

You can download the code from here

How to send emails in PHP using PHPMailer

We all know how to send out email using the mail() function in PHP. It asks for a few things like the recipient email address, subject, message text. Add to that the optional headers argument with which you can set the content type of the email, the sender email address, file attachments etc and you have a very nice and powerful function.

However limitations such as not being coder friendly and no support for SMTP authentication make it some what limited. Enter the PHPMailer.

PHPMailer is a PHP email transport class featuring file attachments, SMTP servers, CCs, BCCs, HTML messages, word wrap, etc. You can download it from here.

After downloading the files unzip it. I have downloaded PHPMailer_v5.1.zip for this purpose. After unzipping it you can use the class.phpmailer.php file in your code.

Please see following code snippet which uses PHPMailer to send out email in PHP

<?php
// Include the phpmailer class file
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
// SMTPAuth = true if using SMTP authentication otherwise set it to false
$mail->SMTPAuth = true;
// These 3 lines are not needed if SMTPAuth = false above
$mail->Host = "<mail_server_address>";
$mail->Username = "<authenticated_email_address>";
$mail->Password = "<authenticated_email_address_password>";  
// Set to true if sending HTML formatted email other wise set to false
$mail->IsHTML(false);
// The sender email address
$mail->From     = '<sender_email_address>';
// The sender name i.e. the one who is sending the email. This name will display on the email client of the recipient
$mail->FromName = '<sender_name>';
// The email subject
$mail->Subject  =  '<subject>';
// The email message body
$mail->Body     =  '<body_text>';
// The recipient email address
$mail->AddAddress('<recipient_email_address>', '');
if (!$mail->Send()) {
	// If there is an error then it prints out the error message here	
	echo $mail->ErrorInfo;
}
else {
        echo "Email sent successfully";
}
?>

Hope the above helped

How to integrate RBS World Pay with your website?

World Pay (or rather RBS World Pay now) is a well know online payment processing service provider. A lot of e-commerce websites use their services to provide their customers a secure way to make payment online for the goods/services they purchase.

RBS World Pay provide their own API for payment processing which store owners can integrate with their website and allow online payment transactions. Its quite easy to integrate with your website. You can embed the following piece of form code in your website and start accepting payments from your customers.

<form action="https://select.worldpay.com/wcc/purchase" method="post" name="form1">              	
<input type="hidden" name="instId" value="<your_installation_id_here>"> 
<input type="hidden" name="cartId" value="<shopping_cart_or_order_id_here>"> 
<input type="hidden" name="currency" value="<3_digit_currency_code_here>">
<input type="hidden" name="desc" value="<shopping_cart_items_here>">
<input type="hidden" name="testMode" value="100">
<input type="hidden" name="amount" value="<order_total_here>">
</form>

The above is basically a simple form code of passing the values of the customer shopping cart to World Pay. You can also add custom form fields which can be passed onto World Pay. The custom form fields are only useful in the case when you need some information to be returned from World Pay instead of storing them in cookies or session. The value of 100 against testMode denotes that the transaction is not live. If you need to set it live then you will have to set testMode to 0.

Once the above form is posted to World Pay and there is no problem with the data then the checkout process starts on World Pay website.

Hope the above helped.