Engine23

Development

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();

Rewrite or Overload Mage_Sales_Model_Order

If you have ever needed to rewrite/overload a core magento Model.

Its actually pretty easy

Step 1: create the module instantiation file

app/etc/modules/Russellalbin_Sales.xml

<?xml version="1.0"?>
<config>
<modules>
<Indiebooker_Sales>
<active>true</active>
<codePool>local</codePool>
</Indiebooker_Sales>
</modules>
</config>

Read more

How to get the reviews for a product by customer

Here is how you can get a product reviewed by a customer in Magento

$storeId = Mage::app()->getStore()->getId();
$customer_reviews = Mage::getModel('review/review')
->getResourceCollection()
->addStoreFilter($storeId)
->addEntityFilter('product', $product_id)
->addFieldToFilter('customer_id', array('eq' =>$customer->getData('id')));
 

Read more

MySQL convert unix timestamp to datetime

UPDATE invoice
   SET invoice_date2 = FROM_UNIXTIME(invoice_date) WHERE invoice_date > 0;
UPDATE invoice
   SET estimated_date2 = FROM_UNIXTIME(estimated_date) WHERE estimated_date > 0;
UPDATE invoice
   SET completed_date2 = FROM_UNIXTIME(completed_date) WHERE completed_date > 0;
UPDATE lawn_contract
  SET lawn_contract_date2 = FROM_UNIXTIME(lawn_contract_date) WHERE lawn_contract_date > 0;
UPDATE tree_shrub
SET estimated_date2 = FROM_UNIXTIME(estimated_date) WHERE estimated_date > 0;
UPDATE lawn_contract
SET estimated_date2 = FROM_UNIXTIME(estimated_date) WHERE estimated_date > 0;

Remove index.php from Yii project URL


Step 1 - Create htaccess

Open notepad or any other text editor, paste the following code into it :
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
 
RewriteBase /donis

Read more

Yii getCommandBuilder() to get the select statement that is built

$model = BanksToSalespeople::model();

$addresses = array();

$criteria = $model->dbCriteria;

$criteria->with = "users";

$criteria->together = true;

$criteria->join ="LEFT JOIN users ON t.userID = users.id";

$criteria->select = 'email';

$criteria->condition = "t.bankID = '$bankID' AND users.email != ''";

// This is how to get the query that is built from the Yii magic command builder:

$query = $model->getCommandBuilder()->createFindCommand($model->getTableSchema(),$criteria)->getText();