Chapters Close

It’s tough when you’re dealing with Magento 1 custom grid view and you have to display EAV attribute data in grid. Right?

After tweaking the minds for hours, we at Aureate Labs would like to present a best and easy go solution that can work without a single error.

Let’s make it happen in a couple of minutes,

In a very short journey before we jump on actual code, make sure you’ve needed table structure same as displayed below:

First, create two tables related to the testimonial.
1.  testimonial table (parent table): stores All testimonial data.
2.  testimonial_product_customer (child table): stores Testimonial_id (FK), Product_id(FK), Customer_ID(FK) relational data.

Here is the detailed table structure with the required columns:

testimonial

  • Id (Primary key)
  • company_name
  • name
  • message
  • post
  • profile_pic
  • status
  • created_at
  • Updated_at

testimonial_product_customer

  • Id (Primary key)
  • testimonial_id (Foreign key – testimonial)
  • product_id (Foreign key – product)
  • customer_id (Foreign key – customer)

Now, all we need is to display these products and customers related data in testimonial grid without breaking any functionality of searching or sorting the data. And that can be easily done with the help of LEFT JOIN (EAV TABLES).

Coming to code, we have to update _prepareCollection() the method of testimonial grid block class (Grid.php) placed at  app/code/local/{Namespace}/Testimonials/Block/Adminhtml/Testimonials/

