Permalink
Browse files

developments

  • Loading branch information...
1 parent 4a3bcfa commit 3f6b7887bd528c9c31070e8d5f2361f8ee039036 @si4dev committed Apr 10, 2012
2 atk4
@@ -1 +1 @@
-Subproject commit 845ff4bb31b32d14767e8deda06fbfc05e0d1d59
+Subproject commit 1df8f051d102fccfc0afc06021bf8de527bb4c0c
View
112 lib/Actions/Image.php
@@ -30,4 +30,116 @@ function fileModified() {
function fileMd5() {
return md5_file($this->file);
}
+
+
+
+ function resizeImage($InputFile, $TargetFile, $MaxWidth, $MaxHeigth, $CompressionFactor = 80, $Type="Photo") {
+ if (strtolower (substr($TargetFile,-4))!=".jpg" && strtolower (substr($TargetFile,-5))!=".jpeg" && strtolower (substr($TargetFile,-4))!=".png") {
+ copy($InputFile, $TargetFile);
+ return Array('status'=>0, 'msg'=>"Not a valid image type for resizing. <BR/>Supported types are: JP(E)G and PNG.");
+ }
+ //Get Image size info
+ $info = @getimagesize( $InputFile );
+
+ if( $info === false )
+ return false;
+ else
+ switch ($info[2])
+ {
+ case 1:
+ if(($sourcefile_id = imagecreatefromgif($InputFile)) === false)
+ return Array('status'=>0, 'msg'=>"Not a valid GIF type.");
+ break;
+ case 2:
+ if(($sourcefile_id = imagecreatefromjpeg($InputFile)) === false)
+ return Array('status'=>0, 'msg'=>"Not a valid JPG type.");
+ break;
+ case 3:
+ if(($sourcefile_id = imagecreatefrompng($InputFile)) === false)
+ return Array('status'=>0, 'msg'=>"Not a valid PNG type.");
+ break;
+ case 6:
+ if(($sourcefile_id = imagecreatefrombmp($InputFile)) === false)
+ return Array('status'=>0, 'msg'=>"Not a valid BMP type.");
+ break;
+ default:
+ return Array('status'=>0, 'msg'=>"Not a valid type.");
+ }
+ // Get dimensions
+ $sourcefile_width=imageSX($sourcefile_id);
+ $sourcefile_height=imageSY($sourcefile_id);
+
+ // If Picture is smaller then $Max, do nothing:
+ if(($sourcefile_width < $MaxWidth) && ($sourcefile_height < $MaxHeigth) AND ($Type == "Photo")) {
+ copy($InputFile, $TargetFile);
+ } else {
+ // Calculate resizing factor in case of Thumb
+
+ if($Type == "Thumb") {
+ if($sourcefile_width >= $sourcefile_height) {
+ $SetWidth = $MaxWidth;
+ $onepercent = ($sourcefile_width / 100);
+ $factor = $SetWidth / $onepercent;
+ $SetHeight = ($sourcefile_height / 100) * $factor;
+ } else {
+ $SetHeight = $MaxHeigth;
+ $onepercent = ($sourcefile_height / 100);
+ $factor = $SetHeight / $onepercent;
+ $SetWidth = ($sourcefile_width / 100) * $factor;
+ }
+ // Make a new image
+ $Newsourcefile_id = ImageCreate($MaxWidth, $MaxHeigth);
+ // Format colors
+ $Newsourcefile_id = ImageCreateTrueColor($MaxWidth, $MaxHeigth);
+ // Calculate alignment
+ $leftalign = ($MaxWidth - $SetWidth) / 2;
+ $topalign = ($MaxHeigth - $SetHeight) / 2;
+ // Fill the rest with white color:
+ if($sourcefile_width > $sourcefile_height) {
+ // Horizontal Fill
+ $white = ImageColorAllocate ($Newsourcefile_id, 255, 255, 255);
+ ImageFilledRectangle($Newsourcefile_id, 0,0, $MaxWidth, $topalign, $white);
+ $bottomoffset = ($MaxHeigth - 1) - $topalign;
+ ImageFilledRectangle($Newsourcefile_id, 0,$bottomoffset, $MaxWidth, $MaxHeigth, $white);
+ } else {
+ // Vertical fill
+ $white = ImageColorAllocate ($Newsourcefile_id, 255, 255, 255);
+ ImageFilledRectangle($Newsourcefile_id,0,0,$leftalign,$MaxHeigth,$white);
+ $rightoffset = ($MaxWidth - 1) - $leftalign;
+ ImageFilledRectangle($Newsourcefile_id, $rightoffset,0,$MaxWidth,$MaxHeigth,$white);
+ }
+ } elseif($Type=="Photo") {
+ if($sourcefile_width >= $sourcefile_height) {
+ $SetWidth = $MaxWidth;
+ $onepercent = ($sourcefile_width / 100);
+ $factor = $SetWidth / $onepercent;
+ $SetHeight = ($sourcefile_height / 100) * $factor;
+ } else {
+ $SetHeight = $MaxHeigth;
+ $onepercent = ($sourcefile_height / 100);
+ $factor = $SetHeight / $onepercent;
+ $SetWidth = ($sourcefile_width / 100) * $factor;
+ }
+
+ // Make a new image
+ $Newsourcefile_id = ImageCreate($SetWidth, $SetHeight);
+ // Format colors
+ $Newsourcefile_id = ImageCreateTrueColor($SetWidth, $SetHeight);
+ // Calculate alignment
+ $leftalign = ($SetWidth - $SetWidth) / 2;
+ $topalign = ($SetHeight - $SetHeight) / 2;
+ }
+
+ // Create resampled and resized image
+ ImageCopyResampled($Newsourcefile_id,$sourcefile_id,$leftalign,$topalign,0,0,$SetWidth,$SetHeight,$sourcefile_width,$sourcefile_height);
+ // Create the Image
+
+ imagejpeg ($Newsourcefile_id,$TargetFile, $CompressionFactor);
+ return Array('status'=>1, 'msg'=>"");
+ }
+}
+
+
+
+
}
View
3 lib/FTP.php
@@ -60,7 +60,8 @@ function save() {
// from local source to ftp remote target
if( !@ftp_put($this->connection,$this->target,$this->source,$this->transfermode) ) {
throw $this->exception('FTP: cannot put')
- ->addMoreInfo('path',$path);
+ ->addMoreInfo('source',$this->source)
+ ->addMoreInfo('target',$this->target);
}
return $this;
}
View
20 lib/Model/Category.php
@@ -11,6 +11,10 @@ function init() {
$this->addField('CategoryShop');
$this->addField('CategorySupplierID');
$this->addField('CategoryShopID');
+
+
+
+// $this->addHook('beforeLoad',function($o){ unset($o->title); echo 'closure'; });
}
@@ -24,17 +28,21 @@ function init() {
'</title>');
*/
private function titleXml() {
- if( strpos($this->get('SupplierCategoryTitle'),'<node') ) {
- $titleXml=$this->get('SupplierCategoryTitle');
- } else {
+ $title=$this->get('SupplierCategoryTitle');
+ if( strpos($title,'<node') === false ) {
// in case the category is not yet in xml structure for old supplier import
- $titleXml='<cat lang="nl"><node>'.$this->get('SupplierCategoryTitle').'</node></cat>';
+ $title=trim($title)?:'-';
+ $this->title=new SimpleXMLElement('<title></title>');
+ $cat=$this->title->addChild('cat');
+ $cat->addAttribute('lang','nl');
+ $cat->{"node"}[]=$title; // this way XML is properly escaped, http://www.php.net/manual/en/simplexmlelement.addchild.php
+ } else {
+ $this->title=new SimpleXMLElement('<title>'.$title.'</title>');
}
- $this->title=new SimpleXMLElement('<title>'.$titleXml.'</title>');
}
function categoryByLang($iso) {
- if(!isset($this->title)) $this->titleXml();
+ $this->titleXml();
foreach( $this->title->cat as $cat ) {
if( (string)$cat['lang'] == $iso ) {
View
7 lib/Model/Pricelist.php
@@ -27,13 +27,16 @@ function init() {
If "name" field is not set in the related model, then the field will show "Record #n" instead.
You can specify a different field to expression by using 3th argument of hasOne();
*/
- $this->hasOne('Media','media_id','file');
-// $this->hasOne('Media');
+ $this->hasOne('Media','media_id','MediaFileModified');
}
// http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=E2+80+A2&mode=bytes
//
+ function image() {
+ return str_replace('/','_',$this->get('shop_productcode')).'.jpg';
+ }
+
function short_description() {
//echo "<pre>[short-".$this->get('id')."[[" . htmlentities($this->get('short_description')). "]]] </pre><br/><br/>";
View
342 lib/Model/Xcart.php
@@ -15,198 +15,246 @@ function import_categories() {
$cats->selectQuery(); // bug fix to get the model fields
$cats->dsql->where('CategoryShop',$this->get('name'))->where('CategoryShopID',-1);
// loop through the categories to be imported to the shop (not all, only needed ones)
+ $i=0;
foreach($cats as $cat) {
$defaultcat=$cats->categoryByLang('nl');
$level = 1; // not used for this xcart shop
$lastshopcatid = 0;
+ $shopcatpath='';
// loop through the levels of one category path (like breadcrumb)
foreach( $defaultcat->node as $title ) {
-
if( !(string)$title ) {
throw $this->exception('Shopassist: supplier title node empty')->addMoreInfo('Category ID',$cats->id);
}
-
+
$dsql=clone $shopcat->dsql;
// this will save or update or do nothing
// select `categoryid`,`category`,`parentid`,`lpos`,`rpos`,`order_by` from `xcart_categories` where `parentid` = 0 and `category` = "LED verlichting" limit 0, 1 [:a_2, :a]
// insert into `xcart_categories` (`category`,`parentid`) values ("LED verlichting",0) [:a_2, :a]
$shopcat->addCondition('parentid',$lastshopcatid)
->addCondition('category',(string)$title)
->tryLoadAny()
- ->save();
+ ->save()
+ ;
$lastshopcatid = $shopcat->get('categoryid');
+ // check if old xcart categoryid_path field is used
+ if( !$shopcat->tree ) {
+ if($shopcatpath) $shopcatpath.='/';
+ $shopcatpath.=$lastshopcatid;
+ $shopcat->set('categoryid_path',$shopcatpath)->save();
+ }
$shopcat->dsql=$dsql; // restore dsql as we added two conditions
$level++;
}
// due to bug we cannot save the join, ok the bug is solved by $this->data=$this->dsql->data in Model_Table,
// however you cannot use ->save() as it will not be possible to load again with condition CategoryShopID=-1
$cats->set('CategoryShopID',$lastshopcatid)->saveAndUnload();
+ $i++;
}
+ $this->nb_categories=$i;
// rebuild category tree of the shop to nicely set the lpos and rpos again
$shopcat->treeRebuild();
}
-
+ /*
+ performance: 600 per 100 seconds
+ images: 100 images in 15 seconds
+ */
+
function import() {
- $filepath=$this->api->getConfig('supplier_image_path');
- $tmp=$this->api->getConfig('tmp');
- $ftproot=parse_url($this->ftproot().'/');
- $imagespath=$this->imagespath().'/';
- $thumbspath=$this->thumbspath().'/';
- $shopimport_category=$this->category_import();
+ $this->i=0;
+ $this->i1=0;
+ $this->i2=0;
+
+ $filepath=$this->api->getConfig('supplier_image_path');
+ $tmp=$this->api->getConfig('tmp');
+ $ftproot=parse_url($this->ftproot().'/');
+ $imagespath=$this->imagespath().'/';
+ $thumbspath=$this->thumbspath().'/';
+ $shopimport_category=$this->category_import();
- // get the mysql connection for this specific shop
- $this->api->db2=$this->api->add('DB')->connect($this->connection());
-
- // get the time from mysql shop database which will be used later to disable products not longer updated
- $dsql2=$this->api->db2->dsql();
- $now=$dsql2->field($dsql2->expr('now()'))->getOne();
+ // get the mysql connection for this specific shop
+ $this->api->db2=$this->api->add('DB')->connect($this->connection());
+
+ // get the time from mysql shop database which will be used later to disable products not longer updated
+ $dsql2=$this->api->db2->dsql();
+ $now=$dsql2->field($dsql2->expr('now()'))->getOne();
- // get the extra field which is used to track which products are imported by shopimport
- $extra=$this->add('Model_Xcart_ExtraField');
- $extra->tryLoadAny();
- $extra->save();
- $fieldid=$extra->get('fieldid');
+ // get the extra field which is used to track which products are imported by shopimport
+ $extra=$this->add('Model_Xcart_ExtraField');
+ $extra->tryLoadAny();
+ $extra->save();
+ $fieldid=$extra->get('fieldid');
- // the product model for the target shop
- $m=$this->add('Model_Xcart_Product');
+ // the product model for the target shop
+ $m=$this->add('Model_Xcart_Product');
+
+ // prepare FTP connection for images
+ $ftp=$this->add('FTP');
+ $ftp->login($ftproot['host'],rawurldecode($ftproot['user']),$ftproot['pass']);
- // prepare FTP connection for images
- $ftp=$this->add('FTP');
- $ftp->login($ftproot['host'],rawurldecode($ftproot['user']),$ftproot['pass']);
+ // prepare image actions to be ready to retreive image information
+ $img=$this->add('Actions_Image');
+
+ // prepare media model
+ $media=$this->add('Model_Media');
+
+ // traverse through the pricelist and import each product one by one
+ $pricelist = $this->ref('Pricelist');
+ $pricelist->selectQuery(); // solves issue to get all fields and now it gets only applicable fields definined in model
+ $i=0;
+ foreach( $pricelist as $product ) {
+
+ if($i>=0) {
+ //echo 'product ['.$product['shop_productcode'].']';
+ // set the product fields
+ $m->tryLoadBy('productcode',$product['shop_productcode']);
+ $m->set('productcode',$product['shop_productcode']);
+ $m->set('product',$product['product_title']);
+ $m->set('weight',$product['weight']);
+ $m->set('descr',$pricelist->short_description());
+ $m->set('fulldescr',$pricelist->specification());
+ $m->set('avail',$product['stock']);
+ $m->set('add_date',strtotime($product['entry_date']));
+ $m->set('list_price',$product['price']);
+ $m->save();
+
+ // handle pricing
+ $pricing=$m->ref('Xcart_Pricing');
+ //$pricing->dsql()->do_delete()->debug();
+ $pricing->tryLoadAny();
+ $pricing->set('price',$product['price']);
+ $pricing->save(); // do not use saveAndUnload as values are needed later!
+
+ $quickprices=$m->ref('Xcart_QuickPrices');
+ $quickprices->tryLoadAny();
+ $quickprices->set('priceid',$pricing->get('priceid'));
+ $quickprices->saveAndUnload();
- // prepare image actions to be ready to retreive image information
- $img=$this->add('Actions_Image');
-
- // prepare media model
- $media=$this->add('Model_Media');
+ // handle category
+ $category=$m->ref('Xcart_ProductCategory');
+ $found=false;
+ foreach( $category as $cat ) {
+ if( $cat['categoryid'] == $product['shop_category_id'] ) {
+ $found = true;
+ } else {
+ $category->delete();
+ }
+ }
+ if( !$found ) {
+ $category->set('categoryid',$product['shop_category_id'])->save();
+ }
+
+ // media file
+ $filename='';
+ $imagep=$m->ref('Xcart_ImageP');
+ $imagep->tryLoadAny();
+ $media_modified=$product['media'];
+ // check if image available and not already uploaded
- // traverse through the pricelist and import each product one by one
- $pricelist = $this->ref('Pricelist');
- $pricelist->selectQuery(); // solves issue to get all fields and now it gets only applicable fields definined in model
- $i=0;
- foreach( $pricelist as $product ) {
+ if($media_modified and strtotime($media_modified) != $imagep->get('date')) {
+ // get filename from media table
+ $media->load($product['media_id']);
+ $filename=$media->get('file');
+ echo'file ['.$filename.']';
+ $shopfilename=$pricelist->image();
- // set the product fields
- $m->tryLoadBy('productcode',$product['shop_productcode']);
- $m->set('productcode',$product['shop_productcode']);
- $m->set('product',$product['product_title']);
- $m->set('weight',$product['weight']);
- $m->set('descr',$pricelist->short_description());
- $m->set('fulldescr',$pricelist->specification());
- $m->set('avail',$product['stock']);
- $m->set('add_date',strtotime($product['entry_date']));
- $m->set('list_price',$product['price']);
- $m->save();
-
- // handle pricing
- $pricing=$m->ref('Xcart_Pricing');
- //$pricing->dsql()->do_delete()->debug();
- $pricing->tryLoadAny();
- $pricing->set('price',$product['price']);
- $pricing->save();
-
- $quickprices=$m->ref('Xcart_QuickPrices');
- $quickprices->tryLoadAny();
- $quickprices->set('priceid',$pricing->get('priceid'));
- $quickprices->save();
-
- // handle category
- $category=$m->ref('Xcart_ProductCategory');
- $found=false;
- foreach( $category as $cat ) {
- if( $cat['categoryid'] == $product['shop_category_id'] ) {
- $found = true;
- } else {
- $category->delete();
- }
+ // overrule filename for development as we don't have the file library
+ if( $this->api->getConfig('mode')=='dev') {
+ $filename='test.jpg';
}
- if( !$found ) {
- $category->set('categoryid',$product['shop_category_id'])->save();
- }
-
- // media file
- $filename='';
- $imagep=$m->ref('Xcart_ImageP');
- $imagep->tryLoadAny();
- $media_modified=$product['media'];
- // check if image available and not already uploaded
- if($media_modified and strtotime($media_modified) != $imagep->get('date')) {
- // get filename from media table
- $media->load($product['media_id']);
- $filename=$media->get('file');
- $shopfilename=$product['shop_productcode'].'.jpg';
- // overrule filename for development as we don't have the file library
- if( $this->api->getConfig('mode')=='dev') {
- $filename='test.jpg';
- }
+ // handle image
+ //copy($filepath.$filename,$tmp.$shopfilename);
+ $s=microtime(true);
+ $img->resizeImage($filepath.$filename, $tmp.$shopfilename, 1024, 1024, 90, 'Thumb');
+ //shell_exec('convert -define jpeg:size=2048x2048 "'.$filepath.$filename.'" -resize 1024x1024 "'.$tmp.$shopfilename.'"');
+ $this->i1+=(microtime(true)-$s);
+ if( $this->api->getConfig('mode')!='dev') {
+ $ftp->cd($ftproot['path'].$imagespath)
+ ->setSource($tmp.$shopfilename)
+ ->setTarget($shopfilename)
+ ->save();
+ }
+ // img action to get image info like widht height etc
+ $img->setFile($filepath.$filename);
+ $imagep->set('filename',$shopfilename);
+ $imagep->set('image_path',$imagespath.$shopfilename);
+ $imagep->set('image_x',$img->imgWidth());
+ $imagep->set('image_y',$img->imgHeight());
+ $imagep->set('image_size',$img->fileSize());
+ $imagep->set('date',strtotime($media_modified));
+ $imagep->set('md5',$img->fileMd5());
+ $imagep->saveAndUnload();
+
+ // handle thumbs
+ if( $this->api->getConfig('mode')!='dev') {
+ $this->i++;
+ $s=microtime(true);
+ $img->resizeImage($filepath.$filename, $tmp.$shopfilename, 140, 140, 90, 'Thumb');
+ //shell_exec('convert -define jpeg:size=250x250 "'.$filepath.$filename.'" -thumbnail 125x125^ "'.$tmp.$shopfilename.'"');
+ $this->i2+=(microtime(true)-$s);
+ $ftp->cd($ftproot['path'].$thumbspath)
+ ->setSource($tmp.$shopfilename)
+ ->setTarget($shopfilename)
+ ->save();
+ }
- // handle image
- //copy($filepath.$filename,$tmp.$shopfilename);
- shell_exec('convert -define jpeg:size=2048x2048 '.$filepath.$filename.' -resize 1024x1024 '.$tmp.$shopfilename);
- if( $this->api->getConfig('mode')!='dev') {
- $ftp->cd($ftproot['path'].$imagespath)
- ->setSource($tmp.$shopfilename)
- ->setTarget($shopfilename)
- ->save();
- }
+ $img->setFile($filepath.$filename);
+ $imaget=$m->ref('Xcart_ImageT');
+ $imaget->tryLoadAny();
+ $imaget->set('filename',$filename);
+ $imaget->set('image_path',$thumbspath.$shopfilename);
+ $imaget->set('image_x',$img->imgWidth());
+ $imaget->set('image_y',$img->imgHeight());
+ $imaget->set('image_size',$img->fileSize());
+ $imaget->set('date',strtotime($media_modified));
+ $imaget->set('md5',$img->fileMd5());
+ $imaget->saveAndUnload();
+
+ unlink($tmp.$shopfilename);
+ }
- // img action to get image info like widht height etc
- $img->setFile($filepath.$filename);
- $imagep->set('filename',$filename);
- $imagep->set('image_path',$imagespath.$shopfilename);
- $imagep->set('image_x',$img->imgWidth());
- $imagep->set('image_y',$img->imgHeight());
- $imagep->set('image_size',$img->fileSize());
- $imagep->set('date',strtotime($media_modified));
- $imagep->set('md5',$img->fileMd5());
- $imagep->save();
-
- // handle thumbs
- if( $this->api->getConfig('mode')!='dev') {
- //echo shell_exec('convert -define jpeg:size=250x250 '.$filepath.$filename.' -thumbnail 125x125^ -gravity center -extent 125x125 '.$tmp.$shopfilename);
- shell_exec('convert -define jpeg:size=250x250 '.$filepath.$filename.' -thumbnail 125x125^ '.$tmp.$shopfilename);
- $ftp->cd($ftproot['path'].$thumbspath)
- ->setSource($tmp.$shopfilename)
- ->setTarget($shopfilename)
- ->save();
- }
+ // handle quick flags
+ $quickflags=$m->ref('Xcart_QuickFlags');
+ $quickflags->tryLoadAny();
+ if($filename) {
+ $quickflags->set('image_path_T',$thumbspath.$shopfilename);
+ }
+ $quickflags->saveAndUnload();
+
+ // handle extra field value to know it's a shopimport product
+$s1=microtime(true);
+ $extravalue=$m->ref('Xcart_ExtraFieldValue');
+$s2=microtime(true);
+ $extravalue->tryLoadBy('fieldid',$fieldid);
+ $extravalue->set('value',$now);
+ $extravalue->saveAndUnload();
+// $extravalue->destroy();
+}
- $img->setFile($filepath.$filename);
- $imaget=$m->ref('Xcart_ImageT');
- $imaget->tryLoadAny();
- $imaget->set('filename',$filename);
- $imaget->set('image_path',$thumbspath.$shopfilename);
- $imaget->set('image_x',$img->imgWidth());
- $imaget->set('image_y',$img->imgHeight());
- $imaget->set('image_size',$img->fileSize());
- $imaget->set('date',strtotime($media_modified));
- $imaget->set('md5',$img->fileMd5());
- $imaget->save();
-
- unlink($tmp.$shopfilename);
- }
+$s+=$s2-$s1;
- // handle quick flags
- $quickflags=$m->ref('Xcart_QuickFlags');
- $quickflags->tryLoadAny();
- if($filename) {
- $quickflags->set('image_path_T',$thumbspath.$shopfilename);
+ if( ($i / 100) == round($i/100) ) {
+ if(!isset($starttime)) {
+ $starttime=microtime(true);
}
- $quickflags->save();
-
- // handle extra field value to know it's a shopimport product
- $extravalue=$m->ref('Xcart_ExtraFieldValue');
- $extravalue->tryLoadBy('fieldid',$fieldid);
- $extravalue->set('value',$now);
- $extravalue->save();
-
- $i++;
- if( $i >= 20 ) break;
+ $mem[$i]=ini_get("memory_limit")."; ".round(memory_get_peak_usage() / (1024 * 1024),3). "M; ". round(memory_get_usage() / (1024 * 1024), 3). "M; ".round(microtime(true)-$starttime,3)."s; ".round($s,3)."s";
+ $starttime=microtime(true);
+ $s=0;
}
- $this->nb_products=$i;
+ if( $i >= 1000000 ) break;
+ $i++;
+ }
+/* echo "<pre>";
+ var_dump($mem);
+ echo "</pre>";
+
+ echo 'timing ['.$this->i.']['.$this->i1.']['.$this->i2.']';
+*/
+ $this->nb_products=$i;
}
+
}
View
18 lib/Model/Xcart/Category.php
@@ -8,15 +8,29 @@ function init() {
parent::init();
$this->addField('category');
$this->addField('parentid');
- $this->addField('lpos');
- $this->addField('rpos');
+
+
+ $res=$this->api->db2->query("show columns from xcart_categories like 'lpos'")->fetch();
+ $this->tree=$res[0]=='lpos'?true:false;
+ if($this->tree) {
+ $this->addField('lpos');
+ $this->addField('rpos');
+ } else {
+ $this->addField('categoryid_path');
+ }
$this->addField('order_by')->type('int');
// $this->hasOne('Xcart_Category','parentid');
$this->hasMany('Xcart_Category','parentid');
+
+
}
+
function treeRebuild($left = 0) {
+ if(!$this->tree) {
+ return $this;
+ }
$right = $left + 1;
if($left==0) {
// main call has no initial load() so we need to setup all parent=0 records
View
2 lib/Model/Xcart/ExtraField.php
@@ -9,7 +9,7 @@ function init() {
$this->addField('field')->defaultValue('Shopimport');
$this->addField('service_name');
$this->setMasterField('service_name','SHOPIMPORT');
-// $this->hasMany('Xcart_Product','filedid');
+ $this->addField('active')->defaultValue('N');
}
}
View
36 page/demo.php
@@ -4,13 +4,31 @@ class page_demo extends Page {
function init() {
parent::init();
- $c=$this->add('CRUD');
- $c->setModel('Model_Shop');
- if ($c->grid){
-
- $c->grid->addQuickSearch(array('name'));
- $c->grid->addPaginator(10);
- }
+
+ $sql="CREATE TABLE IF NOT EXISTS `demo` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `productcode` varchar(250) NOT NULL DEFAULT '',
+ `price` double NOT NULL,
+ PRIMARY KEY (`id`)
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8";
+// $q=$this->api->db->query($sql);
+
+ $m=$this->add('Model_Demo');
+ $m->tryLoadBy('productcode','123');
+ $m->set('price',1000);
+ $m->save();
+ $m->tryLoadBy('productcode','124');
+ $m->set('price',1001);
+ $m->save();
+ }
+}
+
+class Model_Demo extends Model_Table {
+ public $table='demo';
+ function init() {
+ parent::init();
+ $this->debug();
+ $this->addField('productcode');
+ $this->addField('price');
}
-
-}
+}
View
26 page/pricelist.php
@@ -19,18 +19,36 @@ function init() {
if( $shop_id=$_GET['shop'] ) {
+ $starttime=microtime(true);
+
+
+ // -------------------------------------------------------------------------------------------------
+ // set the script memory limit
+ if(isset($memory_limit)) {
+ ini_set("memory_limit", $memory_limit);
+ }
+ // -------------------------------------------------------------------------------------------------
+ // set the script timeout and database timeeout
+ $timeout='6000';
+ if( isset($timeout) ) {
+ set_time_limit($timeout);
+ ini_set('default_socket_timeout', ini_get('max_execution_time'));
+ }
+
+
$this->add('Text')->set('shop '.$shop_id);
$shop = $this->add('Model_Shop');
$shop->load($shop_id);
// temp solution for old database structure
if($supplier=$shop->category_import()) {
+ $this->add('P')->set('look for supplier categories to import ['.$supplier.']');
$sql="insert ignore into tbltype_category (categoryshop,categorysupplierid,categoryshopid)
select '".$shop->get('name')."', c.`SupplierCategoryId`,-1 from tbltype_suppliercategory c
inner join tbldata_product p on (p.`ProductCategoryID` = c.`SupplierCategoryId`)
inner join watch w on (w.`WatchProductID`=p.`ProductID`)
inner join supplier s on (s.`SupplierName`=p.`ProductSupplier`)
- where w.`WatchLastChecked` >= s.`SupplierImportFull` and s.suppliername = 'gistron'
+ where w.`WatchLastChecked` >= s.`SupplierImportFull` and s.suppliername = '".$supplier."'
group by c.`SupplierCategoryId`";
$cat = $this->api->db->query($sql);
}
@@ -40,10 +58,16 @@ function init() {
// load specific shop system
$shop = $this->add('Model_'.$shopsystem);
$shop->load($shop_id)->import_categories();
+ $this->add('P')->set('Imported categories: '.$shop->nb_categories);
+ $starttime2=microtime(true);
$shop->load($shop_id)->import();
+ $starttime3=microtime(true);
$this->add('P')->set('Imported products: '.$shop->nb_products);
} else {
$this->add('Text')->set('no shop selected');
}
+ $this->add('P')->set('Took before ['.round($starttime2-$starttime,3).'] seconds');
+ $this->add('P')->set('Took import ['.round($starttime3-$starttime2,3).'] seconds');
+ $this->add('P')->set('Took after ['.round(microtime(true)-$starttime3,3).'] seconds');
}
}
View
50 templates/default/shared.html
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <title><?page_title?>Agile Toolkit<?/?></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <link rel="shortcut icon" href="<?template?>images/favicon.ico<?/?>" type="image/x-icon" />
+ <link rel="shortcut icon" href="<?template?>images/favicon.ico<?/?>" />
+ <link rel="stylesheet" type="text/css" href="<?template?>css/jquery-ui.css<?/?>" />
+ <link rel="stylesheet" type="text/css" href="<?template?>css/atk-main.css<?/?>" />
+ <link rel="stylesheet" type="text/css" href="<?template?>css/atk-custom.css<?/?>" />
+ <?$js_include?>
+ <!--[if lt IE 9]>
+ <script src="<?template?>css/ie.js<?/?>"></script>
+ <![endif]-->
+ <script type="text/javascript">
+ $(function(){
+ <?$document_ready?>
+ });
+ </script>
+ </head>
+ <body>
+ <div id="atk-layout" class="atk-wrapper">
+ <div id="header">
+ <?logo?><div id="atk-logo" class="ui-widget-header float-left"><a
+ href="<?page?>index<?/?>"><img src="<?template?>images/logo.png<?/?>" /></a></div><?/logo?>
+ <div id="header-right">
+ <?Menu?>
+ <div class="atk-menu atk-menu-horizontal ui-widget">
+ <ul>
+ <li class="ui-state-default"><a href="javascript:void(0)">Menu is not defined</a></li>
+ </ul>
+ </div>
+ <?/?>
+ <div id="atk-version"><b><?name?><?/?></b><br/><i><?$version?></i></div>
+ </div>
+ </div>
+ <?$Content?>
+ <div id="atk-footer-guard"></div>
+ </div>
+ <?Footer?>
+ <div id="footer" class="atk-wrapper">
+ <?footer_text?>
+ Powered by <a href="http://shopimport.nl/">Shopimport</a>. &copy; 2012
+ <a href="http://agiletoolkit.org/about/license"></a>
+ <?/?>
+ </div>
+ <?/?>
+ <div id="atk-growl-holder" class="atk-growl"></div>
+ </body>
+</html>

0 comments on commit 3f6b788

Please sign in to comment.