From The Blog

By Somebody
Date : 2009-10-11
Comments

How to get Category Thumbnail

A relatively new addition to the Magento category model is the ability to choose a category thumbnail. This works out well because those of you that will have used thumbnails for the category image before will know that when it is displayed on the actual category page, it doesn’t really fit into the area, meaning that it has to be removed or replaced somehow.

Magento has now given us the option to upload a thumbnail as well as a main category image, meaning you can cater for both instances of needing a category image. The most common need for a thumbnail must come when displaying subcategories on the category landing page.

The code for the thumbnail URL is:

Mage::getBaseUrl('media').'catalog/category/'.$_category->getThumbnail()

Notice the use of Baseurl(‘media’)? This will ensure that media directory is always found. Then the file path always begins in the category directory.

For those of you keeping score, here’s the main category image script:

$this->htmlEscape($_category->getImageUrl());

Pretty soon you’ll find yourself able to create subcategory pages of thumbnails and main images with ease.

Thank you for your attention..


Continue Reading

By Somebody
Date : 2011-12-01
Comments

How to Remove all Products in Magento

Here is a quick post about removing all of your products from your Magento installation. Select All and Delete is pretty pants when it comes to removing all of your products, especially if you have over +400 products. PHP max execution time usually would have passed.

Open up your MySQL editor, select your Magento database and execute the below code:

TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;
TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;

