Tuesday, 9 June 2015
Magento : Update cart price using the observer event
Hello Friends,
Using Observer,we have seen how to set the custome price, Check Here
Now, We are going for update the product with the custome price, because in magento, for the set any custome price, update custome price, there are different Observer Events which is help us for making proper customization.
A) Open Module Config.xml file which is located at etc directory of Module
[This module is same which we use for the Set Custome price]
B) Here, the code of observer event for update price
{Namespace}/{Module Name}/Model/Observer.php
D) In Observer.php add updatecustomprice function
Enjoy, This is work for me in Magento 1.7.0.2
Using Observer,we have seen how to set the custome price, Check Here
Now, We are going for update the product with the custome price, because in magento, for the set any custome price, update custome price, there are different Observer Events which is help us for making proper customization.
A) Open Module Config.xml file which is located at etc directory of Module
[This module is same which we use for the Set Custome price]
B) Here, the code of observer event for update price
Magento
<frontend>
...................
<events>
<checkout_cart_product_update_after> <!--Here Event Name as per your Requirement -->
<observers>
<{Namespace}_{Module Name}_Model_Observer>
<type>singleton</type>
<class>{Namespace}_{Module Name}__Model_Observer</class>
<method>updatecustomprice</method>
</{Namespace}_{Module Name}__Model_Observer>
</observers>
</checkout_cart_product_update_after>
</events>
.................
</frontend>
C) Now, Create or Update [if alreay you have] Observer.php in Model Directory...................
<events>
<checkout_cart_product_update_after> <!--Here Event Name as per your Requirement -->
<observers>
<{Namespace}_{Module Name}_Model_Observer>
<type>singleton</type>
<class>{Namespace}_{Module Name}__Model_Observer</class>
<method>updatecustomprice</method>
</{Namespace}_{Module Name}__Model_Observer>
</observers>
</checkout_cart_product_update_after>
</events>
.................
</frontend>
{Namespace}/{Module Name}/Model/Observer.php
D) In Observer.php add updatecustomprice function
Magento
class {Namespace}/{Module Name}_Model_Observer
{
public function updatecustomprice(Varien_Event_Observer $observer) {
$item = $observer->getQuoteItem();
$custom_vals = $_SESSION['custom_vals'];
if($custom_vals != '')
{
$additionalOptions = array(array(
'label' => '',
'value' => $custom_vals,
));
$item->addOption(array(
'code' => 'additional_options',
'value' => serialize($additionalOptions),
));
unset($_SESSION['custom_vals']);
}
$price = 123; //Here, set the Custom Price for Item
$item->setCustomPrice($price); // This set the Custom Price in Quote of cart
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);
}
}
E) Now, Clear all cache of site from admin{
public function updatecustomprice(Varien_Event_Observer $observer) {
$item = $observer->getQuoteItem();
$custom_vals = $_SESSION['custom_vals'];
if($custom_vals != '')
{
$additionalOptions = array(array(
'label' => '',
'value' => $custom_vals,
));
$item->addOption(array(
'code' => 'additional_options',
'value' => serialize($additionalOptions),
));
unset($_SESSION['custom_vals']);
}
$price = 123; //Here, set the Custom Price for Item
$item->setCustomPrice($price); // This set the Custom Price in Quote of cart
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);
}
}
Enjoy, This is work for me in Magento 1.7.0.2
Saturday, 6 June 2015
jQuery : Detect Mobile Device and identify company
jQuery
/*Detect device*/
function detectdevice()
{
/*This will return TRUE if its Mobile Device otherwise give False*/
return (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
}
console.log(detectdevice());
function detectdevice()
{
/*This will return TRUE if its Mobile Device otherwise give False*/
return (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
}
console.log(detectdevice());
jQuery : ID is exist or not !
jQuery
/*Check any ID exist or not*/
<div id='id1'></div>
<script type="text/javascript">
var id_exist = jQuery('#id1').length;
console.log(id_exist);
/*This will return 0 if ID not exist otherwise will get 1*/
</script>
<div id='id1'></div>
<script type="text/javascript">
var id_exist = jQuery('#id1').length;
console.log(id_exist);
/*This will return 0 if ID not exist otherwise will get 1*/
</script>
jQuery : Check radio button is checked or not
jQuery
/*Check Radio button is checked or not*/
<script type="text/javascript">
if(jQuery('#id1').is(':checked')==true)
{
/*Something Code*/
}
else
{
/*Something Code*/
}
</script>
<script type="text/javascript">
if(jQuery('#id1').is(':checked')==true)
{
/*Something Code*/
}
else
{
/*Something Code*/
}
</script>
jQuery : Remove or Delete value from the array
Hello Friends,
Here, Using jQuery remove the Value and index from the array !
/*Remove Values and index from Array*/
/*Array['Apple','Banana','Lemon']*/
I hope this will helpful to you !
Thanks
Here, Using jQuery remove the Value and index from the array !
/*Remove Values and index from Array*/
jQuery
var sample_array = new Array('Apple','Banana','Mango','Lemon');
var val = "Mango";
remove_item(sample_array,val);
var remove_item = function (arr, value) {
var b = '';
for (b in arr) {
if (arr[b] === value) {
arr.splice(b, 1);
break;
}
}
return arr;
}
/*Result will be*/var val = "Mango";
remove_item(sample_array,val);
var remove_item = function (arr, value) {
var b = '';
for (b in arr) {
if (arr[b] === value) {
arr.splice(b, 1);
break;
}
}
return arr;
}
/*Array['Apple','Banana','Lemon']*/
I hope this will helpful to you !
Thanks
jQuery : Check image exist or not on location
Hello Friends,
Sometimes we need to check, Is file is exist or not on particular location?
So, for this using below method we can check the file is exist or not !
Sometimes we need to check, Is file is exist or not on particular location?
So, for this using below method we can check the file is exist or not !
jQuery
<script type="text/javascript">
function imageExists(url, callback) {
var img = new Image();
img.onload = function() { callback(true); };
img.onerror = function() { callback(false); };
img.src = url;
}
function onload(id) /*This function will use while Mouseover event */
{
var imageUrl = "Image File URL";
imageExists(imageUrl, function(exists) {
if(exists==true){
/*Something Code here*/
}else{
/*Something Code here*/
}
});
}
</script>
function imageExists(url, callback) {
var img = new Image();
img.onload = function() { callback(true); };
img.onerror = function() { callback(false); };
img.src = url;
}
function onload(id) /*This function will use while Mouseover event */
{
var imageUrl = "Image File URL";
imageExists(imageUrl, function(exists) {
if(exists==true){
/*Something Code here*/
}else{
/*Something Code here*/
}
});
}
</script>
Subscribe to:
Posts (Atom)