Magento Themes and Magento Extensions

RUN MAGENTO CODE EXTERNALLY

Share
Posted on April 28th, 2013 | Posted by admin

If you’re working with Magento often you’ll find sometimes you need to use Magento functions and classes outside of the Magento platform. This can be easily achieved with the following lines of code.

<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
// Now you can run ANY Magento code you want
// Change 12 to the ID of the product you want to load
$_product = Mage::getModel('catalog/product')->load(12);
echo $_product->getName();

This was only a quick post but hopefully it will be useful to someone.

Creating Customer Using Magento API

Share
Posted on April 26th, 2013 | Posted by admin

You can able to create a customer using magento API.Here the following code will create a customer in magento.

$client = new SoapClient(‘http://192.168.1.190/magento/index.php/api/soap/?wsdl’);
$session = $client->login(‘xxxx’,'yyyy’);
$customerInfo = array(
‘firstname’ => ‘Anish’,
‘lastname’ => ‘Kumar’,
‘email’ => ‘anish@example.com’,
‘password_hash’ => md5(‘password’),
‘store_id’ => 0,
‘website_id’ => 0
);
$newCustomerId = $client->call($session, ‘customer.create’,
array($customerInfo));
$client->endSession($session);
?>
Check it out in magento(customers->Manage Customers).You will see a customer that you created.

Direct SQL queries in Magento

Share
Posted on April 15th, 2013 | Posted by admin

Magento and the Zend Framework that it is built upon offer a complete abstraction of data access, which allows you to get on with the creation of higher-level logic without worrying about database access. However, sometimes you just want to be able to run a few key SQL queries directly and bypass the abstraction. This post details the most direct method of doing so in Magento.

$conn = Mage::getSingleton('core/resource')->getConnection('core_read');

This will return a Varien_Db_Adapter_Pdo_Mysql object, a subclass of Zend_Db_Adapter_Abstract, which will allow you to run the Zend adapter methods directly. For example:

// Prints a list of all website names
$results = $conn->fetchAll("SELECT * FROM core_website;");
foreach($results as $row) {
    echo $row['name'] . "\n";
}

Create the checkout_cart_product_add_before observer in Magento

Share
Posted on April 14th, 2013 | Posted by admin

For some reason no one can explain, it appears that the event observer checkout_cart_product_add_before never existed in Magento (even though checkout_cart_product_add_after does). Say what?!??

Anyways, it’s fairly easy to go ahead and dispatch this event. Just add this to your module’s config.xml to rewrite the checkout/cart model:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0"?>
<config>
...
<global>
...
<models>
<checkout>
<rewrite>
<cart>Foo_Bar_Model_Checkout_Cart</cart>
</rewrite>
</checkout>
</models>
...
</global>
...
</config>

Then create your model that adds in the dispatch event to trigger the observers:

How to add Wishlist in Magento toplinks menu for only logged in user

Share
Posted on April 9th, 2013 | Posted by admin

Here is the simple method to add wishlist only for loggedin user in magento.
just go to your layout page that is app/design/frontend/PACKAGE7THEME/layout/local.xml and add following code

<customer_logged_in>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>100</position></action>
<action method="addLink" translate="label title" module="wishlist"><label>My Wishlist</label><path>wishlist</path><title>My Wishlist</title><prepare>true</prepare><urlParams/><position>110</position></action>
</reference>
</customer_logged_in>
<customer_logged_out>
<reference name="top.links">
<remove name="wishlist_link"/>
</reference>
</customer_logged_out>
Page 10 of 76« First...«89101112»203040...Last »