/** * Loads specified relational data associated with the product * * @since 1.1 * * @param array $options List of data to load (prices, images, categories, tags, specs) * @param array $products List of products to load data for * @return void **/ function load_data ($options=false,&$products=false) { global $Ecart; $db =& DB::get(); // Load object schemas on request $catalogtable = DatabaseObject::tablename(Catalog::$table); $Dataset = array(); if (in_array('prices',$options)) { $this->prices = array(); $promotable = DatabaseObject::tablename(Promotion::$table); $discounttable = DatabaseObject::tablename(Discount::$table); $assettable = DatabaseObject::tablename(ProductDownload::$table); $Dataset['prices'] = new Price(); $Dataset['prices']->_datatypes['promos'] = "MAX(promo.status)"; $Dataset['prices']->_datatypes['promotions'] = "group_concat(promo.name)"; $Dataset['prices']->_datatypes['percentoff'] = "SUM(IF (promo.type='Percentage Off',promo.discount,0))"; $Dataset['prices']->_datatypes['amountoff'] = "SUM(IF (promo.type='Amount Off',promo.discount,0))"; $Dataset['prices']->_datatypes['freeshipping'] = "SUM(IF (promo.type='Free Shipping',1,0))"; $Dataset['prices']->_datatypes['buyqty'] = "IF (promo.type='Buy X Get Y Free',promo.buyqty,0)"; $Dataset['prices']->_datatypes['getqty'] = "IF (promo.type='Buy X Get Y Free',promo.getqty,0)"; $Dataset['prices']->_datatypes['download'] = "download.id"; $Dataset['prices']->_datatypes['filename'] = "download.name"; $Dataset['prices']->_datatypes['filedata'] = "download.value"; } if (in_array('images',$options)) { $this->images = array(); $Dataset['images'] = new ProductImage(); array_merge($Dataset['images']->_datatypes,$Dataset['images']->_xcols); } if (in_array('categories',$options)) { $this->categories = array(); $Dataset['categories'] = new Category(); unset($Dataset['categories']->_datatypes['priceranges']); unset($Dataset['categories']->_datatypes['specs']); unset($Dataset['categories']->_datatypes['options']); unset($Dataset['categories']->_datatypes['prices']); } if (in_array('specs',$options)) { $this->specs = array(); $Dataset['specs'] = new Spec(); } if (in_array('tags',$options)) { $this->tags = array(); $Dataset['tags'] = new Tag(); } // Determine the maximum columns to allocate $maxcols = 0; foreach ($Dataset as $set) { $cols = count($set->_datatypes); if ($cols > $maxcols) $maxcols = $cols; } // Prepare product list depending on single product or entire list $ids = array(); if (isset($products) && is_array($products)) { foreach ($products as $product) $ids[] = $product->id; } else $ids[0] = $this->id; // Skip if there are no product ids if (empty($ids) || empty($ids[0])) return false; // Build the mega-query foreach ($Dataset as $rtype => $set) { // Allocate generic columns for record data $columns = array(); $i = 0; foreach ($set->_datatypes as $key => $datatype) $columns[] = ((strpos($datatype,'.')!==false)?"$datatype":"{$set->_table}.$key")." AS c".($i++); for ($i = $i; $i < $maxcols; $i++) $columns[] = "'' AS c$i"; $cols = join(',',$columns); // Build object-specific selects and UNION them $where = ""; if (isset($query)) $query .= " UNION "; else $query = ""; switch($rtype) { case "prices": foreach ($ids as $id) $where .= ((!empty($where))?" OR ":"")."$set->_table.product=$id"; $query .= "(SELECT '$set->_table' as dataset,$set->_table.product AS product,'$rtype' AS rtype,'' AS alphaorder,$set->_table.sortorder AS sortorder,$cols FROM $set->_table LEFT JOIN $assettable AS download ON $set->_table.id=download.parent AND download.context='price' AND download.type='download' LEFT JOIN $discounttable AS discount ON discount.product=$set->_table.product AND discount.price=$set->_table.id LEFT JOIN $promotable AS promo ON promo.id=discount.promo AND (promo.status='enabled' AND ((UNIX_TIMESTAMP(starts)=1 AND UNIX_TIMESTAMP(ends)=1) OR (".time()." > UNIX_TIMESTAMP(starts) AND ".time()." < UNIX_TIMESTAMP(ends)) OR (UNIX_TIMESTAMP(starts)=1 AND ".time()." < UNIX_TIMESTAMP(ends)) OR (".time()." > UNIX_TIMESTAMP(starts) AND UNIX_TIMESTAMP(ends)=1) )) WHERE $where GROUP BY $set->_table.id)"; break; case "images": $ordering = $Ecart->Settings->get('product_image_order'); if (empty($ordering)) $ordering = "ASC"; $orderby = $Ecart->Settings->get('product_image_orderby'); $sortorder = "0"; if ($orderby == "sortorder" || $orderby == "created") { if ($orderby == "created") $orderby = "UNIX_TIMESTAMP(created)"; switch ($ordering) { case "DESC": $sortorder = "$orderby*-1"; break; case "RAND": $sortorder = "RAND()"; break; default: $sortorder = "$orderby"; } } $alphaorder = "''"; if ($orderby == "name") { switch ($ordering) { case "DESC": $alphaorder = "$orderby"; break; case "RAND": $alphaorder = "RAND()"; break; default: $alphaorder = "$orderby"; } } foreach ($ids as $id) $where .= ((!empty($where))?" OR ":"")."parent=$id"; $where = "($where) AND context='product' AND type='image'"; $query .= "(SELECT '$set->_table' as dataset,parent AS product,'$rtype' AS rtype,$alphaorder AS alphaorder,$sortorder AS sortorder,$cols FROM $set->_table WHERE $where ORDER BY $orderby)"; break; case "specs": foreach ($ids as $id) $where .= ((!empty($where))?" OR ":"")."parent=$id AND context='product' AND type='spec'"; $query .= "(SELECT '$set->_table' as dataset,parent AS product,'$rtype' AS rtype,'' AS alphaorder,sortorder AS sortorder,$cols FROM $set->_table WHERE $where)"; break; case "categories": foreach ($ids as $id) $where .= ((!empty($where))?" OR ":"")."catalog.product=$id"; $where = "($where) AND catalog.type='category'"; $query .= "(SELECT '$set->_table' as dataset,catalog.product AS product,'$rtype' AS rtype,$set->_table.name AS alphaorder,0 AS sortorder,$cols FROM $catalogtable AS catalog LEFT JOIN $set->_table ON catalog.parent=$set->_table.id AND catalog.type='category' WHERE $where)"; break; case "tags": foreach ($ids as $id) $where .= ((!empty($where))?" OR ":"")."catalog.product=$id"; $where = "($where) AND catalog.type='tag'"; $query .= "(SELECT '$set->_table' as dataset,catalog.product AS product,'$rtype' AS rtype,$set->_table.name AS alphaorder,0 AS sortorder,$cols FROM $catalogtable AS catalog LEFT JOIN $set->_table ON catalog.parent=$set->_table.id AND type='tag' WHERE $where)"; break; } } // Add order by columns $query .= " ORDER BY sortorder"; // die($query); // Execute the query $data = $db->query($query,AS_ARRAY); // Process the results into specific product object data in a product set foreach ($data as $row) { if (is_array($products) && isset($products[$row->product])) $target = $products[$row->product]; else $target = $this; $record = new stdClass(); $i = 0; $name = ""; foreach ($Dataset[$row->rtype]->_datatypes AS $key => $datatype) { $column = 'c'.$i++; $record->{$key} = ''; if ($key == "name") $name = $row->{$column}; if (!empty($row->{$column})) { if (preg_match("/^[sibNaO](?:\:.+?\{.*\}$|\:.+;$|;$)/",$row->{$column})) $row->{$column} = unserialize($row->{$column}); $record->{$key} = $row->{$column}; } } if ($row->rtype == "images") { $image = new ProductImage(); $image->copydata($record,false,array()); $image->expopulate(); $name = $image->filename; $record = $image; // Reset the product's loaded images if the image was already // loaded from another context (like Category::load_products()) if (isset($target->{$row->rtype}[0]) && $target->{$row->rtype}[0]->id == $image->id) $target->{$row->rtype} = array(); } $target->{$row->rtype}[] = $record; if (!empty($name)) { if (isset($target->{$row->rtype.'key'}[$name])) $target->{$row->rtype.'key'}[$name] = array($target->{$row->rtype.'key'}[$name],$record); else $target->{$row->rtype.'key'}[$name] = $record; } } if (is_array($products)) { foreach ($products as $product) if (!empty($product->prices)) $product->pricing(); } else { if (!empty($this->prices)) $this->pricing($options); } } // end load_data()
/** * Loads a list of products for the category * * @since 1.0 * @version 1.1 * * @param array $loading Loading options for the category * @return void **/ function load_products ($loading=false) { global $Ecart,$wp; $db = DB::get(); $catalogtable = DatabaseObject::tablename(Catalog::$table); $producttable = DatabaseObject::tablename(Product::$table); $pricetable = DatabaseObject::tablename(Price::$table); $discounttable = DatabaseObject::tablename(Discount::$table); $promotable = DatabaseObject::tablename(Promotion::$table); $imagetable = DatabaseObject::tablename(ProductImage::$table); $this->paged = false; $this->pagination = $Ecart->Settings->get('catalog_pagination'); $this->page = (get_query_var('paged') > 0)?get_query_var('paged'):1; if (empty($this->page)) $this->page = 1; $limit = 1000; // Hard product limit per category to keep resources "reasonable" if (!$loading) $loading = $this->loading; else $loading = array_merge($this->loading,$loading); if (!empty($loading['columns'])) $loading['columns'] = ", ".$loading['columns']; else $loading['columns'] = ''; // Allow override for loading unpublished products if (isset($loading['published'])) $this->published = value_is_true($loading['published']); $where = array(); if (!empty($loading['where'])) $where[] = "({$loading['where']})"; $having = array(); if (!empty($loading['having'])) $having[] = "({$loading['having']})"; // Handle default WHERE clause matching this category id if (empty($loading['where']) && !empty($this->id)) $where[] = "p.id in (SELECT product FROM $catalogtable WHERE (parent=$this->id AND type='category'))"; if (!isset($loading['nostock']) && ($Ecart->Settings->get('outofstock_catalog') == "off")) $where[] = "p.id in (SELECT product FROM $pricetable WHERE type != 'N/A' AND inventory='off' OR (inventory='on' AND stock > 0))"; else $where[] = "p.id in (SELECT product FROM $pricetable WHERE type != 'N/A')"; if (!isset($loading['joins'])) $loading['joins'] = ''; if (!empty($Ecart->Flow->Controller->browsing[$this->slug])) { $spectable = DatabaseObject::tablename(Spec::$table); $f = 1; $filters = ""; foreach ($Ecart->Flow->Controller->browsing[$this->slug] as $facet => $value) { if (empty($value)) continue; $specalias = "spec".($f++); // Handle Number Range filtering $match = ""; if (!is_array($value) && preg_match('/^.*?(\d+[\.\,\d]*).*?\-.*?(\d+[\.\,\d]*).*$/',$value,$matches)) { if ($facet == "Price") { // Prices require complex matching on price line entries $min = floatvalue($matches[1]); $max = floatvalue($matches[2]); if ($matches[1] > 0) $match .= " ((onsale=0 AND (minprice >= $min OR maxprice >= $min)) OR (onsale=1 AND (minsaleprice >= $min OR maxsaleprice >= $min)))"; if ($matches[2] > 0) $match .= (empty($match)?"":" AND ")." ((onsale=0 AND (minprice <= $max OR maxprice <= $max)) OR (onsale=1 AND (minsaleprice <= $max OR maxsaleprice <= $max)))"; } else { // Spec-based numbers are somewhat more straightforward if ($matches[1] > 0) $match .= "$specalias.numeral >= {$matches[1]}"; if ($matches[2] > 0) $match .= (empty($match)?"":" AND ")."$specalias.numeral <= {$matches[2]}"; } } else $match = "$specalias.value='$value'"; // No range, direct value match // Use HAVING clause for filtering by pricing information // because of data aggregation if ($facet == "Price") { $having[] = $match; continue; } $loading['joins'] .= " LEFT JOIN $spectable AS $specalias ON $specalias.parent=p.id AND $specalias.context='product' AND $specalias.type='spec' AND $specalias.name='$facet'"; $filters .= (empty($filters))?$match:" AND ".$match; } if (!empty($filters)) $where[] = $filters; } // WP TZ setting based time - (timezone offset:[PHP UTC adjusted time - MySQL UTC adjusted time]) $now = time()."-(".(time()-date("Z",time()))."-UNIX_TIMESTAMP(UTC_TIMESTAMP()))"; if ($this->published) $where[] = "(p.status='publish' AND $now >= UNIX_TIMESTAMP(p.publish))"; else $where[] = "(p.status!='publish' OR $now < UNIX_TIMESTAMP(p.publish))"; $defaultOrder = $Ecart->Settings->get('default_product_order'); if (empty($defaultOrder)) $defaultOrder = ""; $ordering = isset($Ecart->Flow->Controller->browsing['orderby'])? $Ecart->Flow->Controller->browsing['orderby']:$defaultOrder; if (!empty($loading['order'])) $ordering = $loading['order']; switch ($ordering) { case "bestselling": $purchasedtable = DatabaseObject::tablename(Purchased::$table); $loading['columns'] .= ',count(DISTINCT pur.id) AS sold'; $loading['joins'] .= " LEFT JOIN $purchasedtable AS pur ON p.id=pur.product"; $loading['order'] = "sold DESC,p.name ASC"; break; case "highprice": $loading['order'] = "highprice DESC"; break; case "lowprice": $loading['order'] = "lowprice ASC"; break; case "newest": $loading['order'] = "p.publish DESC,p.name ASC"; break; case "oldest": $loading['order'] = "p.publish ASC,p.name ASC"; break; case "random": $loading['order'] = "RAND(".crc32($Ecart->Shopping->session).")"; break; case "title": $loading['order'] = "p.name ASC"; break; default: // Need to add the catalog table for access to category-product priorities if (!isset($this->smart)) { $loading['joins'] .= " LEFT JOIN $catalogtable AS c ON c.product=p.id AND c.parent = '$this->id'"; $loading['order'] = "c.priority ASC,p.name ASC"; } else $loading['order'] = "p.name ASC"; break; } if (!empty($loading['orderby'])) $loading['order'] = $loading['orderby']; if (isset($loading['adjacent']) && isset($loading['product'])) { $product = $loading['product']; $field = substr($loading['order'],0,strpos($loading['order'],' ')); $op = $loading['adjacent'] != "next"?'<':'>'; // Flip the sort order for previous if ($op == '<') { $loading['order'] = str_replace(array('ASC','DESC'),array('DSC','ACE'),$loading['order']); $loading['order'] = str_replace(array('DSC','ACE'),array('DESC','ASC'),$loading['order']); } switch ($field) { case "sold": if ($product->sold() == 0) { $field = 'p.name'; $target = "'".$db->escape($product->name)."'"; } else $target = $product->sold(); $where[] = "$field $op $target"; break; case "highprice": if (empty($product->prices)) $product->load_data(array('prices')); $target = !empty($product->max['saleprice'])?$product->max['saleprice']:$product->max['price']; $where[] = "$target $op IF (pd.sale='on' OR pr.discount>0,pd.saleprice,pd.price) AND p.id != $product->id"; break; case "lowprice": if (empty($product->prices)) $product->load_data(array('prices')); $target = !empty($product->max['saleprice'])?$product->max['saleprice']:$product->max['price']; $where[] = "$target $op= IF (pd.sale='on' OR pr.discount>0,pd.saleprice,pd.price) AND p.id != $product->id"; break; case "p.name": $where[] = "$field $op '".$db->escape($product->name)."'"; break; default: if ($product->priority == 0) { $field = 'p.name'; $target = "'".$db->escape($product->name)."'"; } else $target = $product->priority; $where[] = "$field $op $target"; break; } } if (!empty($having)) $loading['having'] = "HAVING ".join(" AND ",$having); else $loading['having'] = ''; $loading['where'] = join(" AND ",$where); if (empty($loading['limit'])) { if ($this->pagination > 0 && is_numeric($this->page)) { if( !$this->pagination || $this->pagination < 0 ) $this->pagination = $limit; $start = ($this->pagination * ($this->page-1)); $loading['limit'] = "$start,$this->pagination"; } else $loading['limit'] = $limit; } else $limit = (int)$loading['limit']; $columns = "p.*, img.id AS image,img.value AS imgmeta,MAX(pr.status) as promos, SUM(DISTINCT IF(pr.type='Percentage Off',pr.discount,0))AS percentoff, SUM(DISTINCT IF(pr.type='Amount Off',pr.discount,0)) AS amountoff, if (pr.type='Free Shipping',1,0) AS freeshipping, if (pr.type='Buy X Get Y Free',pr.buyqty,0) AS buyqty, if (pr.type='Buy X Get Y Free',pr.getqty,0) AS getqty, MAX(pd.price) AS maxprice,MIN(pd.price) AS minprice, IF(pd.sale='on',1,IF (pr.discount > 0,1,0)) AS onsale, MAX(pd.saleprice) as maxsaleprice,MIN(pd.saleprice) AS minsaleprice, IF (pd.sale='on' AND MIN(pd.saleprice) > 0,MIN(pd.saleprice),MIN(pd.price)) AS lowprice, IF (pd.sale='on' AND MIN(pd.saleprice) > 0,MAX(pd.saleprice),MAX(pd.price)) AS highprice, IF(pd.inventory='on',1,0) AS inventory, SUM(pd.stock) as stock"; // Query without promotions for MySQL servers prior to 5 if (version_compare($db->mysql,'5.0','<')) { $columns = "p.*, img.id AS image,img.value AS imgmeta, MAX(pd.price) AS maxprice,MIN(pd.price) AS minprice, IF(pd.sale='on',1,0) AS onsale, MAX(pd.saleprice) as maxsaleprice,MIN(pd.saleprice) AS minsaleprice, IF(pd.inventory='on',1,0) AS inventory, SUM(pd.stock) as stock"; } // Handle alphabetic page requests if ((!isset($Ecart->Category->controls) || (isset($Ecart->Category->controls) && $Ecart->Category->controls !== false)) && ((isset($loading['pagination']) && $loading['pagination'] == "alpha") || !is_numeric($this->page))) { $alphanav = range('A','Z'); $ac = "SELECT count(DISTINCT p.id) AS total,IF(LEFT(p.name,1) REGEXP '[0-9]',LEFT(p.name,1),LEFT(SOUNDEX(p.name),1)) AS letter,AVG(IF(pd.sale='on',pd.saleprice,pd.price)) as avgprice FROM $producttable AS p LEFT JOIN $pricetable AS pd ON pd.product=p.id AND pd.type != 'N/A' LEFT JOIN $discounttable AS dc ON dc.product=p.id AND dc.price=pd.id LEFT JOIN $promotable AS pr ON pr.id=dc.promo LEFT JOIN $imagetable AS img ON img.parent=p.id AND img.context='product' AND img.type='image' AND img.sortorder=0 {$loading['joins']} WHERE {$loading['where']} GROUP BY letter"; $alpha = $db->query($ac); $existing = current($alpha); if (!isset($this->alpha['0-9'])) { $this->alpha['0-9'] = new stdClass(); $this->alpha['0-9']->letter = '0-9'; $this->alpha['0-9']->total = 0; $this->alpha['0-9']->avg = 0; } while (is_numeric($existing->letter)) { $this->alpha['0-9']->total += $existing->total; $this->alpha['0-9']->avg = ($this->alpha['0-9']->avg+$existing->avg)/2; $this->alpha['0-9']->letter = '0-9'; $existing = next($alpha); } foreach ($alphanav as $letter) { if ($existing->letter == $letter) { $this->alpha[$letter] = $existing; $existing = next($alpha); } else { $entry = new stdClass(); $entry->letter = $letter; $entry->total = 0; $entry->avg = 0; $this->alpha[$letter] = $entry; } } $this->paged = true; if (!is_numeric($this->page)) { $alphafilter = $this->page == "0-9"? "(LEFT(p.name,1) REGEXP '[0-9]') = 1": "IF(LEFT(p.name,1) REGEXP '[0-9]',LEFT(p.name,1),LEFT(SOUNDEX(p.name),1))='$this->page'"; $loading['where'] .= (empty($loading['where'])?"":" AND ").$alphafilter; } } $query = "SELECT SQL_CALC_FOUND_ROWS $columns{$loading['columns']} FROM $producttable AS p LEFT JOIN $pricetable AS pd ON pd.product=p.id AND pd.type != 'N/A' LEFT JOIN $discounttable AS dc ON dc.product=p.id AND dc.price=pd.id LEFT JOIN $promotable AS pr ON pr.id=dc.promo LEFT JOIN $imagetable AS img ON img.parent=p.id AND img.context='product' AND img.type='image' AND img.sortorder=0 {$loading['joins']} WHERE {$loading['where']} GROUP BY p.id {$loading['having']} ORDER BY {$loading['order']} LIMIT {$loading['limit']}"; // Execute the main category products query $products = $db->query($query,AS_ARRAY); $total = $db->query("SELECT FOUND_ROWS() as count"); $this->total = $total->count; if ($this->pagination > 0 && $limit > $this->pagination) { $this->pages = ceil($this->total / $this->pagination); if ($this->pages > 1) $this->paged = true; } // if ($this->pagination == 0 || $limit < $this->pagination) // $this->total = count($this->products); $this->pricing['min'] = 0; $this->pricing['max'] = 0; $prices = array(); foreach ($products as $i => &$product) { if ($product->maxsaleprice == 0) $product->maxsaleprice = $product->maxprice; if ($product->minsaleprice == 0) $product->minsaleprice = $product->minprice; $prices[] = $product->onsale?$product->minsaleprice:$product->minprice; if (!empty($product->percentoff)) { $product->maxsaleprice = $product->maxsaleprice - ($product->maxsaleprice * ($product->percentoff/100)); $product->minsaleprice = $product->minsaleprice - ($product->minsaleprice * ($product->percentoff/100)); } if (!empty($product->amountoff)) { $product->maxsaleprice = $product->maxsaleprice - $product->amountoff; $product->minsaleprice = $product->minsaleprice - $product->amountoff; } $this->pricing['max'] = max($this->pricing['max'],$product->maxsaleprice); $this->pricing['min'] = min($this->pricing['min'],$product->minsaleprice); $this->products[$product->id] = new Product(); $this->products[$product->id]->populate($product); if (isset($product->score)) $this->products[$product->id]->score = $product->score; // Special property for Bestseller category if (isset($product->sold) && $product->sold) $this->products[$product->id]->sold = $product->sold; // Special property Promotions if (isset($product->promos)) $this->products[$product->id]->promos = $product->promos; if (!empty($product->image)) { $image = new ProductImage(); $image->id = $product->image; $image->value = unserialize($product->imgmeta); $image->expopulate(); $this->products[$product->id]->images = array($image); } } $this->pricing['average'] = 0; if (count($prices) > 0) $this->pricing['average'] = array_sum($prices)/count($prices); if (!isset($loading['load'])) $loading['load'] = array('prices'); if (count($this->products) > 0) { $Processing = new Product(); $Processing->load_data($loading['load'],$this->products); } $this->loaded = true; }
/** * Interface processor for the product editor * * @return void **/ function editor () { global $Ecart,$ProductImages; $db = DB::get(); if ( !(is_ecart_userlevel() || current_user_can('ecart_products')) ) wp_die(__('You do not have sufficient permissions to access this page.')); if (empty($Ecart->Product)) { $Product = new Product(); $Product->status = "publish"; } else $Product = $Ecart->Product; // $Product->load_data(array('images')); // echo "<pre>"; print_r($Product->imagesets); echo "</pre>"; $Product->slug = apply_filters('editable_slug',$Product->slug); $permalink = trailingslashit(ecarturl()); require_once("$Ecart->path/core/model/Asset.php"); require_once("$Ecart->path/core/model/Category.php"); $Price = new Price(); $priceTypes = array( array('value'=>'Shipped','label'=>__('Tangible Product','Ecart')), array('value'=>'Download','label'=>__('Digital Download','Ecart')), array('value'=>'N/A','label'=>__('Disabled','Ecart')), ); $workflows = array( "continue" => __('Continue Editing','Ecart'), "close" => __('Products Manager','Ecart'), "new" => __('New Product','Ecart'), "next" => __('Edit Next','Ecart'), "previous" => __('Edit Previous','Ecart') ); $taglist = array(); foreach ($Product->tags as $tag) $taglist[] = $tag->name; if ($Product->id) { $ProductImage = new ProductImage(); $results = $db->query("SELECT * FROM $ProductImage->_table WHERE context='product' AND parent=$Product->id AND type='image' ORDER BY sortorder",AS_ARRAY); $ProductImages = array(); foreach ((array)$results as $i => $image) { $image->value = unserialize($image->value); $ProductImages[$i] = new ProductImage(); $ProductImages[$i]->copydata($image,false,array()); $ProductImages[$i]->expopulate(); // Load any cropped image cache $cropped = $db->query("SELECT * FROM $ProductImage->_table WHERE context='image' AND type='image' AND parent='$image->id' AND '2'=SUBSTRING_INDEX(SUBSTRING_INDEX(name,'_',4),'_',-1)",AS_ARRAY); foreach ((array)$cropped as $c => $cache) { $cache->value = unserialize($cache->value); $CachedImage = new ProductImage(); $CachedImage->copydata($cache,false,array()); $CachedImage->expopulate(); $ProductImages[$i]->cropped[$c] = $CachedImage; } } } $shiprates = $this->Settings->get('shipping_rates'); if (!empty($shiprates)) ksort($shiprates); $uploader = $Ecart->Settings->get('uploader_pref'); if (!$uploader) $uploader = 'flash'; $process = (!empty($Product->id)?$Product->id:'new'); $_POST['action'] = add_query_arg(array_merge($_GET,array('page'=>$this->Admin->pagename('products'))),admin_url('admin.php')); include(ECART_ADMIN_PATH."/products/editor.php"); }