INSERT  INTO `catalog_product_link_type`(`link_type_id`,`code`) VALUES (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
INSERT  INTO `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) VALUES (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
INSERT  INTO `cataloginventory_stock`(`stock_id`,`stock_name`) VALUES (1,'Default');

Login to your Admin Panel and browse your empty catalog structure! This script is highly reccomended for testing advanced imports.

Thanks for reading the Magento Blog here at E-commerce web design! The home of the Magento Fox.

Thank you for your attention..


Continue Reading

By Somebody
Date : 2011-12-01
Comments

How to Create Downloadable Products in Magento

This one has had me going round in circles for some time now and it’s been quite pesky to implement. Here’s my solution to creating downloadable links to your products through PHP.

So we don’t have to re invent the wheel here is Rob’s post about creating a product, you can use this to get you started as a base point.

Before we add the links we need to make some changes to the product. Change/Add the following methods to your create product script.

  • Change $product->setTypeId(‘simple’); to $product->setTypeId(‘downloadable’);
  • Add $product->setStoreId(’0′); before $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId())); – Remember to use your store id.

Finally add the below code block after $product->setStockData($stockData);

$product->setDownloadableData(add_downloadable_data());
$product->setLinksPurchasedSeparately(1);
$product->setLinksPurchasedSeparately(true);

Now your product is lets create some links. Paste the below function above $product = Mage::getModel(‘catalog/product’);

function add_downloadable_data() {
  $downloadableitems['link'][0]['is_delete'] = 0;
  $downloadableitems['link'][0]['link_id'] = 0;
  $downloadableitems['link'][0]['title'] = 'My Link';
  $downloadableitems['link'][0]['price'] = 5.00;
  $downloadableitems['link'][0]['number_of_downloads'] = 0;
  $downloadableitems['link'][0]['is_shareable'] = 2;
  $downloadableitems['link'][0]['sample'] = array('file' => '[]','type' => 'url', 'url'  => 'http://example.com/secure/samples/sample-video.mp4');
  $downloadableitems['link'][0]['type'] = 'url';
  $downloadableitems['link'][0]['link_url'] = 'http://example.com/secure/videos/download-video.mp4';

  return $downloadableitems;
}

This is example is not limited to 1 downloadable link, to create multiple links iterate through change the array value for $downloadableitems['link'].

$i = 0;
foreach($arr_links as $link) {
                $downloadableitems['link'][$i]['is_delete'] = $link['is_delete'];
  $downloadableitems['link'][$i]['link_id'] = $link['link_id'];
  $downloadableitems['link'][$i]['title'] = $link['title'];

// add in the rest of the links.......

$i++;
}

Have a play and post your thoughts below!

Thanks for reading the Magento Blog here at E-commerce web design! The home of the Magento Fox!

Thank you for your attention..


Continue Reading

By Somebody
Date : 2010-02-18
Comments

How to Reset Password in Magento

You’ve forgotten you administrator password, we’ve all been there. It’s like getting rejected from your favourite club because your wearing trainers, pitifully annoying.

Hopefully one of the below methods should be your VIP pass back into Mage!

Fire up your favourite database administrator and navigate to your Magento database. Use the below query to select your username.

SELECT 'username' FROM 'admin_user';

Once you’ve found your username it’s time to blag your way in.

UPDATE admin_user SET password=CONCAT(MD5('PaSSWoRd'), ':qX') WHERE username='admin';

For Magento versions before 1.4.1 use this statement.

UPDATE admin_user SET password=CONCAT(MD5('qXpassword'), ':qX') WHERE username='dave';

The above method is good but pretty ruthless, you’ve more than likely changed your store owners password. If you fancy a more reckless/elegent method copy the below code into the following file: /app/code/core/Mage/Adminhtml/controllers/IndexController.php.

For this code to work you will have to comment out the loginAction() method, temporarily. Navigate to your Magento admin path and login with any credentials you like, your user will be created.

Thank you for your attention..


Continue Reading

By Somebody
Date : 2009-12-01
Comments

How to Display Custom Attributes on Product View

Adding custom attributes to your product view is very easy. Adding them to the product listing (category pages) is much more difficult. You’ll need to create a custom module for that. In this post though, I’ll only be showing you how to add attributes to the product view page.

If it is a text field (textbox or textarea), this is all you have to do:

<?php echo $_product->getAttributeName() ?>

If you are using a dropdown or a multiple select, you have to call it a little differently:

<?php echo $_product->getAttributeText('shirt_size') ?>

Thank you for your attention..


Continue Reading

By Somebody
Date : 2009-11-05
Comments

How to Install Fancybox for Magento

Fancybox, the Lightbox alternative, is the king of the floating content world. With slick shadows and the ability to display pretty much anything you can embed into a HTML document, it reigns supreme.

If you want to hack up the main templates and are available for a first class ticket to copy and paste hell, it’s easy to install for Magento.

For our install you will need to download the latest stable release of the jQuery and fancybox library’s.

To start things off, unzip and upload the fancybox folder to the document root layer of your Magento installation, this will make it accessible to all of your packages and themes.

Now create a new CSS file called fancybox-loader.css, paste in the below code and save it in this directory: /skin/frontend/[PACKAGE]/[THEME]/css/

@import url("/fancybox/jquery.fancybox-x.x.x.css");

This stylesheet relatively calls in the fancybox master stylesheet, which in turn, loads the fancybox images relatively. If we didn’t create fancybox-loader.css we would have to edit all the image paths, which you really don’t want to be doing.

Open the jQuery library and add the following line of code to the very bottom of the file, and upload to this directory: /js/jquery/[JQUERY-FILE].js

var j = jQuery.noConflict();

That snippet will disable the ‘$’ object variable for jQuery, as it is already being used by the Prototype library, which is weaved into Magento.

Last thing to do before we put it all together is move the jquery.fancybox-x.x.x.pack.js file from /fancybox to /js/jquery. Then to link it all together in your page.xml (/app/design/frontend/[PACKAGE]/[THEME]/layout/page.xml). Add in the following lines of XML into the ‘head’ block.

<action method="addJs"><script>jquery/jquery-x.x.x.js</script></action>
<action method="addJs"><script>jquery/jquery.fancybox-x.x.x.pack.js</script></action>
<action method="addCss"><stylesheet>css/fancybox-loader.css</stylesheet></action>

This will include the required files in the ‘‘ of your HTML page. To drop in some fancybox magic open up your desired temlpate/CMS page/static block and add the following code.

<a id="inline" href="#data">Foxy Div</a>
<div style="display:none"><div id="data">Foxes rule, Dogs drule!</div></div>

<script type="text/javascript">
 j(document).ready(function() {
  j("#inline").fancybox();
 });
</script>

Job Done!

Thank you for your attention..


Continue Reading