importing data into ZenCart

From HTYP, the free directory anyone can edit

Jump to: navigation, search

Contents

[edit] Navigation

computing: software: ZenCart: importing data

[edit] Overview

ZenCart, as of this writing, has no facility for importing business data for other applications. Due to ZenCart's open source nature, however, it is not difficult to write such a routine and add it to the menu of available functions in the Administration section. The necessary particulars are not very well documented yet, so this page will be a collection point for that information.

[edit] Patches

Some features are still stubbed, but you can bulk-upload images and then assign or delete them individually. Some functions use wiki access, which can be replaced with hard-coded HTML (need to document this).

[edit] custom_dhtml.php

  • new file: $zc/admin/includes/boxes/custom_dhtml.php
<?php
/*
 2006-09-17 (wzl) custom menu loader based on reports.dhtml and others
 
 REQUIRES:
	admin/custom_menu.php
	single-line modification to admin/includes/header_navigation.php
*/
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
 
define('CUSTOM_MENU_MODULE', 'custom_menu');
define('CUSTOM_MODULE_SET_PROD_ENTRY','bulk_prod_entry');
define('CUSTOM_MODULE_SET_BULK_UPLOAD','bulk_img_upload');
define('CUSTOM_MODULE_SET_BULK_ASSIGN','bulk_img_assign');
 
  $za_contents = array();
  $za_heading = array();
// 2006-09-17 (Wzl) this could ultimately use language defines, but for now I am hard-coding the text
  $za_heading = array('text' => 'Jubilee Custom Functions', 'link' => zen_href_link(CUSTOM_MENU_MODULE, '', 'NONSSL'));
  $za_contents[] = array('text' => 'Bulk product entry', 'link' => zen_href_link(CUSTOM_MENU_MODULE, 'set=bulk_prod_entry', 'NONSSL'));
  $za_contents[] = array('text' => 'Bulk image upload', 'link' => zen_href_link(CUSTOM_MENU_MODULE, 'set=bulk_img_upload', 'NONSSL'));
  $za_contents[] = array('text' => 'Bulk image assign/delete', 'link' => zen_href_link(CUSTOM_MENU_MODULE, 'set=bulk_img_assign', 'NONSSL'));
?>
<!-- drop-down //-->
<?php
echo zen_draw_admin_box($za_heading, $za_contents);
?>
<!-- end of drop-down //-->

"Jubilee Custom Functions" can be replaced by whatever text seems appropriate; "Jubilee" was part of the name of the store I was setting up, and I wanted to make it clear to the owner that this was the menu entry I had written for him.

[edit] custom_menu.php

[edit] header_navigation.php

  • file edit: $zc/admin/includes/header_navigation.php
//  require(DIR_WS_BOXES . 'extras_dhtml.php');
  require(DIR_WS_BOXES . 'custom_dhtml.php');

Removing extras_dhtml.php is optional; the store I was setting up had no use for it.

[edit] new tables

So far, I haven't needed to use the new table names in more than one file; if I do, I'll need to move the defines from $zc/admin/custom_menu.php to $zc/includes/database_tables.php

  • new tables:
CREATE TABLE `custom_import_mfgrs` (
  `id_mfgr` int(11) NOT NULL DEFAULT '0' COMMENT 'manufacturers.id',
  `import_alias` varchar(255) NOT NULL DEFAULT '' COMMENT 'name used in import data'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 
CREATE TABLE `custom_import_prod` (
  `import_key` varchar(255) DEFAULT NULL,
  `prod_key` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='custom table for handling imported products';
 
CREATE TABLE `custom_uploads` (
  `id` int(11) NOT NULL KEY AUTO_INCREMENT,
  `id_admin` int(11) NOT NULL DEFAULT '0' COMMENT 'who did the upload (admin.admin_id)',
  `when_started` datetime DEFAULT NULL COMMENT 'timestamp of when the upload started',
  `when_finished` datetime DEFAULT NULL COMMENT 'timestamp of when the upload finished; NULL means incomplete',
  `filename` varchar(255) NOT NULL COMMENT 'name of archive (zipfile or tarball) being uploaded',
  `comment` varchar(255) DEFAULT ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='custom table for managing bulk file uploads';
 
CREATE TABLE `custom_upload_files` (
  `id` int(11) NOT NULL KEY AUTO_INCREMENT,
  `id_upload` int(11) NOT NULL COMMENT 'custom_uploads.id',
  `filespec` varchar(255) NOT NULL COMMENT 'relative filespec of image file',
  `size_x` int(11) DEFAULT NULL COMMENT 'pixel width of image',
  `size_y` int(11) DEFAULT NULL COMMENT 'pixel height of image',
  `id_prod` int(11) DEFAULT NULL COMMENT 'products.products_id - product to which this image was assigned',
  `when_deleted` datetime DEFAULT NULL COMMENT 'if not null, this file has been deleted',
  `who_deleted` int(11) DEFAULT NULL COMMENT 'admin.admin_id of who did the deletion'
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='detail table for custom_uploads: one record per file'
 
CREATE TABLE `custom_upload_thumbs` (
  `id` int(11) NOT NULL KEY AUTO_INCREMENT,
  `id_file`  int(11) NOT NULL COMMENT 'custom_upload_files.id',
  `filename` varchar(255) NOT NULL COMMENT 'filename.ext inside thumbs folder; generally "id-geometry.ext"',
  `size_x` int(11) DEFAULT NULL COMMENT 'pixel width of image',
  `size_y` int(11) DEFAULT NULL COMMENT 'pixel height of image',
  `request` varchar(255) NOT NULL COMMENT 'resizing request to match, for quick searching (id_upload + x + y)',
  `when_made` datetime NOT NULL COMMENT 'when thumbnail was generated'
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='record of thumbnails already created; used for thumbnail caching';

Note: a more ideal optimization would have a separate table for requests; this version will sometimes unnecessarily recreate thumbnail files, though at least it won't store more thumbnail files than necessary.

[edit] new folders

You will need to create the following folders and give them universal read/write permission (same as the images folder) in order for bulk uploads to work.

  • $zc/images/bulk
  • $zc/images/thumbs

[edit] Reference

Personal tools