WePay Payment integration in cakephp -Crowd funding
How to implement WePay payment in CakePHP?
Here is an idea that how to implement the WePay in cakePHP less than 10 mins!
Follow the given steps to implement WePay on your cakePHP app.
Adding cusom options automatically to magento products
Hello friends in this post i’m going to give you a nice code to add custom options to your product when it is saved. After searching long time got good resources with that i have created an event to add custom options.
Magento having lot of feature to customize the product
We can add different prices to a single product using custom options.
Adding custom option for a product is easy, but if you want to add same custom option for every product that you are creating will take more time.
So here i have written an observer to add custom options to product when it is created at first time.
Below code will add two color variation custom option for your product when it is created.
Add the below code in your module config.xml. If you want to know hoe to create module refer Magento event module creation post
<global> <event> <catalog_product_save_after><!--Event name--> <observers> <Company_Myproducts_Model_Addcustomoptions_Observer><!--Unique identifier name--> <type>singleton</type> <class>Company_Myproducts_Model_Addcustomoptions_Observer</class><!--Observer Class name--> <method>add_custom_options</method><!--Observer Class method name--> </Company_Myproducts_Model_Addcustomoptions_Observer> </observers> </catalog_product_save_after> </event> </global>
Create a file in app/code/local/Company/Myproducts/Model/Addcustomoptions/Observer.php and copy/paste below code on it
<?php
class Company_Myproducts_Model_Addcustomoptions_Observer extends Mage_Core_Helper_Abstract{
public function add_custom_options(Varien_Event_Observer $observer){
$event = $observer->getEvent();
$product = $event->getProduct();
$arrayOption = array();
//For Creating dropdown,select,multiselect,radio type of custom option
$arrayOption[] = $this->setCustomOption("Red,Blue", "Color variations", "drop_down");
//For Creating textfield and textarea type of custom option
//$arrayOption[] = $this->setCustomOption("Anyvalue", "Area", "area", true);
//Loading the product that is newly created
$product = Mage::getModel("catalog/product")->load($product->getId());
if(count($product->getOptions()) == 0){
foreach ($arrayOption as $options) {
foreach ($options as $option) {
$opt = Mage::getModel('catalog/product_option');
$opt->setProduct($product);
$opt->addOption($option);
$opt->saveOptions();
}
}
//Enabling created options to show in backend as well as frontend.
$resource = Mage::getSingleton('core/resource');
$tableName = $resource->getTableName('catalog_product_entity');
$sql = "UPDATE $tableName SET has_options = '1' WHERE entity_id =".$product->getId();
$writeConnection = $resource->getConnection('core_write')->query($sql);
}
}
/**
* @param $value - Must be comma separated options.
* @param $title - Title of the custom option.
* @param $type - Type of custom option - drop_down,radio,checkbox,multiple,area,field.
* @param $noOption - Specifies if the custom options has options or not.
*/
protected function setCustomOption($value, $title, $type, $noOption = false)
{
$custom_options = array();
if ($type && $value != "" && $value) {
$values = explode(',', $value);
if (count($values)) {
/**If the custom option has options*/
if (! $noOption) {
$is_required = 0;
$sort_order = 0;
$custom_options[] = array(
'is_delete' => 0 ,
'title' => $title ,
'previous_group' => '' ,
'previous_type' => '' ,
'type' => $type ,
'is_require' => $is_required ,
'sort_order' => $sort_order ,
'values' => array()
);
foreach ($values as $v) {
$titleopt = ucfirst(trim($v));
switch ($type) {
case 'drop_down':
case 'radio':
case 'checkbox':
case 'multiple':
default:
$title = ucfirst(trim($v));
$custom_options[count($custom_options) - 1]['values'][] = array(
'is_delete' => 0 , 'title' => $titleopt , 'option_type_id' => - 1 , 'price_type' => 'fixed' , 'price' => '' , 'sku' => '' , 'sort_order' => ''
);
break;
}
}
return $custom_options;
}
/**If the custom option doesn't have options | Case: area and field*/
else {
$is_required = 0;
$sort_order = '';
$custom_options[] = array(
"is_delete" => 0 , "title" => $title , "previous_group" => "text" , "price_type" => 'fixed' , "price" => '' , "type" => $type , "is_required" => $is_required
);
return $custom_options;
}
}
}
return false;
}
}?>
Want to know more please refer this link Adding custom options in magento product.
Convert long url to short url using tinyurl api
Tinyurl provides us a short and simple service to convert long URL to small(tiny) URL. We can send email without link breakage.
Here is the tinyurl api to get shorten url. You can use any of the method.
Method 1:
Use file_get_contents to fetch tinyurl.
echo file_get_contents('http://tinyurl.com/api-create.php?url=http://www.websnippetz.com');
file_get_contents is not working? If your are able to access php.ini file set allow_url_fopen = On or you can use the below method.
Method 2:
Use cURL(runs faster than file_get_contents) to fetch tinyurl.
function get_tiny_url($url) {
$url = "http://tinyurl.com/api-create.php?url={$url}";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo get_tiny_url('http://www.websnippetz.com');
Modify item price in cart after placing order using sales_quote_add_item
We can easily modify product price after placing order in magento using the event sales_quote_add_item.
We can see this hook registered in app/code/core/Mage/Sales/Model/Quote.php line:874. This is the event created by magento.
Mage::dispatchEvent(‘sales_quote_add_item’, array(‘quote_item’ => $item));
We can access $item values using its registered event name sales_quote_add_item and we can modify the price with our logic.
Follow the steps:
- Create a new module. Register our module in magento.
Create a file in app/etc/modules/Company_All.xml<?xml version="1.0"?> <config> <modules> <Company_Product> <codePool>local</codePool> <active>true</active> </Company_Product> </modules> </config> - Create configuration file for our module file in app/code/local/Company/Product/etc/config.xml
<?xml version="1.0"?> <config> <global> <models> <product> <class>Company_Product_Model</class> </product> </models> <events> <sales_quote_add_item><!--Event to override price after adding product to cart--> <observers> <company_product_price_observer><!--Any unique identifier name --> <type>singleton</type> <class>Company_Product_Model_Price_Observer</class><!--Our observer class name--> <method>update_book_price</method><!--Method to be called from our observer class--> </company_product_price_observer> </observers> </sales_quote_add_item> </events> </global> </config> - Create our observer file in app/code/local/Company/Product/Model/Price/Observer.php
class Company_Product_Model_Price_Observer{ public function update_book_price(Varien_Event_Observer $observer) { $quote_item = $observer->getQuoteItem(); //if(){ //your logic goes here $customprice = 50; //} $quote_item->setOriginalCustomPrice($customprice); $quote_item->save(); return $this; } }
Is this post helpful? Share your comments
Send email from xampp localhost
Send email from xampp localhost. Follow the easy steps
- Goto http://glob.com.au/sendmail/, download latest sendmail package.
- Extract the zip file and copy the files into your \xampp\sendmail folder(Replace every file in the existing folder).
-
Update the sendmail.ini file in sendmail folder with the following details, and make sure it is not commented(;).
smtp_server=smtp.gmail.com smtp_port=25 error_logfile=error.log debug_logfile=debug.log auth_username=yourname@gmail.com auth_password=gmailpassword force_sender=yourname@gmail.com
Here i have added gmail account for sending emails.
-
Open xampp\php\php.ini file find sendmail_path and update its value to
"\"C:\xampp\sendmail\sendmail.exe\" -t". Now it will look like belowsendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Make sure it’s not commented(;)
- Restart your apache server.
Now you can send email from xampp localhost! enjoy
Unzip file in server using PHP ZipArchive
Once i wanted to upload WordPress folder which contains 1000′s of files, if i choose to upload those files using FTP it will take much time.








