function run($request) { $tables = array("ProductGroup", "ProductGroup_Live", "Product", "Product_Live"); if (class_exists("ProductVariation")) { $tables[] = "ProductVariation"; } //todo: make list based on buyables rather than hard-coded. foreach ($tables as $tableName) { $classErrorCount = 0; $removeCount = 0; $updateClassCount = 0; $rowCount = DB::query("SELECT COUNT(\"ImageID\") FROM \"{$tableName}\" WHERE ImageID > 0;")->value(); DB::alteration_message("<h2><strong>CHECKING {$tableName} ( {$rowCount} records ):</strong></h2>"); $rows = DB::query("SELECT \"ImageID\", \"{$tableName}\".\"ID\" FROM \"{$tableName}\" WHERE ImageID > 0;"); if ($rows) { foreach ($rows as $row) { $remove = false; $classErrorCount += DB::query("\r\n\t\t\t\t\t\tSELECT COUNT (\"File\".\"ID\")\r\n\t\t\t\t\t\tFROM \"File\"\r\n\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\"File\".\"ID\" = " . $row["ImageID"] . "\r\n\t\t\t\t\t\t\tAND (\r\n\t\t\t\t\t\t\t \"ClassName\" = 'Image' OR\r\n\t\t\t\t\t\t\t \"ClassName\" = 'ProductVariation_Image' OR\r\n\t\t\t\t\t\t\t \"ClassName\" = ''\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t")->value(); DB::query("\r\n\t\t\t\t\t\tUPDATE \"File\"\r\n\t\t\t\t\t\tSET \"ClassName\" = 'Product_Image'\r\n\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\"File\".\"ID\" = " . $row["ImageID"] . "\r\n\t\t\t\t\t\t\tAND (\r\n\t\t\t\t\t\t\t \"ClassName\" = 'Image' OR\r\n\t\t\t\t\t\t\t \"ClassName\" = 'ProductVariation_Image' OR\r\n\t\t\t\t\t\t\t \"ClassName\" = ''\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t"); $image = Product_Image::get()->byID($row["ImageID"]); if (!$image) { $remove = true; } elseif (!$image->getTag()) { $remove = true; } if ($remove) { $removeCount++; DB::query("UPDATE \"{$tableName}\" SET \"ImageID\" = 0 WHERE \"{$tableName}\".\"ID\" = " . $row["ID"] . " AND \"{$tableName}\".\"ImageID\" = " . $row["ImageID"] . ";"); } elseif (!is_a($image, Object::getCustomClass("Product_Image"))) { $updateClassCount++; $image = $image->newClassInstance("Product_Image"); $image - write(); } } } if ($classErrorCount) { DB::alteration_message("<strong>{$tableName}:</strong> there were {$classErrorCount} files with the wrong class names. These have been fixed.", "deleted"); } else { DB::alteration_message("<strong>{$tableName}:</strong> there were no files with the wrong class names. ", "created"); } if ($removeCount) { DB::alteration_message("<strong>{$tableName}:</strong> Removed {$removeCount} image(s) from products and variations because they do not exist in the file-system or database", "deleted"); } else { DB::alteration_message("<strong>{$tableName}:</strong> All product images are accounted for", "created"); } if ($updateClassCount) { DB::alteration_message("<strong>{$tableName}:</strong> {$removeCount} image(s) did not match the requirement 'instanceOF Product_Image', this has been corrected.", "deleted"); } else { DB::alteration_message("<strong>{$tableName}:</strong> All product images instancesOF Product_Image", "created"); } } }
public function index($params) { $id = $params[0]; $page = isset($params[1]) ? $params[1] : 1; $products = array(); if ($pros = Product::query()->where([['`active`', '=', 1], ['`id_category`', '=', $id]])->order_by('`order`')->take(12)->skip($page * 12)->get()) { while ($row = $pros->fetch_assoc()) { $pro = new Product($row); if ($imgs = Product_Image::query()->where([['`id_product`', '=', $pro->id]])->take(1)->get()) { $images = array(); while ($other_row = $imgs->fetch_assoc()) { $image = new Product_Image($other_row); array_push($images, $image); } $pro->images = $images; $imgs->free(); } array_push($products, $pro); } $pros->free(); } if ($pros = Product::query()->where([['`active`', '=', 1], ['`id_category`', '=', $id]])->order_by('`view`')->take(1)->get()) { $featured = null; if ($row = $pros->fetch_assoc()) { $featured = new Product($row); if ($imgs = Product_Image::query()->where([['`id_product`', '=', $featured->id]])->take(1)->get()) { $images = array(); while ($other_row = $imgs->fetch_assoc()) { $image = new Product_Image($other_row); array_push($images, $image); } $featured->images = $images; $imgs->free(); } } $pros->free(); } if ($count = Product::query(['count(*) as `count`'])->where([['`active`', '=', 1], ['`id_category`', '=', $id]])->get()) { if ($row = $count->fetch_assoc()) { $cnt = ceil($row['count'] / 12); } $count->free(); } $this->render('views/category/index.php', ['products' => $products, 'featured_product' => $featured, 'id_cat' => $id, 'page' => $page, 'total_page' => $cnt]); }
public function _new_products() { //'select * from eli_product where `active` =1 order by `id` desc limit 8' $products = array(); if ($pros = Product::query()->where([['`active`', '=', 1]])->order_by('`order`')->take(8)->get()) { while ($row = $pros->fetch_assoc()) { //'select * from eli_product_image where `id_product`=' .$pro->id. ' limit 1' $pro = new Product($row); if ($imgs = Product_Image::query()->where([['`id_product`', '=', $pro->id]])->take(1)->get()) { $images = array(); if ($other_row = $imgs->fetch_assoc()) { $image = new Product_Image($other_row); array_push($images, $image); } $pro->images = $images; $imgs->free(); } array_push($products, $pro); } $pros->free(); } return $products; }
static function set_large_image_width($width = 600) { self::$large_image_width = $width; }
public function getColor() { $Image = new Product_Image(); return $Image->findItem(array('Id = ' . $this->Color)); }
/** * The function returns array of Product Images. * * @access public * @return array The Images. */ public function getImages() { $Image = new Product_Image(); return $Image->findList(array('ProductId = ' . $this->Id), 'Position asc'); }
/** * Provide a copy of the current order's items, including image details and variations * @todo what about subTitles? i.e the variation choosen (I think) * @return array */ protected function getCurrentShoppingCartItems() { $result = array(); $items = ShoppingCart::curr()->Items(); if ($items->exists()) { foreach ($items->getIterator() as $item) { // Definitions $data = array(); $product = $item->Product(); $data["id"] = (string) $item->ProductID; $data["internalItemID"] = $product->InternalItemID; $data["title"] = $product->Title; $data["quantity"] = (int) $item->Quantity; $data["unitPrice"] = $product->getPrice(); $data["href"] = $item->Link(); $data['categories'] = $product->getCategories()->column('Title'); $data["addLink"] = $item->addLink(); $data["removeLink"] = $item->removeLink(); $data["removeallLink"] = $item->removeallLink(); $data["setquantityLink"] = $item->setquantityLink(); // Image if ($image = $item->Image()->ScaleWidth((int) Product_Image::config()->cart_image_width)) { $data["image"] = array('alt' => $image->Title, 'src' => $image->Filename, 'width' => $image->Width, 'height' => $image->Height); } // Variations if ($product->has_many("Variations")) { $variations = $product->Variations(); if ($variations->exists()) { $data['variations'] = array(); foreach ($variations as $variation) { $data['variations'][] = array('id' => (string) $variation->ID, 'title' => $variation->Title); } } } $result[] = $data; } } return $result; }
/** * Returns the default image or a dummy one if it does not exists. * @return String */ function DefaultImage() { if ($this->DefaultProductImageID) { if ($defaultImage = $this->DefaultProductImage()) { if ($defaultImage->exists()) { return $defaultImage; } } } $obj = Product_Image::create(); $obj->Link = $this->DefaultImageLink(); $obj->URL = $this->DefaultImageLink(); return $obj; }
Order::set_receipt_subject("Shop Sale Information #%d"); Order::set_modifiers(array(), true); Order::set_table_overview_fields(array('ID' => 'Order No', 'Created' => 'Created', 'FirstName' => 'First Name', 'Surname' => 'Surname', 'Total' => 'Total', 'Status' => 'Status')); Order::set_maximum_ignorable_sales_payments_difference(0.01); Order::set_order_id_start_number(0); Order::set_cancel_before_payment(true); Order::set_cancel_before_processing(false); Order::set_cancel_before_sending(false); Order::set_cancel_after_sending(false); OrderForm::set_user_membership_optional(false); OrderForm::set_force_membership(true); OrderManipulation::set_allow_cancelling(false); OrderManipulation::set_allow_paying(false); // * * * PRODUCTS ProductsAndGroupsModelAdmin::set_managed_models(array("Product", "ProductGroup", "ProductVariation", "ProductAttributeType")); Product_Image::set_thumbnail_size(140, 100); Product_Image::set_content_image_width(200); Product_Image::set_large_image_width(200); ProductGroup::set_include_child_groups(true); ProductGroup::set_must_have_price(true); ProductGroup::set_sort_options(array('Title' => 'Alphabetical', 'Price' => 'Lowest Price')); // * * * CHECKOUT ExpiryDateField::set_short_months(true); OrderFormWithoutShippingAddress::set_fixed_country_code(null); OrderFormWithoutShippingAddress::set_postal_code_url("http://www.nzpost.co.nz/Cultures/en-NZ/OnlineTools/PostCodeFinder"); OrderFormWithoutShippingAddress::set_postal_code_label("find postcode"); OrderFormWithoutShippingAddress::set_login_invite_alternative_text('Please <a href="Security/login?BackURL=/">log in now</a> to retrieve your account details or create an account below.'); // * * * MEMBER EcommerceRole::set_group_name("Shop Customers"); // * * * HELP Product::set_global_allow_purchase(true);