WarpConduit Computing

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

Increase Image Upload File Size Limit on OpenCart 1.4.9.3

February 4, 2011 by Josh Hartman

OpenCart’s default image upload size is 300KB and that is simply too small for clients that don’t have the knowledge to resize their images before uploading them. Although uploading digital camera images does use more bandwidth, sometimes it can not be avoided. To adjust the image upload size make the following changes around line 446 of admin/controller/common/filemanager.php:

if ($this->request->files['image']['size'] > 10485760) {
	$json['error'] = $this->language->get('error_file_size');
}

In this case we have increased the upload size limit to 10MB, also make sure that your php configuration will allow file uploads and posts of this size.

Now you have these big images uploaded, but sometimes GD can run out of memory trying to resize these large images. You can solve this by using imagemagick, if available. So what we’re going to do is resize all images larger than 1000×1000 down to 1000×1000. Make the following changes around line 490 of admin/controller/common/filemanager.php:

if (!isset($json['error'])) {	
	if(substr($this->request->files['image']['type'],0,5)=='image'){
		$imageinfo = getimagesize($this->request->files['image']['tmp_name']);
		if($imageinfo[0]>1000 || $imageinfo[1]>1000){
			exec('convert -colorspace RGB "'.$this->request->files['image']['tmp_name'].'" -resize 1000x1000 "'.$this->request->files['image']['tmp_name'].'"');
		}
	}
	if (@move_uploaded_file($this->request->files['image']['tmp_name'], $directory . '/' . basename($this->request->files['image']['name']))) {		
		$json['success'] = $this->language->get('text_uploaded');
	} else {
		$json['error'] = $this->language->get('error_uploaded');
	}
}

That’s it, your image upload file size limit has been lifted and memory usage issues have been dealt with!

Filed Under: Web Development Tagged With: image, limit, opencart, php, size, upload

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

  • « Previous Page
  • 1
  • …
  • 6
  • 7
  • 8
  • 9
  • 10
  • …
  • 12
  • 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.