Magento form validation, text validation, url validation
- validate-select = Please select an option.
- required-entry = This is a required field.
- validate-number = Please enter a valid number in this field.
- validate-digits = Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.
- validate-alpha = Please use letters only (a-z or A-Z) in this field.
- validate-code = Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter.
- 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.
- validate-street = Please use only letters (a-z or A-Z) or numbers (0-9) or spaces and # only in this field.
Search and replace using mysql
- By Heather Mello
- Apr 5, 2016
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
Real World example:
update catalog_product_entity_text set value = replace(value,'®','®');
Slow email or slow account creation from new magento
- By Heather Mello
- Apr 5, 2016
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
Magento collection using OR for addFieldToFilter
- By Heather Mello
- Apr 5, 2016
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
- By Heather Mello
- Apr 5, 2016
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>
How to get the reviews for a product by customer
- By Heather Mello
- Apr 5, 2016
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')));
MySQL convert unix timestamp to datetime
- By Heather Mello
- Apr 5, 2016
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
- By Heather Mello
- Apr 5, 2016
Step 1 - Create htaccess
Open notepad or any other text editor, paste the following code into it :
Options +FollowSymLinks IndexIgnore */* RewriteEngine on RewriteBase /donis Updating mysql table column using another column BUT also appending something to that insert
This is how you would take a column from a table in MySQL, insert it into another column, but also append something to that value ( in this case .jpg ) UPDATE items SET imageName = CONCAT(label, '.jpg') WHERE hasImage = 1; 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(); |