Search This Blog

Friday, October 28, 2011

Free one click cart checkout community edition

Free one click cart checkout community edition

Magento 2.0
http://connect20.magentocommerce.com/community/GoldenSpiralStudio_OneClickCartCheckout
Magento 1.0
magento-community/GoldenSpiralStudio_OneClickCartCheckout

refrence
http://www.magentocommerce.com/magento-connect/GoldenSpiralStd/extension/6971/goldenspiralstudio_oneclickcartcheckout

Tuesday, October 18, 2011

magento create customer custom attribute throuogh sql or code

$installer = $this;

$installer->startSetup();

$connection = $installer->getConnection();

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$installer->removeAttribute('customer', 'name_goes_here');

$setup->addAttribute('customer', 'name_goes_here', array(
'input' => 'text',
'type' => 'varchar',
'label' => 'name_goes_here',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$installer->endSetup();

$installer->installEntities();

use this in mysql4-upgrade-0.1.0-0.1.1.php or any latest sql folder script

Tuesday, September 20, 2011

How to Remove Product from cart on checkout page or by coding in magento

$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();
}

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/

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;
}

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";
}

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();