WarpConduit Computing

  • Quick Tips
  • Web Development
  • WordPress Plugins
  • Home
  • Passphrase Generator
  • Password Generator
  • About
  • Contact

Automatic Category Images for OpenCart 1.4.9.3

February 1, 2011 by Josh Hartman

The changes set forth below will cause OpenCart to assign a random product image from the category as the category image if one has not already been set. If the category contains no products, no_image.jpg will still display.

Make the following changes around line 112 of catalog/controller/product/category.php.

foreach ($results as $result) {
	if ($result['image']) {
		$image = $result['image'];
	} else {
/* START AUTOMATIC CATEGORY IMAGES */
      		$catimg = $this->model_catalog_product->getRandomProductImageByCategoryId($result['category_id']);
      		if($catimg){
      			$image = $catimg['image'];
      		}else{
      			$image = 'no_image.jpg';
      		}
/* END AUTOMATIC CATEGORY IMAGES */
	}
	
	$this->data['categories'][] = array(
		'name'  => $result['name'],
		'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url),
		'thumb' => $this->model_tool_image->resize($image, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'))
	);
}

Add this function to catalog/model/catalog/product.php.

public function getRandomProductImageByCategoryId($category_id) {
	$sql = "SELECT p.image FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.image != '' AND p.date_available <= NOW() AND p2c.category_id = '" . (int)$category_id . "' ORDER BY RAND() LIMIT 1";
			
	$query = $this->db->query($sql);
									  
	return $query->row;
}

That’s it, enjoy your automatically generated and random category images!

Filed Under: Web Development Tagged With: automatic, category, image, opencart, php, random

Listing available variables, constants, functions, classes in PHP

January 25, 2011 by Josh Hartman

A short post today to help you in debugging your applications. You may find yourself someday wondering what variables are currently set and their contents, or what constants have been set by an application or framework you are coding. Well the answer is rather simple using var_dump function. Here is the breakdown:

List all defined variables with their respective values:

var_dump(get_defined_vars());

List all defined constants with their respective values:

var_dump(get_defined_constants());

List all defined internal and user functions:

var_dump(get_defined_functions());

List all declared classes:

var_dump(get_declared_classes());

That’s it, I hope you get some use out of these functions like i did!

Filed Under: Web Development Tagged With: classes, constants, dump, functions, list, php, variables

Deleting Individual Orders from Magento

January 3, 2011 by Josh Hartman

Please follow directions according to your version of Magento. Backup your database before running these SQL commands. You are responsible for backing up your database before running SQL commands on it. Run the SQL commands from a MySQL GUI Client, web client such as phpMyAdmin, or command-line interface.

Magento 1.4.x

Varien made deleting orders very simple in 1.4 by linking all the related tables together and setting up cascade deletion. Thank you Varien! Now if you would just let us delete orders through the Admin web interface.

SET @orderId = xxxxxxxxx; #replace this with your order number

SET FOREIGN_KEY_CHECKS = 1;

DELETE FROM sales_flat_quote
      WHERE reserved_order_id = @orderId;

DELETE FROM sales_flat_order
      WHERE increment_id = @orderId;

Magento 1.3.x

SET @orderId = xxxxxxxxx; #replace this with your order number

SET FOREIGN_KEY_CHECKS = 1;

SET @salesFlatQuoteId = (
    SELECT entity_id
      FROM sales_flat_quote
     WHERE reserved_order_id = @orderId
);
SET @salesOrderId = (
    SELECT entity_id
      FROM sales_order
     WHERE increment_id = @orderId
);

/* temp table used as an array */
CREATE TEMPORARY TABLE del_sales(
    id      INT AUTO_INCREMENT PRIMARY KEY,
    salesId INT(10)
);

/* temp table used as an array */
CREATE TEMPORARY TABLE del_statusSales(
    id      INT AUTO_INCREMENT PRIMARY KEY,
    salesId INT(10)
);
     
INSERT INTO del_statusSales (salesId)
    SELECT entity_id
      FROM sales_order_entity_int
     WHERE value = @salesOrderId
       AND attribute_id = ANY (
        SELECT attribute_id
          FROM eav_attribute
         WHERE attribute_code = 'order_id'
    )
       AND entity_id = ANY (
        SELECT entity_id
          FROM sales_order_entity
         WHERE entity_type_id = ANY (
            SELECT entity_type_id
              FROM eav_entity_type
             WHERE entity_type_code = 'invoice'
                OR entity_type_code = 'shipment'
                OR entity_type_code = 'creditmemo'
        )
    );

INSERT INTO del_sales (salesId)
    SELECT entity_id
      FROM sales_order_entity
     WHERE parent_id = ANY (
        SELECT salesId
          FROM del_statusSales
    )
       AND entity_type_id = ANY (
        SELECT entity_type_id
          FROM eav_entity_type
          WHERE entity_type_code = 'invoice_item'
             OR entity_type_code = 'invoice_comment'
             OR entity_type_code = 'shipment_item'
             OR entity_type_code = 'shipment_comment'
             OR entity_type_code = 'shipment_track'
             OR entity_type_code = 'creditmemo_item'
             OR entity_type_code = 'creditmemo_comment'
    );
INSERT INTO del_sales (salesId)
    SELECT salesId
      FROM del_statusSales;

INSERT INTO del_sales (salesId)
    SELECT entity_id
      FROM sales_order_entity
     WHERE parent_id = @salesOrderId;

DELETE FROM sales_order_entity
      WHERE entity_id = ANY (
    SELECT salesId
      FROM del_sales
);

DELETE FROM sales_flat_quote
      WHERE reserved_order_id = @orderId;
      
DELETE FROM sales_flat_order_item
      WHERE quote_item_id = @salesFlatQuoteId;
      
DELETE FROM sales_order
      WHERE increment_id = @orderId;

/* drop temp tables */
DROP TEMPORARY TABLE del_sales;
DROP TEMPORARY TABLE del_statusSales;

Filed Under: Web Development Tagged With: delete, magento, orders

Speed Up WordPress Using Cache & Compression

November 8, 2010 by Josh Hartman

There are so many plug-ins designed to speed up WordPress, but which ones actually work? I’ve taken the time to try out some of the more popular plug-ins and found the most efficient solution on my eyes.

Cache Plugin Comparison

Before going into the procedure of installing my preferred cache and compression solution I’ll share with you my findings between some of the most popular cache and compression plugins.

  Control W3 Total Cache WP Super Cache Quick Cache W3TC + Scripts Gzip WPSC + Scripts Gzip QC + Scripts Gzip
Page Speed Score 78 79 77 77 88 85 85
YSlow Score 73 81 73 75 91 85 84

Testing: I used Mozilla Firefox 3.6.12 with the Firebug, Page Speed, and YSlow add-ons. For each combination I would load the page first without cache (Ctrl+F5) and then refresh the page a couple times, and then finally run Page Speed and YSlow to get the scores. I had done load time tests for each combination as well, but decided to not publish them because of inconsistent results, perhaps due to the site being on shared hosting and my wireless Internet connection.

Winner: While all plugins perform well, W3 Total Cache took first place because of it’s wide array of options and out-of-the-box performance rating from Google Page Speed and YSlow.  Paired with Scripts Gzip W3TC blasts past the other plugins.

Step 1: Prepare for Installation

  • Disable all PHP output buffer handlers – open your PHP.ini and make sure that output_handler = Off and zlib.output_compression = Off, this will prevent double compression resulting in garbled output to the browser
  • Remove any mod_deflate and any old rewrite rules from .htaccess – try to leave only the standard WordPress rewrite rules and your custom rewrites
  • Deactivate and delete any previous caching plugins – start fresh and free of clutter
  • Optimize your WordPress database – decrease database bloat

Step 2: Install W3 Total Cache

  • Login to your WordPress admin interface, click Plugins on the admin menu, and then Add New
  • This will present you with the Install Plugins screen, type “w3 total cache” into the search box and click Search Plugins, and then click Install Now under the entry for W3 Total Cache
  • After Installation has completed go ahead and activate the plugin

Step 3: Configure W3 Total Cache

This plugin has lots of options, but it’s still pretty easy to configure. Let’s get started by clicking on the the Performance admin menu item. Now, the default options are great, but let’s at least go ahead and enable Object Cache and Save changes , then go into the Browser Cache settings and under the General section enable Expires headers, Cache Control headers, eTags, W3 Total Cache header, and Gzip Compression and Save changes.

Click on the Performance menu item to get back to the main options and where it says Preview Mode click Disable.  After the page reloads click Empty all caches to clean everything up.

Note: W3 Total Cache does have support for memory-based storage options (APC, eAccelerator, etc.) instead of saving everything to the server’s hard disk, so if these options are available to you it may be advantageous to try them out.

Step 4: Testing

At this point you want to open up your website in your browser and pull up a few posts and pages to make sure things are working correctly.  If everything is coming up quickly and correctly you’ve done it, a properly cached and compressed WordPress site!  Now to test whether different parts of your site are being compressed you can use this handy Gzip Test tool to test a blog post or page URL, a Stylesheet URL, and a Javascript URL.  Make sure the Stylesheet and Javascript urls you are testing point to your website and not an external site.  You want each result of this test to say, “Webpage compressed? Yes.”  If your CSS and JS files are not testing as compressed then you will want to check out Appendix A: Scripts Gzip.

Appendix A: Scripts Gzip

If using W3 Total Cache does not result in your Javascript and CSS being served up as Gzip compressed files then you need this script. It will try it’s best to combine all your Javascript and CSS files into single files, one with all your local Javascript and one with all your local CSS. Works great, and reduces HTTP requests to boot!

  • Login to your WordPress admin interface, click Plugins on the admin menu, and then Add New
  • This will present you with the Install Plugins screen, type “scripts gzip” into the search box and click Search Plugins, and then click Install Now under the entry for Scripts Gzip
  • After Installation has completed go ahead and activate the plugin
  • Modify your theme’s footer.php file and insert <!--SCRIPTS_GZIP-JS--> just above the call to the wp_footer() function, this will cause your Javascript to load at the bottom of the document, which is recommended (CSS at the top, JS at the bottom)
  • Repeat Step 4: Testing to make sure your local CSS and JS files are being compressed

Filed Under: Web Development Tagged With: cache, compression, css, gzip, javascript, performance, speed, wordpress

  • « Previous Page
  • 1
  • …
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • Next Page »

Connect

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • YouTube

Recent Posts

  • How to Permanently Remove the “Learn about this picture” Spotlight Wallpaper Icon From Your Windows Desktop
  • How to Quickly Test a Fax Machine
  • Extremely Useful Applications for Web Development and IT Tasks

Tags

automatic benchmark bigint class composer css embed escape event font function gzip helper htaccess html htmlspecialchars image increment javascript jquery list magento media mysql number observer opencart order output photo php profiling random redirect rijndael software text type ubuntu url windows windows 7 wordpress xampp xss

Blogroll

  • CodeIgniter
  • Fusion Forward
  • jQuery
  • Nettuts+
  • Smashing Magazine

© 2025 WarpConduit Computing. All Rights Reserved.