How to bulk upload to more than one category with the excellent Wp-e-commerce plugin.
In our case, we needed to assign each product to a category and a brand (e.g. Category: Jeans, Brand: Levis). To do this, we removed the bulk 'add to category' dropdown from the bottom of the import page and added a category and brand option to the dropdowns that are used to assign columns in the uploaded .csv file. Here's how...
Open wp-e-commerce/wpsc-admin/includes/settings-pages/import.php
As we are going to assign each item to its own category and brand, the category dropdown at the bottom of the upload page is no longer relevant. So, we remove lines 77 - 85:
Please select a category you would like to place all products from this CSV into:
'.$category.'';
}
Next we add the category and brand options to the dropdown list of assignable fields.
lines 61 - 69 show:
Product Name
Description
Additional Description
Price
SKU
Weight
Weight Unit
Stock Quantity
Stock Quantity Limit
We are going to add to these so we now have:
Product Name
Description
Additional Description
Price
SKU
Weight
Weight Unit
Stock Quantity
Stock Quantity Limit
Category
Brand
now we change (what is now) line 122 - 123 to read:
$category_query = "INSERT INTO `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` VALUES ('','$id','".$cvs_data2."')";
$wpdb query($category_query);
and add the following two lines underneath:
$brand_query = "INSERT INTO `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` VALUES ('','$id','".$cvs_data2."')";
$wpdb query($brand_query);
This is simply adding the category and brand id to the WPSC_TABLE_ITEM_CATEGORY_ASSOC table.
Remember to add the Category IDs to your csv file and NOT the category name. Alternatively you could extend this tutorial by looking up the Category ID using the Category Name and inserting that.
Mostrando entradas con la etiqueta Content Management System (CMS). Mostrar todas las entradas
Mostrando entradas con la etiqueta Content Management System (CMS). Mostrar todas las entradas
miércoles, 19 de mayo de 2010
martes, 12 de enero de 2010
Custom Write Panels
One of the great assets Wordpress possesses is the ability to easily customise the backend.
For example, a client needs a website for a real estate agent. The client will be posting information on the various properties available and displaying standard information on each property:
Title
Short Description
Long Description
Price
Thumbnail image
Large images
Bedrooms
Bathrooms
Generic Description (selected from a list of pre-defined descriptions)
Obviously the title and description fields can be covered using the standard Wordpress Title and Content fields. Thanks to the fantastic additions to Wordpress 2.9, Post Thumbnail images are now easy to use and reference, and the Gallery Shortcode has been in effect for a while now.
This just leaves the custom fields. There are plugins you can use, but we are control freaks and like to do thinks ourselves. So, as a starting point, we use this fantastic tutorial on Wefunction, but with a few extras.
First of all we create an array for our fields:
$track_meta_boxes =
array(
"price" => array(
"name" => "price",
"type" => "input",
"std" => "",
"title" => "Price",
"options" => "",
"description" => "Enter Property Price"),
"bedrooms" => array(
"name" => "bedrooms",
"type" => "input",
"std" => "",
"title" => "Bedrooms",
"options" => "",
"description" => "No. of bedrooms"),
"bathrooms" => array(
"name" => "bathrooms",
"type" => "input",
"std" => "",
"title" => "Bathrooms",
"options" => '',
"description" => "No. of bathrooms"),
"desc" => array(
"name" => "desc",
"type" => "select",
"std" => "",
"title" => "Description",
"options" => $desc,
"description" => "Description")
);
Notice that we have added a field called "type" to our array. This defines whether we are displaying and input box or a select box. We also add an array called $desc to the 'options' field. This could be defined as follows:
$desc = "Great for the first time buyer";
$desc = "Roomy and spacious";
$desc = "No room to swing a cat";
Now we just make a small amendment to the code to test whether we are displaying a select or input field:
if ( $meta_box == 'select' ) {
echo '';
} else {
echo '';
}
Note that this code just deals with displaying the panel. You can ascertain the necessary coding to display saved values (front and backend) from the wefunction tutorial. You will probably also want to test each of your option values against the saved value and flag it as selected if it is indeed the saved value.
We would also advise using the standard Wordpress markup when it comes to displaying the panels (something that they don't do in the wefunction tutorial). This is just for aesthetics, and it saves space.
For example, a client needs a website for a real estate agent. The client will be posting information on the various properties available and displaying standard information on each property:
Title
Short Description
Long Description
Price
Thumbnail image
Large images
Bedrooms
Bathrooms
Generic Description (selected from a list of pre-defined descriptions)
Obviously the title and description fields can be covered using the standard Wordpress Title and Content fields. Thanks to the fantastic additions to Wordpress 2.9, Post Thumbnail images are now easy to use and reference, and the Gallery Shortcode has been in effect for a while now.
This just leaves the custom fields. There are plugins you can use, but we are control freaks and like to do thinks ourselves. So, as a starting point, we use this fantastic tutorial on Wefunction, but with a few extras.
First of all we create an array for our fields:
$track_meta_boxes =
array(
"price" => array(
"name" => "price",
"type" => "input",
"std" => "",
"title" => "Price",
"options" => "",
"description" => "Enter Property Price"),
"bedrooms" => array(
"name" => "bedrooms",
"type" => "input",
"std" => "",
"title" => "Bedrooms",
"options" => "",
"description" => "No. of bedrooms"),
"bathrooms" => array(
"name" => "bathrooms",
"type" => "input",
"std" => "",
"title" => "Bathrooms",
"options" => '',
"description" => "No. of bathrooms"),
"desc" => array(
"name" => "desc",
"type" => "select",
"std" => "",
"title" => "Description",
"options" => $desc,
"description" => "Description")
);
Notice that we have added a field called "type" to our array. This defines whether we are displaying and input box or a select box. We also add an array called $desc to the 'options' field. This could be defined as follows:
$desc = "Great for the first time buyer";
$desc = "Roomy and spacious";
$desc = "No room to swing a cat";
Now we just make a small amendment to the code to test whether we are displaying a select or input field:
if ( $meta_box == 'select' ) {
echo '';
} else {
echo '';
}
Note that this code just deals with displaying the panel. You can ascertain the necessary coding to display saved values (front and backend) from the wefunction tutorial. You will probably also want to test each of your option values against the saved value and flag it as selected if it is indeed the saved value.
We would also advise using the standard Wordpress markup when it comes to displaying the panels (something that they don't do in the wefunction tutorial). This is just for aesthetics, and it saves space.
Etiquetas:
Content Management System (CMS),
php,
wordpress
martes, 17 de noviembre de 2009
Displaying user data in your Wordpress theme
The last time I needed to display user data was for the Press Stick website. For their site, they wanted the user to be greeted with a personalised message on logging in.
The message for the Press Stick site was:
"hi from . welcome back to the press-stick sourcing portal. we look forward to showing you the new and exciting products available to you."
For the purpose's of this site, we tweaked the standard Wordpress user data so that the user's magazine name would be stored in the 'Nickname' field. To return the message above, we simply insert the following:
user_firstname.' '.$current_user user_lastname;
$magazine = $current_user nickname;
echo '';
The message for the Press Stick site was:
"hi from . welcome back to the press-stick sourcing portal. we look forward to showing you the new and exciting products available to you."
For the purpose's of this site, we tweaked the standard Wordpress user data so that the user's magazine name would be stored in the 'Nickname' field. To return the message above, we simply insert the following:
user_firstname.' '.$current_user user_lastname;
$magazine = $current_user nickname;
echo '';
Etiquetas:
Content Management System (CMS),
php,
Press Stick,
wordpress
List all blogs in a Wordpress MU installation
The African Travel Experts site has two dropdown lists of all the blogs on their WPMU installation sorted into two different categories. Here's how.
The way the site is set up is to have the African Travel Experts site as the main 'umbrella site' with sub-sites for each African country, which act as parent sites to sub-sites relating to the country. For example:
Master site: African Travel Experts
Country sub-site: South Africa
Child-site: Cape Town
Seeing as the standard WPMU installation doesn't provide for classifying blogs/sites in this way, a plugin and a bit of lateral thinking was required. I opted for the Blog Types plugin, which allows you to define your own categories for a blog. Once installed, I defined my categories in the config as follows:
// Blog types
// name and nicename are required
$blog_types = 'South Africa';
$blog_types = 'south_africa';
$blog_types = '';
$blog_types = 'no';
$blog_types = 'Botswana';
$blog_types = 'botswana';
$blog_types = '';
$blog_types = 'no';
//.... etc until all countries are defined
$blog_subtypes = 'Cape Town';
$blog_subtypes = 'cape_town';
$blog_subtypes = 'south_africa';
$blog_subtypes = '';
$blog_subtypes = 'Eastern Cape';
$blog_subtypes = 'eastern_cape';
$blog_subtypes = 'south_africa';
$blog_subtypes = '';
//.... etc until all areas are defined
// Allow users to select one or multiple blog types
// Note: If you allow users to select multiple blog types, they cannot select a subtype
$blog_types_selection = 'single'; //Options: 'single' or 'multiple'
// Allow users to select one or multiple blog subtypes
$blog_subtypes_selection = 'single'; //Options: 'single' or 'multiple'
// Branding singular
$blog_types_branding_singular = __('Country');
$blog_subtypes_branding_singular = __('Area');
// Branding plural
$blog_types_branding_plural = __('Countries');
$blog_subtypes_branding_plural = __('Areas');
// Display admin panel blog types page
$blog_types_display_admin_page = 'yes'; //Options: 'yes' or 'no'
// Display signup form blog types selection
$blog_types_display_signup_form = 'yes'; //Options: 'yes' or 'no'
// Enable subtypes
$blog_types_enable_subtypes = 'yes'; //Options: 'yes' or 'no'
The way the site is set up is to have the African Travel Experts site as the main 'umbrella site' with sub-sites for each African country, which act as parent sites to sub-sites relating to the country. For example:
Master site: African Travel Experts
Country sub-site: South Africa
Child-site: Cape Town
Seeing as the standard WPMU installation doesn't provide for classifying blogs/sites in this way, a plugin and a bit of lateral thinking was required. I opted for the Blog Types plugin, which allows you to define your own categories for a blog. Once installed, I defined my categories in the config as follows:
// Blog types
// name and nicename are required
$blog_types = 'South Africa';
$blog_types = 'south_africa';
$blog_types = '';
$blog_types = 'no';
$blog_types = 'Botswana';
$blog_types = 'botswana';
$blog_types = '';
$blog_types = 'no';
//.... etc until all countries are defined
$blog_subtypes = 'Cape Town';
$blog_subtypes = 'cape_town';
$blog_subtypes = 'south_africa';
$blog_subtypes = '';
$blog_subtypes = 'Eastern Cape';
$blog_subtypes = 'eastern_cape';
$blog_subtypes = 'south_africa';
$blog_subtypes = '';
//.... etc until all areas are defined
// Allow users to select one or multiple blog types
// Note: If you allow users to select multiple blog types, they cannot select a subtype
$blog_types_selection = 'single'; //Options: 'single' or 'multiple'
// Allow users to select one or multiple blog subtypes
$blog_subtypes_selection = 'single'; //Options: 'single' or 'multiple'
// Branding singular
$blog_types_branding_singular = __('Country');
$blog_subtypes_branding_singular = __('Area');
// Branding plural
$blog_types_branding_plural = __('Countries');
$blog_subtypes_branding_plural = __('Areas');
// Display admin panel blog types page
$blog_types_display_admin_page = 'yes'; //Options: 'yes' or 'no'
// Display signup form blog types selection
$blog_types_display_signup_form = 'yes'; //Options: 'yes' or 'no'
// Enable subtypes
$blog_types_enable_subtypes = 'yes'; //Options: 'yes' or 'no'
Etiquetas:
African Travel Experts,
Content Management System (CMS),
mySQL,
php,
Wordpress Multi User
lunes, 16 de noviembre de 2009
Auto-generating Community Builder profiles
For the AIRCO website, user profiles had to be auto-generated on admin approval, and a mail generated to the user.
The site was already running on a Joomla installation making use of the Community Builder suite, but some extra tweaking was needed to hook the site up to the member application backend.
The Process:
Potential member completes application form
Admin approves form
Profile is auto-generated and details are mailed to the member as follows:
1. Convert the member's name to a valid username (the member can always edit this if it isn't what they want)
$username = ereg_replace("", "", $name ); //convert to alphanumeric
$username = trim($username); // remove any unnecessary whitespace
$username = substr($username, 0, 24); //ensure the length of the username doesn't exceed 24 characters
2. Ensure that the email address used is unique (this is tested on initial registration, but we re-test to be safe)
$query = "SELECT * FROM jos_users WHERE email = '$email'";
$result = mysql_query($query) or die(mysql_error());
$check = mysql_num_rows($result);
if($check 0):
//flag as duplicate and exit
endif;
3. Check for duplicate username, and if one exists add a number on the end, retest and increment number until we get a unique value:
$n = 0;
$username_flag = '';
while($username_flag != 'set'):
$query = "SELECT * FROM jos_users WHERE username = '$username'";
$result = mysql_query($query) or die(mysql_error());
$check = mysql_num_rows($result);
$n++;
if($check 0):
$username = $username.$n;
else:
$username_flag = 'set';
endif;
endwhile;
4. Everything ok? Then we add the data:
a. Add
jos_users - name, username, email, password (remember to encrypt this with md5), usertype, gid, registerDate, params
jos_core_acl_aro - section_value = users, value = id of the record you inserted into jos_users, name = name of the member (as entered into jos_users)
jos_core_acl_groups_aro_map - group_id = id of the group your member belongs to, in my case 19 - Author, aro_id = id of the record you inserted into jos_core_acl_aro
jos_comprofiler id & user_id = id of the record you inserted into jos_users, then any other values captured for custom fields.
5. Finally email the member:
$to = $email;//captured from application form
$subject = "Your profile";
$body = "Dear ".$name."\n";
$body .= "You are now a full Member.\n\n";
$body .= "MEMBER'S AREA LOG-IN DETAILS\n";
$body .= "Username: ".$username."\n";
$body .= "Password: ".$password."\n\n";
$from = "FROM: ".$SENDERS_EMAIL_HERE;
mail($to, $subject, $body, $from);
The site was already running on a Joomla installation making use of the Community Builder suite, but some extra tweaking was needed to hook the site up to the member application backend.
The Process:
Potential member completes application form
Admin approves form
Profile is auto-generated and details are mailed to the member as follows:
1. Convert the member's name to a valid username (the member can always edit this if it isn't what they want)
$username = ereg_replace("", "", $name ); //convert to alphanumeric
$username = trim($username); // remove any unnecessary whitespace
$username = substr($username, 0, 24); //ensure the length of the username doesn't exceed 24 characters
2. Ensure that the email address used is unique (this is tested on initial registration, but we re-test to be safe)
$query = "SELECT * FROM jos_users WHERE email = '$email'";
$result = mysql_query($query) or die(mysql_error());
$check = mysql_num_rows($result);
if($check 0):
//flag as duplicate and exit
endif;
3. Check for duplicate username, and if one exists add a number on the end, retest and increment number until we get a unique value:
$n = 0;
$username_flag = '';
while($username_flag != 'set'):
$query = "SELECT * FROM jos_users WHERE username = '$username'";
$result = mysql_query($query) or die(mysql_error());
$check = mysql_num_rows($result);
$n++;
if($check 0):
$username = $username.$n;
else:
$username_flag = 'set';
endif;
endwhile;
4. Everything ok? Then we add the data:
a. Add
jos_users - name, username, email, password (remember to encrypt this with md5), usertype, gid, registerDate, params
jos_core_acl_aro - section_value = users, value = id of the record you inserted into jos_users, name = name of the member (as entered into jos_users)
jos_core_acl_groups_aro_map - group_id = id of the group your member belongs to, in my case 19 - Author, aro_id = id of the record you inserted into jos_core_acl_aro
jos_comprofiler id & user_id = id of the record you inserted into jos_users, then any other values captured for custom fields.
5. Finally email the member:
$to = $email;//captured from application form
$subject = "Your profile";
$body = "Dear ".$name."\n";
$body .= "You are now a full Member.\n\n";
$body .= "MEMBER'S AREA LOG-IN DETAILS\n";
$body .= "Username: ".$username."\n";
$body .= "Password: ".$password."\n\n";
$from = "FROM: ".$SENDERS_EMAIL_HERE;
mail($to, $subject, $body, $from);
Etiquetas:
Airco,
Content Management System (CMS),
joomla,
mySQL,
php
Suscribirse a:
Entradas (Atom)