Monday, August 20, 2012
Add first/last name in newsletter module Magento
>> First add two fields ( subscriber_firstname, subscriber_lastname) in newsletter_subscriber table and app\design\frontend\THEME\default\template\newsletter\subscribe.phtml.
>> Now edit this page : app\code\core\Mage\Newsletter\controllers\SubscriberController.php
Here you'll find "public function newAction()"
Paste the below code after this following code:
$status = Mage::getModel('newsletter/subscriber')->subscribe($email); //line (63)
///////////////////////// First Name //////////////////////////////
if ($this->getRequest()->getPost('subscriber_firstname'))
{
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
$name = (string) $this->getRequest()->getPost('subscriber_firstname');
$subscriber->setSubscriberFirstname($name);
$subscriber->save();
}
////////////////////// END ///////////////////////////////////////
Do same for field Last Name....
>> The above code will effect your frontend. If you want to see the information from Admin too, you have to implement a little bit.
Go to this link : app\code\core\Mage\Adminhtml\Block\Newsletter\Subscriber\grid.php
Add this code :
//It will show the information to the admin on News Letter Subscriber Section.
$this->addColumn('subscriber_firstname', array(
'header' => Mage::helper('newsletter')->__('Subscriber First Name'),
'index' => 'subscriber_firstname',
'default' => '----'
));
*Note :- I would suggest to override the subscriber controller and admin blocks. In this post I've focused in the logic only and shown in 3 steps to understand you its very simple. But it's not good programming. You should follow the magento module structure. In my another post you'll see that how to override frontend and admin controllers.
*********** Good Luck **********
Magento:: how to get Review/Rating information
>> Get the review collection :
$reviews = Mage::getModel('review/review')->getResourceCollection();
$reviews->addStoreFilter( Mage::app()->getStore()->getId() )
->addStatusFilter( Mage_Review_Model_Review::STATUS_APPROVED )
->setDateOrder()
->addRateVotes()
->load();
>> Get the rating summary of a product:
$summaryData = Mage::getModel('review/review_summary')
->setStoreId($storeId)
->load($_product->getId());
foreach($summaryData as $s){
$percentage = $s[rating_summary];
$rev_count= $s[reviews_count];
break;
}
>> Get the rating collection :
$rating_collection = Mage::getModel('rating/rating')->getEntitySummary($_review->getEntityPkValue(),true);
$rating_count = $rating_collection->getData('count');
if (!empty($rating_count)) {
$rating_sum = $rating_collection->getData('sum') / $rating_count;
}
$reviews = Mage::getModel('review/review')->getResourceCollection();
$reviews->addStoreFilter( Mage::app()->getStore()->getId() )
->addStatusFilter( Mage_Review_Model_Review::STATUS_APPROVED )
->setDateOrder()
->addRateVotes()
->load();
>> Get the rating summary of a product:
$summaryData = Mage::getModel('review/review_summary')
->setStoreId($storeId)
->load($_product->getId());
foreach($summaryData as $s){
$percentage = $s[rating_summary];
$rev_count= $s[reviews_count];
break;
}
>> Get the rating collection :
$rating_collection = Mage::getModel('rating/rating')->getEntitySummary($_review->getEntityPkValue(),true);
$rating_count = $rating_collection->getData('count');
if (!empty($rating_count)) {
$rating_sum = $rating_collection->getData('sum') / $rating_count;
}
Friday, August 17, 2012
Magento:: get Admin user details.
>> Get admin information from admin page ::
$userArray = Mage::getSingleton('admin/session')->getData();
$user = Mage::getSingleton('admin/session');
$userId = $user->getUser()->getUserId();
$userEmail = $user->getUser()->getEmail();
$userFirstname = $user->getUser()->getFirstname();
$userLastname = $user->getUser()->getLastname();
$userUsername = $user->getUser()->getUsername();
$userPassword = $user->getUser()->getPassword();
>> Get admin information from frontend::
$getadmin=Mage::getModel('admin/user')->load(1);
$adminname=$getadmin->getName();
$adminemail=$getadmin->getEmail();
*********** Good Luck **********
Magento:: get store and website information
>> Get store data :
Mage::app()->getStore();
Store Id
Mage::app()->getStore()->getStoreId();
Store code
Mage::app()->getStore()->getCode();
Website Id
Mage::app()->getStore()->getWebsiteId();
Store Name
Mage::app()->getStore()->getName();
Is Active
Mage::app()->getStore()->getIsActive();
Store Home Url
Mage::app()->getStore()->getHomeUrl();
*********** Good Luck **********
Magento:: currency format
>> Get currency symbol :
Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
>> Change price format with currency symbol :
Mage::helper('core')->currency($price);
Magento:: how to move Email To Friend form in product page
>> Move email to friend form to product details page ::
1. Go to admin=>system=>configuration=>Email To Friend and change "Limit Sending By" cookie to IP.
And change "Allow for Guests" to Yes.
2. Add to catalog.xml layout (in content):
<block type="sendfriend/send" name="sendfriend.send" template="sendfriend/send.phtml" />
3. Add to view.phtml template page:
<?php echo $this->getChildHtml('sendfriend.send');?>
4. In Mage_Sendfriend_Block_Send block row159
replace the method :
public function getSendUrl()
{
return Mage::getUrl('*/*/sendmail', array(
'id' => $this->getProductId(),
'cat_id' => $this->getCategoryId()
));
}
with...
public function getSendUrl()
{
return Mage::getUrl('sendfriend/product/sendmail', array(
'id' => $this->getProductId(),
'cat_id' => $this->getCategoryId()
));
}
*********** Good Luck **********
get unique value from an array in php
>> Get unique value in an array::
$arra1 = array('12','15','18','17','12','18');
$cntArr = array_count_values($arra1);
$newArr = array();
echo "<pre>"; print_r($arra1); echo "</pre>";
echo "<pre>"; print_r($cntArr); echo "</pre>";
foreach($cntArr as $key => $val){
if ($val > 1){
array_push($newArr,$key);
}
}
echo "<pre>"; print_r($newArr); echo "</pre>";
*********** Good Luck **********
Subscribe to:
Comments (Atom)