Magento Development and Coding
Magento 'Shop by
Brand' in SideBar:
First, create a template file, label it productbrand.phtml
then keep it in catalog/product folder after which you can copy the code in it
given below, also paste it in your productbrand.phtml. Make use of the product
brand and include it in the database, which needs a label of all the brands you
are interested to include and use it to make a comprehensive working out with
brands mentioned of all items.
<div>
<div>
<h4>
<span>Product Brands</span></h4>
</div>
<div style="padding-left:8px;">
<?php
$product = Mage::getModel('catalog/product');
$attributes =
Mage::getResourceModel('eav/entity_attribute_collection')->setEntityTypeFilter($product->getResource()->getTypeId())->addFieldToFilter('attribute_code',
'manufacturer');
$attribute =
$attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);
?>
<ul id="manufacturer_list"><?php foreach
($manufacturers as $manufacturer): ?>
<li><a
href="http://www.yourdomain.com/catalogsearch/advanced/result/?manufacturer[]=<?php
echo $manufacturer['value'] ?>"><?php echo $manufacturer['label']
?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<div>
</div>
</div>
Create Customer By
Code In Magento:
Creating customer programmatically is simple just use your
code below.
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
//$customer = new Mage_Customer_Model_Customer();
$customer = Mage::getModel("customer/customer");
$customer->website_id = $websiteId;
$customer->setStore($store);
$customer->firstname = "vikram";
$customer->lastname = "singh";
$customer->email = "singh@yourdomain.com";
$customer->password_hash = md5("password");
$customer->save();
Change Admin URL in
Magento:
It is easy to change admin URL in Magneto, open local.xml at
this location below, /app/etc/local.xml now search the code below replacing
'admin' with your desired name. As you do, your admin URL changed to adminarea
is a correction.
Magento Code Method
Send Every Store
Activity Email to Store Owner in Magento:
We can do this by editiing Templete.php file at the location
given below app\code\core\Mage\Core\Model\Email Search for your code:
$this->setSentSuccess($this->send($email, $name,
$vars));
In addition, just below this looked out code paste the code
given.
$this->setSentSuccess($this->send('owner@store.com',
$name, $vars));
Now every email that shoots from Magento store delivers to the
owner also.
Get Customer GroupId
in Magento:
Firstly, you need to check if your customer logs in or not:
$logged_in = Mage::getSingleton( 'customer/session'
)->isLoggedIn();
Now use the code below to check CustomerGroupID
$group = Mage::getSingleton('customer/session')->getCustomerGroupId();
Labels: How can I get
the CostumerGroupid?
Magento Custom Form with
Notification:
Step1: you need to make an XML file same at the location shown
below, if the folder does not exist please create it /app/etc/modules/MageWorks_Contact.xml
and paste its content below in MageWorks_Contact.xml
Step 2: Now create Confix.xml at this location below
app/code/local/MageWorks/Contact/etc/config.xml, paste the content below to the
config.xml file
Step 3: Now create controller at the following location app/code/local/MageWorks/Contact/controllers/IndexController.php
Now paste all content shown next to the controller:
class MageWorks_Contact_IndexController extends
Mage_Core_Controller_Front_Action
{
public function indexAction()
{
//Get current
layout state
$this->loadLayout();
$block =
$this->getLayout()->createBlock(
'Mage_Core_Block_Template',
'mageworks.contact',
array(
'template' => 'mageworks/contact.phtml'
)
);
$this->getLayout()->getBlock('content')->append($block);
//$this->getLayout()->getBlock('right')->insert($block, 'catalog.compare.sidebar',
true);
$this->_initLayoutMessages('core/session');
$this->renderLayout();
}
public function
sendemailAction()
{
//Fetch
submited params
$params = $this->getRequest()->getParams();
$mail = new
Zend_Mail();
$mail->setBodyText($params['comment']);
$mail->setFrom($params['email'], $params['name']);
$mail->addTo('somebody_else@example.com', 'Some Recipient');
$mail->setSubject('Test MageWorks_Contact Module for Magento');
try {
$mail->send();
}
catch(Exception $ex) {
Mage::getSingleton('core/session')->addError('Unable to send email.
Sample of a custom notification error from MageWorks_Contact.');
}
//Redirect
back to index action of (this) mageworks-contact controller
$this->_redirect('mageworks-contact/');
}
}
Step 4: Create view app/design/frontend/default/default/template/mageworks/contact.phtml
Paste content below to the contact.phtml page:
MageWorks_Contact
module sample:
Coding Processes in Magento
Magento Display
Category BestSellers:
Category distinction and selection to choose the kind of
product you are intending to sell through the database assigned with an array
of different items displayed on it.
$curr_categoryid = Mage::registry('current_category')->getId();
$cat_Id= $curr_categoryid;
$category =
Mage::getModel('catalog/category')->load($cat_Id);
$products =
Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect('*')
->setOrder('ordered_qty', 'desc')
->addCategoryFilter($category);
Get Nicely Formated
Final Price in Magento:
Final price in proper format is shown and you can attain it using
the below code snippet if you want an evaluation of all prices of items to be
purchased through this Magento online e-commerce store.
$_coreHelper = $this->helper('core');
$_taxHelper = $this->helper(’tax’);
$_finalPriceInclTax = $_taxHelper->getPrice($_product,
$_product->getFinalPrice(), true);
$_finalPriceFormated =
$_coreHelper->currency($_finalPriceInclTax,true,false);
echo $_finalPriceFormated;
Labels: Formatted
Price Magento:
Magento Image
Switcher on MouseOver:
Step1. Open file on location given below app/design/frontend/default/default/template/catalog/product/view/media.phtml
Step2. Search the code in media.phtml file
<a href="#" onclick="popWin('<?php
echo $this->getGalleryUrl($_image) ?>', 'gallery',
'width=300,height=300,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes');
return false;">
<!--nested img
tag stays the same-->
</a>
Step 3. Replace searched code with code below.
<a href="<?php echo
$this->helper('catalog/image')->init($this->getProduct(), 'image',
$_image->getFile()); ?>" title="<?php echo
$_product->getName();?>" onmouseover="$('image').src =
this.href; return false;">
<!--nested img
tag stays the same-->
</a>
Comments
Post a Comment