Engine23

Magento Ecommerce Strategy, Design & Development

Magento Cron configuration

Magento Settings: System >> Configuration >> System > ‘Cron (Scheduled Tasks)’ tab.

  • Generate schedules every: 60
  • Schedule ahead for: 1
  • Missed if not run within: 60
  • History cleanup every: 120
  • Success history lifetime: 120
  • Failure history lifetime: 120
$ crontab -e 
# Execute the Magneto cron every 15 minutes
*/15 * * * * /bin/sh /path/to/magento/cron.sh 
These settings allow Magento to generate and clean schedules within a 2-hour time frame.

Get a Magento table name or custom table name

So you want to get the table name that is declared in the xml and you are not in an upgrade/install script.

If you were in an upgrade/install script you could just use: 

$tbl = $this->getTable('catalog/product');

In any other page you can use:

$tbl = Mage::getSingleton('core/resource')->getTableName('catalog/product');

If this will return: catalog_product_entity

This works with any declaration that is set in the xml!

Setting up Amazon EC2 Ubuntu 12.10 server for Magneto using NFS

This is all the steps and details i used to create an instance of a web server to be used for a Magento Website.

1 - Start a m3.xlarge instance

2 - Make sure its part of a security group that has Ports 80, 443 open to all 0.0.0.0/0

3 - Add a SSH port execption for your IP

4 - Assign an Elastic IP to each new instance

5 - Get the ssh details from Connect Instance in the Amazon control panel and ssh into the device(s)

6- Change the date/time of the server

Read more

Magento Form Validation

Magento form validation, text validation, url validation

Validation using Magento Adminhtml forms. Validate class and its error message that found in prototype library.

  1. validate-select = Please select an option.
  2. required-entry = This is a required field.
  3. validate-number = Please enter a valid number in this field.
  4. validate-digits = Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.
  5. validate-alpha = Please use letters only (a-z or A-Z) in this field.
  6. validate-code = Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter.
  7. validate-alphanum = Please use only letters (a-z or A-Z) or numbers (0-9) only in this field. No spaces or other characters are allowed.
  8. validate-street = Please use only letters (a-z or A-Z) or numbers (0-9) or spaces and # only in this field.

Read more

Slow email or slow account creation from new magento

If you have a new magento installation, and you notice that the join process takes a very long time to complete, your sendmail is probably the source.

Some new servers dont have sendmail setup properly and you need to adjust a few things.

For slow email from the app, edit 3 files.
1)  /etc/resolv.conf, add search whateveryourdomainnameis.com in before the nameservers.

[root@Web1 etc]# cat /etc/resolv.conf
search winetapsocial.com
nameserver 114.243.44.83
nameserver 114.243.44.84

Read more

Magento collection using OR for addFieldToFilter

Lets say you wanted sql that looked something like:

SELECT `main_table`.*,`main_table`.`email` AS `invitation_email`,`main_table`.`group_id` AS `invitee_group_id` FROM `enterprise_invitation` AS `main_table` WHERE ((status ='new') OR (customer_id ='1234'))

In order to achieve this, your collection needs to be formatted like this:

$collection =Mage::getModel('enterprise_invitation/invitation')->getCollection(); $collection->addFieldToFilter(array('status','customer_id'), array( array('status','eq'=>'new'), array('customer_id','eq'=>'1234')));

Now to see what this looks like you can always echo the query that this creates by using

echo $collection->getSelect()->__toString();