//** Swiching Views **
//From FirstViewController
SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
[controller release];
//** Navigation Controller **
//Pushing the First View Controller in App Delegate File
- (void)applicationDidFinishLaunching {
// Create a navigation controller
navController = [[UINavigationController alloc] init];
// Push the first view controller on the stack
MainMenuController *tmpController = [[MainMenuController alloc] initWithNibName:@"MainMenuView" bundle:nil];
[navController pushViewController:tmpController animated:NO];
[tmpController release];
[navController pushViewController:firstViewController animated:NO];
// Add the navigation controller’s view to the window
[window addSubview:navController.view];
[window makeKeyAndVisible];
}
//Push to add a view controller
ViewController *newView = [[ViewController alloc] initWithNibName:@"NewView" bundle:nil];
[self.navigationController pushViewController:newView animated:YES];
[newView release];
//Go back / remove / pop to the View before
[self.navigationController popViewControllerAnimated:YES];
//... or pop to the Root View
[self.navigationController popToRootViewControllerAnimated:YES];
//Set to change the entire stack of view controllers
- (void)setViewControllers:(NSArray *)viewControllers
animated:(BOOL)animated;
//** Message Box / Pop up messages **
// Simple
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"PopUp!" message: @"..." delegate:self cancelButtonTitle:@"Wooohooo!" otherButtonTitles:nil];
[alert show];
// Extended
NSString *msg = [[NSString alloc] initWithFormat:
@"This is a Alert Box Message, %d, everything went OK."
, 123];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"PopUp!"
message:msg
delegate:self
cancelButtonTitle:@"Wooohooo!"
otherButtonTitles:nil];
[alert show];
[alert release];
//** Sharing Data Between Views / Use of a Singleton **
//ClassToShare.h
@interface ClassToShare : NSObject
{
int profileId;
}
@property (nonatomic) int profileId;
+ (ClassToShare *)sharedSingleton;
@end
//ClassToShare.m
@implementation ClassToShare
@synthesize profileId;
+ (ClassToShare *)sharedSingleton
{
static ClassToShare *sharedSingleton;
@synchronized(self)
{
if (!sharedSingleton)
sharedSingleton = [[ClassToShare alloc] init];
return sharedSingleton;
}
}
@end
//How To Use
//From AppDelegate.m (don't forget to add #import "ClassToShare.h")
- (void)applicationDidFinishLaunching:(UIApplication *)application {
ClassToShare *session = [ClassToShare sharedSingleton];
session.profileId = 123;
//[...]
}
//From Any View (don't forget to add #import "ClassToShare.h")
ClassToShare *session = [ClassToShare sharedSingleton];
session.profileId; //123
//** UITableView Table Views Controller Code / Checklist Table **/
@interface SelectFilterController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *listData;
NSIndexPath * selectedIndexPath;
int selectedRow;
}
@property (nonatomic, retain) NSArray *listData;
@property (nonatomic, assign) int selectedRow;
@end
@implementation SelectFilterController
@synthesize listData;
- (void)viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];
self.listData = array;
[array release];
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
//tableViewController is a IBOutlet linked to UITableView object in the Interface Builder
//With this you select programmatically a row in the tableview
if(self.selectedRow > -1) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.selectedRow inSection:0];
[self.tableViewController.delegate tableView:self.tableViewController didSelectRowAtIndexPath:indexPath];
}
}
#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.listData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier: SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int newRow = [indexPath row];
int oldRow;
//check if selectedIndexPath exists
if(selectedIndexPath != nil)
[selectedIndexPath row];
else
-1;
//select or deselect the check mark
if (newRow != oldRow)
{
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:selectedIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
selectedIndexPath = indexPath;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
//** UIWebView **
- (void)viewDidLoad {
NSString *urlAddress = @"http://www.apple.com/uk";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}
- 22nd, Jun 2010
iPhone UIKit / Foundantion Class
- 22nd, Jun 2010
iPhone iPad – Cocoa Touch Classes
//The class declaration always begins with the @interface compiler directive and ends with the @end directive.
//MyClass.h
@interface MyClass : NSObject
{
int count;
NSString* name;
}
@property (nonatomic, retain) NSString *name;
@property (nonatomic, assign) int count;
-(MyClass*)thisIsAMethod:(NSString*)aName;
@end
//MyClass.m
@implementation MyClass
@synthesize name;
@synthesize count;
+ (void) initialize {
self.name=[NSString stringWithFormat:@"Something"];
}
-(MyClass*)thisIsAMethod:(NSString*)aName {
NSLog(aName);
return self;
}
@end
//** Declared Properties **
@property BOOL flag;
@property (copy) NSString *nameObject; // Copy the object during assignment.
@property (readonly) UIView *rootView; // Declare only a getter method.
@property (retain) NSString *name; //Specifies that retain should be invoked on the object upon assignment.
@property (nonatomic) NSArray *array; //Specifies that accessors are non-atomic. By default, accessors are atomic.
//You can combine the @property in a single line if you want:
@property (nonatomic, assign) int number1, number2, number3;
//Note: Each readable property specifies a method with the same name as the property. Each writable property specifies an additional method of the form setPropertyName:, where the first letter of the property name is capitalized.
//In your class implementation, you can use the @synthesize compiler directive to ask the compiler to generate the methods according to the specification in the declaration:
@synthesize flag;
@synthesize nameObject;
@synthesize rootView;
//You can combine the @synthesize statements in a single line if you want:
@synthesize flag, nameObject, rootView;
// UIAction and IBOutlet
// IBAction and IBOutlet are macros defined to point variables and methods to the Interface Builder.
@interface FirstView : UIViewController {
IBOutlet UITextField *personFilter; //this object will be able to point to a Text Field Input in the Interface
//[...]
}
-(IBAction) touchSearch:(id)sender; //this method will be able to point to an event in the Interface
@end
//** Methods and Messaging Syntax **
//Method declaration syntax:
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index
// - is method type identifier
// (void) is Return type
// insertObject, atIndex: Method signature keyworks
// id, NSUInteger: Parameter types
// anObject, index: Parameter names
//Example
-(NSString *) getFilterName:(SearchFilters) filter
//Example
- (NSString *) getName:(NSString *)thisArray
atIndex:(int)index
//** Messaging **
//When you want to call a method, you do so by messaging an object.
//Messages are enclosed by brackets ([ and ]). Inside the brackets, the object receiving the message is on the left side and the message (along with any parameters required by the message) is on the right.
[myArray insertObject:anObject atIndex:0];
//To avoid declaring numerous local variables to store temporary results:
[[myAppObject theArray] insertObject:[myAppObject objectToInsert] atIndex:0];
//Objective-C also provides a dot syntax for invoking accessor methods:
[myAppObject.theArray insertObject:[myAppObject objectToInsert] atIndex:0];
//You can also use dot syntax for assignment:
myAppObject.theArray = aNewArray;
//The syntax for a class method declaration is identical to that of an instance method, with one exception. Instead of using a minus sign for the method type identifier, you use a plus (+) sign.
//** Constructor **
+ (void) initialize {
// Initialization for this class and any subclasses
}
//Strongly and weakly typed variable declarations:
//When storing objects in variables, you always use a pointer type. Objective-C supports both strong and weak typing for variables containing objects. Strongly typed pointers include the class name in the variable type declaration. Weakly typed pointers are used frequently for things such as collection classes, where the exact type of the objects in a collection may be unknown.
MyClass *myObject1; // Strong typing
id myObject2; // Weak typing
More info: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/ObjectiveC/
- 22nd, Jun 2010
Objective-C – Fundamentals – Handbook
//The Objective-C language is a simple computer language designed to enable sophisticated object-oriented programming.
//Objective-C extends the standard ANSI C language by providing syntax for defining classes, and methods, as well as other constructs that
//promote dynamic extension of classes.
.h //Header files.
.m //Source files. This is the typical extension used for source files and can contain both Objective-C and C code.
.mm //Source files. A source file with this extension can contain C++ code in addition to Objective-C and C code
//** Enum **
//declaration
typedef enum numberTypes
{
ONE,
TWO,
THREE
} Numbers;
//use
Numbers x = TWO;
int num = (int)THREE;
//Null object is nil
NSMutableArray *myArray = nil; // nil is essentially the same as NULL
/**
*
* Strings
*
*/
// Create a String.
NSString *myString;
NSString *myString2 = @"My String\n";
NSString *myString3 = nil;
// Concatenate numbers and other strings
NSString *anotherString = [NSString stringWithFormat:@"Number: %d and String: %s", 1, @"My String"];
//Double to String: %f 64-bit floating-point number (double)
//Char to String: %c
//int to string
[NSString stringWithFormat:@"%d", number];
//or
[[NSNumber numberWithInt:number] stringValue];
// Create an Objective-C string from a C string
NSString *fromCString = [NSString stringWithCString:"A C string" encoding:NSASCIIStringEncoding];
//String to Number
//String to Int
int x = [strNumber intValue];
//String to Float
float x = [strNumber floatValue];
//String to Double
double x = [strNumber doubleValue];
/**
*
* Arrays
*
*/
// Create a new array .
NSArray *myArray = [[NSArray alloc] initWithObjects: @"Cat",@"Dog",@"Horse",@"Sheep", nil];
//Array of Arrays
NSMutableArray *searchFilters = [[NSMutableArray alloc] init];
// Initialize with Objects
NSArray *filters = [[NSArray alloc] initWithObjects: @"Cat",@"Dog",@"Horse",@"Sheep", nil];
[searchFilters addObject:filters];
filters = [[NSArray alloc] initWithObjects: @"White",@"Black",@"Red",@"Yellow", nil];
[searchFilters addObject:filters];
filters = [[NSArray alloc] initWithObjects: @"£0 - £20",@"£15 - £40",@"£40 - £80",@"+ £80",@"Any price", nil];
[searchFilters addObject:filters];
/**
*
* Dictionary / Hash Collections
*
*/
//Create the dictionary
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
//Add data
[dictionary setObject:@"Toys" forKey:@"34"];
[dictionary setObject:@"Kitchen" forKey:@"45"];
[dictionary setObject:@"Electronics" forKey:@"46"];
//Get Data
NSLog([dictionary objectForKey:@"34"]);
//Get Keys ordered
NSArray* sortedKeys = [[myDict allKeys] sortedArrayUsingSelector:@selector(compare:)];
//Get Values (Note: It will be unsorted)
NSArray* values = [myDict allValues];
/**
*
* Memory Management
*
*/
//Use of the objects if Garbage Collection is supported and activated (e.g.: iPhoneMac OS X supported)
NSString *str = [NSString string];
// Use of the objects if Garbage Collection is not supported (e.g.: iPhone)
MyObject *obj = [[MyObject alloc] init];
[...]
[obj release];
//Note: EXEC_BAD_ACCESS error usually happens when trying to access an object released.
// Only release objects that you retain, copy, alloc, or new.
/**
*
* Protocols and Delegates
*
*/
//A protocol declares methods that can be implemented by any class. Protocols are not classes themselves.
//They simply define an interface that other objects are responsible for implementing. When you implement the methods of a protocol in one of your classes,
//your class is said to conform to that protocol.
@protocol MyProtocol
- (void)myProtocolMethod;
@end
- 17th, Jun 2010
MySQL Settings for Magento Website
The last month we started having delays processing orders in the backend in a production e-Commerce Website.
We adjusted the system to this config and we the website runs at a really good performance now.
We calculated this values using this formula:
key_buffer_size + (read_buffer_size + sort_buffer_size) * max_connections = Total Memory
Website Details
Magento E-Commerce Website
Running in a:
Dell Server
CPU cores: Two
Processor(s): 1x Dual Xeon
Clock Speed: >= 2.33GHz
RAM: 2 GBytes
Disks: 1×250 GB SATA
Managing:
13.651 Orders in the last 6 months.
24.403 Customers
1.196 Products
Download mysqltuner.pl
More Info:
The MySQL Performance Blog http://www.mysqlperformanceblog.com/2006/05/17/mysql-server-memory-usage/
Stack Overflow: http://stackoverflow.com/questions/1178736/mysql-maximum-memory-usage
Reports
#
#
# Default Configuration
#
#
/etc/my.cnf
innodb_buffer_pool_size = 128M
mysql> SHOW VARIABLES
+-----------------------------------------+------------------------+ | Variable_name | Value | +-----------------------------------------+------------------------+ | innodb_buffer_pool_size | 134217728 | | key_buffer_size | 8384512 | | max_allowed_packet | 1048576 | | sort_buffer_size | 2097144 | | read_buffer_size | 131072 | | read_rnd_buffer_size | 262144 | | tmp_table_size | 16777216 | | myisam_sort_buffer_size | 8388608 | | query_cache_size | 0 | | query_cache_type | ON | | query_cache_limit | 1048576 | | thread_cache_size | 0 | | max_connections | 500 | | innodb_lock_wait_timeout | 50 | | wait_timeout | 28800 | +-----------------------------------------+------------------------+
./mysqltuner.pl
——– General Statistics ————————————————–
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.37
[OK] Operating on 32-bit architecture with less than 2GB RAM
——– Storage Engine Statistics ——————————————-
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 923M (Tables: 190)
[--] Data in InnoDB tables: 1G (Tables: 549)
[!!] Total fragmented tables: 573
——– Performance Metrics ————————————————-
[--] Up for: 15s (147 q [9.800 qps], 9 conn, TX: 289K, RX: 75K)
[--] Reads / Writes: 100% / 0%
[--] Total buffers: 154.0M global + 2.7M per thread (500 max threads)
[OK] Maximum possible memory usage: 1.5G (73% of installed RAM)
[OK] Slow queries: 0% (0/147)
[OK] Highest usage of available connections: 0% (2/500)
[OK] Key buffer size / total MyISAM indexes: 8.0M/193.3M
[OK] Key buffer hit rate: 100.0% (52 cached / 0 reads)
[!!] Query cache is disabled
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 71 sorts)
[OK] Temporary tables created on disk: 1% (1 on disk / 70 total)
[!!] Thread cache is disabled
[OK] Table cache hit rate: 88% (55 open / 62 opened)
[OK] Open file limit used: 0% (16/2K)
[OK] Table locks acquired immediately: 100% (366 immediate / 366 locks)
[!!] Connections aborted: 11%
[!!] InnoDB data size / buffer pool: 1.4G/128.0M
——– Recommendations —————————————————–
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours – recommendations may be inaccurate
Enable the slow query log to troubleshoot bad queries
Set thread_cache_size to 4 as a starting value
Your applications are not closing MySQL connections properly
Variables to adjust:
query_cache_size (>= 8M)
thread_cache_size (start at 4)
innodb_buffer_pool_size (>= 1G)
#
#
# New Configuration
#
#
/etc/my.cnf
innodb_buffer_pool_size = 384M
key_buffer = 256M
query_cache_size = 1M
query_cache_limit = 128M
thread_cache_size = 8
max_connections = 400
innodb_lock_wait_timeout = 100
mysql> SHOW VARIABLES
+-----------------------------------------+------------------------+ | Variable_name | Value | +-----------------------------------------+------------------------+ | innodb_buffer_pool_size | 402653184 | | key_buffer_size | 268435456 | | max_allowed_packet | 1048576 | | sort_buffer_size | 2097144 | | read_buffer_size | 131072 | | read_rnd_buffer_size | 262144 | | tmp_table_size | 16777216 | | myisam_sort_buffer_size | 8388608 | | query_cache_size | 1048576 | | query_cache_type | ON | | query_cache_limit | 134217728 | | thread_cache_size | 8 | | max_connections | 400 | | innodb_lock_wait_timeout | 100 | | wait_timeout | 28800 | +-----------------------------------------+------------------------+
./mysqltuner.pl
——– General Statistics ————————————————–
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.37
[OK] Operating on 32-bit architecture with less than 2GB RAM
——– Storage Engine Statistics ——————————————-
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 926M (Tables: 190)
[--] Data in InnoDB tables: 1G (Tables: 549)
[!!] Total fragmented tables: 572
——– Performance Metrics ————————————————-
[--] Up for: 13s (141 q [10.846 qps], 11 conn, TX: 396K, RX: 59K)
[--] Reads / Writes: 97% / 3%
[--] Total buffers: 659.0M global + 2.7M per thread (400 max threads)
[OK] Maximum possible memory usage: 1.7G (85% of installed RAM)
[OK] Slow queries: 0% (0/141)
[OK] Highest usage of available connections: 1% (4/400)
[OK] Key buffer size / total MyISAM indexes: 256.0M/193.7M
[OK] Key buffer hit rate: 100.0% (52 cached / 0 reads)
[OK] Query cache efficiency: 23.6% (29 cached / 123 selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 53 sorts)
[OK] Temporary tables created on disk: 1% (1 on disk / 54 total)
[OK] Thread cache hit rate: 63% (4 created / 11 connections)
[OK] Table cache hit rate: 86% (46 open / 53 opened)
[OK] Open file limit used: 0% (16/2K)
[OK] Table locks acquired immediately: 100% (265 immediate / 265 locks)
[!!] Connections aborted: 9%
[!!] InnoDB data size / buffer pool: 1.4G/384.0M
- 14th, Jun 2010
Mac OS X Handbook
//Screen Capture //...to desktop SHIFT+CMD+4 //...to clipboard SHIFT+CMD+CTRL+4 //sharp, dash key ####### In Mac on British Keyboards I found it as ALT+3 //pound, pound key £££££££ In Mac on British Keyboards I found it as SHIFT+3 //euro, euro key €€€€€€€€ In Mac on British Keyboards I found it as ALT+2 //unix home, key ~~~~~~~~ Windows: Documents~1 In Mac on British Keyboards I found it as ALT+n //Show hidden files in finder defaults write com.apple.Finder AppleShowAllFiles YES //Burn ISO CDs or DVDs 1) Create image with Disk Utility, uncompressed and CD/DVD master option 2) hdiutil makehybrid -iso -joliet -o Master.iso Master.dmg 3) Burn the ISO image with Disk Utility //determine the device that is you CD/DVD drive drutil status //Install Mac Port from <a href="http://www.macports.org/" target="_blank">www.macports.org</a> port search wget sudo port install unison
- 14th, Jun 2010
MySQL Handbook
/* Shell Commands*/
mysqladmin -u root -p shutdown
mysqladmin -u root -p'oldpassword' password newpass
/* Users */
// Any host
CREATE USER 'user1'@'%' IDENTIFIED BY 'user1';
GRANT ALL PRIVILEGES ON MyDatabase.* TO user1@'%' IDENTIFIED BY 'user1' WITH GRANT OPTION;
SET PASSWORD FOR 'user1'@'%' = PASSWORD('123456');
DROP USER user@'%';
//Specific host
CREATE USER 'user1'@'192.168.1.155' IDENTIFIED BY 'user1';
GRANT ALL PRIVILEGES ON MyDatabase.* TO user1@'192.168.1.155' IDENTIFIED BY 'user1' WITH GRANT OPTION;
SET PASSWORD FOR 'user1'@'192.168.1.155' = PASSWORD('123456');
DROP USER user@'192.168.1.155';
/* Text Field, instead of varchar
for unlimited text field use TEXT var instead of VARCHAR(number)
Not recommended for large databases
*/
/* dump database in /var/www/File-2009-10-28_20:34.sql */
mysqldump -u'user' -p'password' name_database > /var/www/File-$(date +%F_%R).sql
/* Rename a database */
RENAME DATABASE Db_name TO new_db_name;
/* Export Data */
//Export Rows Into A SQL File
mysqldump --user root -p --databases mydatabase --tables 'mytable' --where 'id != 10' > fileUploads3.sql
//Export Rows Into A CSV File
SELECT *
INTO OUTFILE '/Users/nacho/file1.csv'
FROM mytable;
SELECT *
INTO OUTFILE '/Users/nacho/file2.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
FROM mytable
[...];
/* Import Data */
/*
admin1Codes.txt
ES.00 Ceuta
ES.07 Balearic Islands
ES.27 La Rioja
[...]
Relative Path
*/
LOAD DATA LOCAL INFILE './admin1Codes.txt' INTO TABLE admin1Codes (code, name);
/* Absolute Path */
LOAD DATA INFILE '/Users/nacho/Documents/admin1Codes.txt' INTO TABLE admin1Codes (code, name);
/* Run Commands From Shell */
mysql -u'root' -p'root' -e'SHOW DATABASES'
mysql -u'root' -p'root' database < script.sql
- 14th, Jun 2010
How to Create a New Website – Multiwebsite
Creating a new website / store in Magento
1) Creating the folder
cd /magento/folder
$ mkdir newmagentostore
$ cp .htaccess newmagentostore/
$ cp index.php newmagentostore/
2) Modify newmagentostore/index.php
$mageFilename = ‘../app/Mage.php’;
2.1) Modify newmagentostore/.htaccess and add these lines:
SetEnvIf Host “127.0.0.1*” MAGE_RUN_CODE=newmagentostore
SetEnvIf Host “127.0.0.1*” MAGE_RUN_TYPE=website
3) Create a root category (Root NewMagentoStore), mark it as anchor
4) Create New Website
Configuration >>> Manage Store
Name: NewMagentoStore Website
Code: newmagentowebsite
Link to the new store
5) Create New Store
Configuration >>> Manage Store
Name: NewMagentoStore Store
Code: newmagentostore
Link to the category
6) Create New View
Configuration >>> Manage Store
Name: NewMagentoStore View
Code: newmagentoview
7) System >>> Configuration
Scope: Default Config
Currency Setup
Add all new currencies
8) System >>> Configuration
Scope: each View
Currency Setup
set the Default Currency
set the Allowed currencies
9) Config Secure and Unsecure Url
System >>> Configurations >>> Web
Scope: new website_view
Unsecure
Base Url: http://localhost:8888/magento/
Base Link URL: {{unsecure_base_url}}newmagentostore/
Secure
Base Url: http://localhost:8888/magento/
Base Link URL: {{secure_base_url}}newmagentostore/
10) Set conversion rates System >>> Manage Currency Rates
Note: If there is more than one currency allowed, the customer will have a drop-down currency select in each product category.
Note2: If you want to configure fixed prices in different currencies, set the Catalog Price Scope to Website in System >>> Configuration >>> Catalog >>> Price
You will be able to choose the scope config in each product.
- 14th, Jun 2010
Magento Admin Menu and Admin Config Variables
<!-- ************************************************ -->
<!-- ADMIN MENU / ADMIN MENU / ADMIN MENU -->
<!-- ************************************************ -->
<!-- USE: http://127.0.0.1/index.php/admin/report_customer/orders/key/b7ce150ef2c79cb01e8a88cc8287f2c1/ -->
<!-- structure menu: Admin >>> Reports >>> Customers >>> Customer by... -->
<!-- menu definition: -->
<adminhtml>
<menu>
<report>
<children>
<customers>
<children>
<emails translate="title" module="reports">
<title>Customers recently order</title>
<sort_order>60</sort_order>
<action>customreports/adminhtml_customer/order</action>
</emails>
</children>
</report>
</menu>
</adminhtml>
<!-- router definition: -->
<admin>
<routers>
<customreports>
<use>admin</use>
<args>
<module>Unexpectedit_CustomReports</module>
<frontName>customreports</frontName>
</args>
</customreports>
</routers>
</admin>
<!-- controller file:
class Unexpectedit_CustomReports_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
{
public function orderAction(){
[...]
}
-->
<!-- ************************************************ -->
<!-- DECLARE RESOURCE with for MENUS FOR ADMIN ROLE USER -->
<!-- ************************************************ -->
<!-- for the Menu defined above, this would be the resource -->
<!-- Note1: just go to Configuration >>> Permissions >>> Roles -->
<adminhtml>
<acl>
<resources>
<admin>
<children>
<report>
<children>
<customers>
<children>
<emails module="reports">
<title>Customers recentyly order</title>
</emails>
</children>
</children>
</report>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<!-- ************************************************ -->
<!-- CONFIG VARIABLES, CONFIGURATION >>> Options -->
<!-- ************************************************ -->
<!-- File: etc/system.xml -->
<?xml version="1.0"?>
<config>
<sections>
<customer>
<groups>
<create_account>
<fields>
<email_welcome_copy translate="label">
<label>Send Welcome Copy To</label>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</email_welcome_copy>
</fields>
</create_account>
</groups>
</customer>
</sections>
</config>
<!-- use: -->
<?php
$email_welcome_copy=Mage::getStoreConfig('customer/create_account/email_welcome_copy');
?>
- 14th, Jun 2010
Magento declare / override Controllers
<!-- ************************************************ -->
<!-- CONTROLLER / DECLARE / Frontend -->
<!-- ************************************************ -->
<!-- USE: http://127.0.0.1/mydebug/ -->
<!-- Note: It is really important that the module name starts with capital letter. If not it would fail in some Unix systems.
Even the Controller file name should have one capital letter and Controller at the end like: IndexController.php NOT ShowProductsController.php-->
<!-- structure:
Unexpectedit/mydebug
-->
<config>
<frontend>
<routers>
<mydebug>
<use>standard</use>
<args>
<module>Unexpectedit_Mydebug</module>
<frontName>mydebug</frontName>
</args>
</mydebug>
</routers>
</frontend>
</config>
<!-- controller file:
class Unexpectedit_Mydebug_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction(){
echo "-Debug module - ";
}
}
-->
<!-- ************************************************ -->
<!-- CONTROLLER / DECLARE / Frontend with layout file -->
<!-- ************************************************ -->
<!-- USE: http://127.0.0.1/mymodule/ -->
<!-- structure:
Unexpectedit/Mymodule
-->
<frontend>
<routers>
<mymodule>
<use>standard</use>
<args>
<module>Unexpectedit_Mymodule</module>
<frontName>mymodule</frontName>
</args>
</mymodule>
</routers>
<layout>
<updates>
<mymodule>
<file>mymodule.xml</file>
</mymodule>
</updates>
</layout>
</frontend>
<!-- controller file: Unexpectedit/controllers/IndexController.php
class Unexpectedit_Mymodule_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
-->
<!-- layout.xml file: -->
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="left">
<block type="mymodule/view" name="left.mymodule_view" after="catalog"></block>
</reference>
</default>
<mymodule_index_index>
<reference name="content">
<block type="mymodule/results" name="mymodule_results" after="catalog.leftnav" template="mymodule/results.phtml" />
</reference>
</mymodule_index_index>
</layout>
<!-- ************************************************ -->
<!-- CONTROLLER / DECLARE / Admin -->
<!-- ************************************************ -->
<!-- USE: http://127.0.0.1/index.php/customreports/adminhtml_sales/bestseller/key/1eb756c24ee25b303bcf6711da65e4f6/ -->
<!-- structure:
Unexpectedit/CustomReports
/controllers
/Adminhtml
SalesController.php
-->
<!-- menu link
<emails translate="title" module="reports">
<title>Sales Report</title>
<action>customreports/adminhtml_sales/bestseller</action>
</emails>
-->
<admin>
<routers>
<customreports>
<use>admin</use>
<args>
<module>Unexpectedit_CustomReports</module>
<frontName>customreports</frontName>
</args>
</customreports>
</routers>
</admin>
<!-- controller file:
class Unexpectedit_CustomReports_Block_Adminhtml_Sales_Bestseller extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'adminhtml_sales_bestseller';
$this->_blockGroup = 'customreports';
$this->_headerText = 'Bestsellers';
parent::__construct();
$this->_removeButton('add');
}
}
-->
<!-- ************************************************ -->
<!-- CONTROLLER / OVERRIDE / Frontend -->
<!-- ************************************************ -->
<!--
Source: http://www.magentocommerce.com/wiki/how_to_overload_a_controller
Files required:
1. Magento/app/code/local/Unexpectedit/MyCustomer/etc/config.xml
2. Magento/app/code/local/Unexpectedit/MyCustomer/controllers/AccountController.php
Note: It's really important called MyCustomer instead of Customer.
-->
<!-- 1.File: Unexpectedit/MyCustomer/etc/config.xml -->
<?xml version="1.0"?>
<config>
<modules>
<Unexpectedit_MyCustomer>
<version>1.00</version>
</Unexpectedit_MyCustomer>
</modules>
<frontend>
<routers>
<handpickedcollection_mycustomer>
<use>standard</use>
<args>
<module>Unexpectedit_MyCustomer</module>
<frontName>mycustomer</frontName>
</args>
</handpickedcollection_mycustomer>
</routers>
</frontend>
<global>
<rewrite>
<handpickedcollection_mycustomer_account>
<from>#^/customer/account/#</from>
<to>/mycustomer/account/</to>
</handpickedcollection_mycustomer_account>
</rewrite>
</global>
</config>
<!-- 2.File: Unexpectedit/MyCustomer/controllers/AccountController.php -->
<?php
require_once 'Mage/Customer/controllers/AccountController.php';
class Unexpectedit_MyCustomer_AccountController extends Mage_Customer_AccountController
{
// Overloaded loginAction
public function loginAction()
{
echo "great!";
parent::indexAction();
}
?>
<!-- ************************************************ -->
<!-- CONTROLLER / OVERRIDE / Admin -->
<!-- ************************************************ -->
<!-- USE: http://127.0.0.1/index.php/admin/permissions_user/index/ -->
<!-- structure:
Unexpectedit/Adminhtml
/controllers
/Override
/Admin
/Permissions
UserController.php
-->
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Unexpectedit_Adminhtml_Override before="Mage_Adminhtml">Unexpectedit_Adminhtml_Override_Admin</Unexpectedit_Adminhtml_Override>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<!-- controller file:
include("Mage/Adminhtml/controllers/Permissions/UserController.php");
class Unexpectedit_Adminhtml_Override_Admin_Permissions_UserController extends Mage_Adminhtml_Permissions_UserController
{
[...]
}
-->
- 14th, Jun 2010
How to declare / override Magento Blocks
<!-- ************************************************ -->
<!-- BLOCKS / DECLARE -->
<!-- ************************************************ -->
<!-- structure:
Unexpectedit/Home
/Block
/*
-->
<global>
<blocks>
<home>
<class>Unexpectedit_Home_Block</class>
</home>
</blocks>
</global>
<!-- ************************************************ -->
<!-- BLOCKS / OVERRIDE -->
<!-- ************************************************ -->
<!-- structure:
Unexpectedit/Catalog
/Block
/List
View.php
/List
Toolbar.php
-->
<global>
<blocks>
<catalog>
<rewrite><product_view>Unexpectedit_Catalog_Block_Product_View</product_view></rewrite>
<rewrite><product_list_toolbar>Unexpectedit_Catalog_Block_Product_List_Toolbar</product_list_toolbar></rewrite>
</catalog>
</blocks>
</global>
<!-- ************************************************ -->
<!-- BLOCKS / OVERRIDE / Admin -->
<!-- ************************************************ -->
<!-- structure:
Unexpectedit/Adminhtml
/Block
/Customer/Edit/Tab
Account.php
-->
<global>
<blocks>
<adminhtml>
<rewrite><customer_edit_tab_account>Unexpectedit_Adminhtml_Block_Customer_Edit_Tab_Account</customer_edit_tab_account></rewrite>
</adminhtml>
</blocks>
</global>