$session= Mage::getSingleton('checkout/session');
$quote = $session->getQuote();
$cart = Mage::getModel('checkout/cart');
$cartItems = $cart->getItems();
foreach ($cartItems as $item)
{
$quote->removeItem($item->getId())->save();
}
Search This Blog
Tuesday, September 20, 2011
Wednesday, August 24, 2011
Magento display gift message in front end
$message = Mage::getModel('giftmessage/message');
/* Add Gift Message*/
$gift_message_id = $order->getOrder()->getGiftMessageId();
if(!is_null($gift_message_id)) {
$message->load((int)$gift_message_id);
$gift_sender = $message->getData('sender');
$gift_recipient = $message->getData('recipient');
echo $gift_message = $message->getData('message');
}
http://www.magentocommerce.com/boards/viewthread/11346/
/* Add Gift Message*/
$gift_message_id = $order->getOrder()->getGiftMessageId();
if(!is_null($gift_message_id)) {
$message->load((int)$gift_message_id);
$gift_sender = $message->getData('sender');
$gift_recipient = $message->getData('recipient');
echo $gift_message = $message->getData('message');
}
http://www.magentocommerce.com/boards/viewthread/11346/
Friday, August 12, 2011
best php export to csv without space or comma
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// DB Connection here
$db = mysql_select_db("test",$con);
$result = mysql_query("SELECT * FROM test1");
csvToExcelDownloadFromResult($result);
function csvToExcelDownloadFromResult($result, $showColumnHeaders = true, $asFilename = 'data.csv') {
setExcelContentType();
setDownloadAsHeader($asFilename);
return csvFileFromResult('php://output', $result, $showColumnHeaders);
}
function csvFileFromResult($filename, $result, $showColumnHeaders = true) {
$fp = fopen($filename, 'w');
$rc = csvFromResult($fp, $result, $showColumnHeaders);
fclose($fp);
return $rc;
}
function setExcelContentType() {
if(headers_sent())
return false;
header('Content-type: application/vnd.ms-excel');
return true;
}
function setDownloadAsHeader($filename) {
if(headers_sent())
return false;
header('Content-disposition: attachment; filename=' . $filename);
return true;
}
function csvFromResult($stream, $result, $showColumnHeaders = true) {
if($showColumnHeaders) {
$columnHeaders = array();
$nfields = mysql_num_fields($result);
for($i = 0; $i < $nfields; $i++) { $field = mysql_fetch_field($result, $i); $columnHeaders[] = $field->name;
}
fputcsv($stream, $columnHeaders);
}
$nrows = 0;
while($row = mysql_fetch_row($result)) {
fputcsv($stream, $row);
$nrows++;
}
return $nrows;
}
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// DB Connection here
$db = mysql_select_db("test",$con);
$result = mysql_query("SELECT * FROM test1");
csvToExcelDownloadFromResult($result);
function csvToExcelDownloadFromResult($result, $showColumnHeaders = true, $asFilename = 'data.csv') {
setExcelContentType();
setDownloadAsHeader($asFilename);
return csvFileFromResult('php://output', $result, $showColumnHeaders);
}
function csvFileFromResult($filename, $result, $showColumnHeaders = true) {
$fp = fopen($filename, 'w');
$rc = csvFromResult($fp, $result, $showColumnHeaders);
fclose($fp);
return $rc;
}
function setExcelContentType() {
if(headers_sent())
return false;
header('Content-type: application/vnd.ms-excel');
return true;
}
function setDownloadAsHeader($filename) {
if(headers_sent())
return false;
header('Content-disposition: attachment; filename=' . $filename);
return true;
}
function csvFromResult($stream, $result, $showColumnHeaders = true) {
if($showColumnHeaders) {
$columnHeaders = array();
$nfields = mysql_num_fields($result);
for($i = 0; $i < $nfields; $i++) { $field = mysql_fetch_field($result, $i); $columnHeaders[] = $field->name;
}
fputcsv($stream, $columnHeaders);
}
$nrows = 0;
while($row = mysql_fetch_row($result)) {
fputcsv($stream, $row);
$nrows++;
}
return $nrows;
}
Monday, July 25, 2011
Using php to display visitor / user information such as their IP address
$ip = $_SERVER['REMOTE_ADDR'];
$hostaddress = gethostbyaddr($ip);
$browser = $_SERVER['HTTP_USER_AGENT'];
$referred = $_SERVER['HTTP_REFERER']; // a quirky spelling mistake that stuck in php
print "Display IP address:
\n";
print "$ip
\n";
print "More detailed host address:
\n";
print "$hostaddress
\n";
print "Display browser info:
\n";
print "$browser
\n";
print "Where you came from (if you clicked on a link to get here:
\n";
if ($referred == "") {
print "Page was directly requested";
}
else {
print "$referred";
}
$hostaddress = gethostbyaddr($ip);
$browser = $_SERVER['HTTP_USER_AGENT'];
$referred = $_SERVER['HTTP_REFERER']; // a quirky spelling mistake that stuck in php
print "Display IP address:
\n";
print "$ip
\n";
print "More detailed host address:
\n";
print "$hostaddress
\n";
print "Display browser info:
\n";
print "$browser
\n";
print "Where you came from (if you clicked on a link to get here:
\n";
if ($referred == "") {
print "Page was directly requested";
}
else {
print "$referred";
}
magento how to use distinct or get unique records from collection
magento how to use distinct or get unique records from collection
$collection = Mage::getModel('catalog/product')->getCollection()
->distinct(true)
->addAttributeToSelect('color')
->load();
$collection = Mage::getModel('catalog/product')->getCollection()
->distinct(true)
->addAttributeToSelect('color')
->load();
Sunday, July 17, 2011
Magento send mails like contact us form or forms or how to send mails in magento
if(!empty($post)) { $translate = Mage::getSingleton('core/translate');
$translate->setTranslateInline(false); try { $name = $_POST['name'];
$email = $_POST['email']; $to_admin =
Mage::getStoreConfig('trans_email/ident_general/email'); $name_admin =
Mage::getStoreConfig('trans_email/ident_general/name'); $subject =
'Contact Us'; /*$vars = array('Name'=>$name, 'Email Id' =>$email ); */
//const EMAIL_TEMPLATE_XML_PATH = 'customer/testemail/email_template';
//$templateId = Mage::getStoreConfig(EMAIL_TEMPLATE_XML_PATH);
$templateId=1; $sender = array('name' => $name,'email' => $email);
$translate=Mage::getModel('core/email_template')
->setTemplateSubject($subject) ->sendTransactional($templateId, $sender,
$to_admin, $name_admin, array('data' => $vars));
$translate->setTranslateInline(true);
Mage::getSingleton('core/session')->addSuccess(Mage::helper('customer')->__('Data
Sent Successfully')); $url = Mage::getUrl().'thanks';
Mage::app()->getFrontController()->getResponse()->setRedirect($url); }
catch (Exception $e) {
Mage::getSingleton('core/session')->addError(Mage::helper('customer')->__('Unable
to send email.')); $url = Mage::getUrl().'contactus';
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
return; } }
$translate->setTranslateInline(false); try { $name = $_POST['name'];
$email = $_POST['email']; $to_admin =
Mage::getStoreConfig('trans_email/ident_general/email'); $name_admin =
Mage::getStoreConfig('trans_email/ident_general/name'); $subject =
'Contact Us'; /*$vars = array('Name'=>$name, 'Email Id' =>$email ); */
//const EMAIL_TEMPLATE_XML_PATH = 'customer/testemail/email_template';
//$templateId = Mage::getStoreConfig(EMAIL_TEMPLATE_XML_PATH);
$templateId=1; $sender = array('name' => $name,'email' => $email);
$translate=Mage::getModel('core/email_template')
->setTemplateSubject($subject) ->sendTransactional($templateId, $sender,
$to_admin, $name_admin, array('data' => $vars));
$translate->setTranslateInline(true);
Mage::getSingleton('core/session')->addSuccess(Mage::helper('customer')->__('Data
Sent Successfully')); $url = Mage::getUrl().'thanks';
Mage::app()->getFrontController()->getResponse()->setRedirect($url); }
catch (Exception $e) {
Mage::getSingleton('core/session')->addError(Mage::helper('customer')->__('Unable
to send email.')); $url = Mage::getUrl().'contactus';
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
return; } }
Friday, July 15, 2011
admin store email magento general contacts email or Magento: Store Mail Addresses
//General contact
Mage::getStoreConfig('trans_email/ident_gerneral/name');
Mage::getStoreConfig('trans_email/ident_gerneral/email');
//Sales Representative
Mage::getStoreConfig('trans_email/ident_sales/name');
Mage::getStoreConfig('trans_email/ident_sales/email');
//Customer Support
Mage::getStoreConfig('trans_email/ident_support/name');
Mage::getStoreConfig('trans_email/ident_support/email');
//Custom email1
Mage::getStoreConfig('trans_email/ident_custom1/name');
Mage::getStoreConfig('trans_email/ident_custom1/email');
//Custom email2
Mage::getStoreConfig('trans_email/ident_custom2/name');
Mage::getStoreConfig('trans_email/ident_custom2/email');
Mage::getStoreConfig('trans_email/ident_gerneral/name');
Mage::getStoreConfig('trans_email/ident_gerneral/email');
//Sales Representative
Mage::getStoreConfig('trans_email/ident_sales/name');
Mage::getStoreConfig('trans_email/ident_sales/email');
//Customer Support
Mage::getStoreConfig('trans_email/ident_support/name');
Mage::getStoreConfig('trans_email/ident_support/email');
//Custom email1
Mage::getStoreConfig('trans_email/ident_custom1/name');
Mage::getStoreConfig('trans_email/ident_custom1/email');
//Custom email2
Mage::getStoreConfig('trans_email/ident_custom2/name');
Mage::getStoreConfig('trans_email/ident_custom2/email');
Subscribe to:
Posts (Atom)