protected function _prepareCollection()
{
    $collection = Mage::getModel('testimonials/testimonial')
                 ->getCollection();
    $productsTableName = Mage::getSingleton('core/resource')
                 ->getTableName('catalog/product');
    $productCustomerTableName = Mage::getSingleton('core/resource')
                 ->getTableName('testimonials/testimonial_product_customer');
    $entityTypeId = Mage::getModel('eav/entity')
        ->setType('catalog_product')
        ->getTypeId();
    $entityCustTypeId = Mage::getModel('eav/entity')
        ->setType('customer')
        ->getTypeId();
    $prodNameAttrId = Mage::getModel('eav/entity_attribute')
        ->loadByCode($entityTypeId, 'name')
        ->getAttributeId();
    $custNameAttrId = Mage::getModel('eav/entity_attribute')
        ->loadByCode($entityCustTypeId, 'firstname')
        ->getAttributeId();
    $collection->getSelect()
        ->joinLeft(
            array('testproduct' => $productCustomerTableName),
            'main_table.id = testproduct.testimonial_id',
            array('product_id','testimonial_id','customer_id')
        )
        ->joinLeft(
            array('prod' => 'catalog_product_entity'),
            'prod.entity_id = testproduct.product_id',
            array('sku')
        )
        ->joinLeft(
            array('cpev' => 'catalog_product_entity_varchar'),
            'cpev.entity_id=prod.entity_id AND cpev.attribute_id='.$prodNameAttrId.'',
            array('cpev.value' => 'value')
        )
        ->joinLeft(
            array('ccev' => 'customer_entity_varchar'),
            'ccev.entity_id=testprodcust.customer_id AND ccev.attribute_id='.$custNameAttrId.'',
            array('ccev.value' => 'value')
        );
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

Next, to display product and customer-related columns in grid view,  add them to the method_prepareColumns as defined below.

protected function _prepareColumns()
{
    $this->addColumn('pro_name', array(
        'header'    => Mage::helper('testimonials')->__('Product'),
        'align'     =>'right',
        'index'     => 'cpev.value',
        'width'     => '50px',
    ));
    $this->addColumn('cust_name', array(
        'header'    =>Mage::helper('testimonials')->__('Customer'),
        'align'     =>'right',
        'index'     => 'ccev.value',
        'width'     => '50px',
    ));
    return parent::_prepareColumns();
}

That is all! Now you can check for the EAV attributes data displayed successfully in the custom grid. If you encountered any error, don’t hesitate to connect us by leaving the comment below. We will be glad to help you.

Happy coding 🙂

For any Magento project, the most exciting time is when you launch the Magento project live. But what I have noticed most of the times is that there are some unnecessary links present in my account section.

This is because Magento brings in some default links under my account on the right-hand section as you can see in the screenshot below.

Usually, some of the projects that I build doesn’t make use of any downloadable products, recurring profiles or any applications yet links like this are present in my account under this section.

Sometimes add a product to the wishlist option is not present at the front end but like you can see in the above screenshot “My Wishlist” link is still present in my account section.

Therefore I believe this may confuse the customer to a certain extent about the feature that is not present on the site.

The best practice is to verify and remove all these unnecessary links that are not required in my account section.

Here are the code snippets which will help you to remove Billing Agreements, Recurring Profiles and My Downloadable Products links from the account.

Billing Agreements: Copy this file app/design/frontend/base/default/layout/sales/billing_agreement.xml in your current theme and remove or comment out the following lines

<reference name="customer_account_navigation">
     <action method="addLink" translate="label">
          <name>billing_agreements</name>
          <path>sales/billing_agreement/</path>
          <label>Billing Agreements</label>
     </action>
</reference>

Recurring Profiles: Copy this file app/design/frontend/base/default/layout/sales/recurring_profile.xml in your current theme and remove or comment out the following lines

<reference name="customer_account_navigation">
     <action method="addLink" translate="label">
          <name>recurring_profiles</name>
          <path>sales/recurring_profile/</path>
          <label>Recurring Profiles</label>
     </action>
</reference>

My Downloadable Products: Copy this file app/design/frontend/base/default/layout/downloadable.xml in your current theme and remove or comment out the following lines

<reference name="customer_account_navigation">
     <action method="addLink" translate="label" module="downloadable"
          <name>downloadable_products</name
          <path>downloadable/customer/products</path>
          <label>My Downloadable Products</label>
     </action>
</reference>

In the end, it’s a good practice to remove all the unnecessary links from your account section and keep it nice and clean.

Cheers!

Magento forbids calling the Cron manually from the browser by default from htaccess if you are using Apache webserver.

## Deny access to cron.php
<Files cron.php>
############################################
## uncomment the lines below to enable cron access with base HTTP authorization
## http://httpd.apache.org/docs/2.2/howto/auth.html
##
## Warning: .htpasswd file should be placed somewhere not accessible from the web.
## This is so that folks cannot download the password file.
## For example, if your documents are served out of /usr/local/apache/htdocs
## you might want to put the password file(s) in /usr/local/apache/.
        #AuthName "Cron auth"
        #AuthUserFile ../.htpasswd
        #AuthType basic
        #Require valid-user
############################################
        Order allow,deny
        Deny from all
</Files>

To run Cron directly from the browser, we would have to update .htaccess file before calling the “yoursite.com/cron.php” URL from the browser.
For that, you need to comment out these two lines below:

#Order allow,deny
#Deny from all

What is important here is that if you don’t secure cron.php file using HTTP authorization, any user could potentially run Cron by requesting the “http://example.com/cron.php” URL to attack your Magento application.
From the security perspective, it’s very important to uncomment these lines after generating the .htpasswd file:

AuthName "Cron auth"
AuthUserFile ../.htpasswd
AuthType basic
Require valid-user

There are many online tools available to easily generate .htpasswd.

Just be sure about the path of the .htpasswd file. We can easily find the path of the .htpasswd file using the pwd command from the directory where the .htpasswd file is placed using the console.

It’s important to place the .htpasswd file somewhere that is not accessible from the web. This is so that folks cannot download the .htpasswd file.

Sometimes developer skips this HTTP authorization step which allows any third party to access the cron.php file directly from the URL.

Cheers!

In Magento, sometimes you may want to export specific tables for which you need to make use of command line.

To export full database, we make use of:
mysqldump --user=root --password= --host=localhost --compress --disable-keys --quick [db_name] > export.sql

In case you need to export specific tables, use the following command:
mysqldump --user=root --password= --host=localhost --compress --disable-keys --quick [db_name] [Space separated Table Names] > export.sql

salesrule
salesrule_coupon
salesrule_coupon_usage
salesrule_customer
salesrule_customer_group
salesrule_label
salesrule_product_attribute
salesrule_website

Let’s say if we want to export the following table named “salesrule”:

Then run the command below:
mysqldump --user=root --password= --host=localhost --compress --disable-keys --quick magento1937 salesrule salesrule_coupon salesrule_coupon_usage salesrule_customer salesrule_customer_group salesrule_label salesrule_product_attribute salesrule_website > export_salesrule_tables.sql

Hope this helps!

After Magento 1.9 edition and so, the order confirmation emails aren’t sent quickly. Instead, they are queued up to be sent with the Cron job operation. And with that update, let me put a question in front of you,

Why are order emails send through the queue, while Invoice emails are sent directly?

Here, it is a list of reasons behind sending the orders email using the queue:

To make the checkout/post-checkout process error-free: Generally, sending orders and emails in bulk will certainly affect website performance and you don’t want that because eCommerce website performance matters a lot..
To avoid website slowdown: It is benefited by the re-send functionality in case of any failure or interruption.
To resend, if not delivered: Organised and queued flow of orders emails can avoid uncomfortably while processing for checkout or even after it.

However, Order’s email can also be sent immediately, without queueing up.

Send order email immediately:

If  you like to send order email immediately you can consider overriding the Mage_Sales_Model_Order::queueNewOrderEmail()  method by changing the following lines:

/** @var $emailQueue Mage_Core_Model_Email_Queue */

$emailQueue = Mage::getModel('core/email_queue'); 

$emailQueue->setEntityId($this->getId())
->setEntityType(self::ENTITY)
->setEventType(self::EMAIL_EVENT_NAME_NEW_ORDER)
->setIsForceCheck(!$forceMode); 

$mailer->setQueue($emailQueue)->send();

To:

/** @var $emailQueue Mage_Core_Model_Email_Queue */

$mailer->send();

If you want to send invoices using a queue for smooth sending, then also it can be achieved by the solution presented below.

Send invoices using the queue:

The opposite solution is to let invoices use the queue:
You must override Mage_Sales_Model_Order_Invoice::sendEmail changing:

// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
$mailer->setStoreId($storeId); $mailer->setTemplateId($templateId);
$mailer->setTemplateParams(array(
	'order' => $order,
	'invoice' => $this,
	'comment' => $comment,
	'billing' => $order->getBillingAddress(),
	'payment_html' => $paymentBlockHtml
	)
);
$mailer->send();

To:

// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
$mailer->setStoreId($storeId);
$mailer->setTemplateId($templateId);
$mailer->setTemplateParams(array(
	'order' => $order,
	'invoice' => $this,
	'comment' => $comment,
	'billing' => $order->getBillingAddress(),
	'payment_html' => $paymentBlockHtml
	)
);
$emailQueue = Mage::getModel('core/email_queue');
$emailQueue->setEntityId($this->getId())
	->setEntityType('order_invoice')
	->setEventType('new_invoice');
$mailer->setQueue($emailQueue)->send();

Hence, these are some code manipulation by which you can send orders email quick or queue up invoice emails against immediate delivery.

Feel free to leave the comments below and contact us if you need any other help.

Grow your online business like 4,350 subscribers

    * This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
    envelope

    Thank You!

    We are reviewing your submission, and will be in touch shortly.