function display($tpl = null) { JToolBarHelper::title(JText::_("PRODUCTS"), 'fss_prods'); JToolBarHelper::deleteList(); JToolBarHelper::editList(); JToolBarHelper::addNew(); JToolBarHelper::divider(); if (FSS_Helper::TableExists("#__virtuemart_products_en_gb") || FSS_Helper::TableExists("#__vm_product")) { JToolBarHelper::custom('import_vm', 'copy', 'copy', 'IMPORT_FROM_VIRTUEMART', false); } if (FSS_Helper::TableExists("#__hikashop_product")) { JToolBarHelper::custom('import_hs', 'copy', 'copy', 'Import From Hika Shop', false); } JToolBarHelper::cancel('cancellist'); FSSAdminHelper::DoSubToolbar(); $this->lists = $this->get('Lists'); $this->data = $this->get('Data'); $this->pagination = $this->get('Pagination'); $categories = array(); $categories[] = JHTML::_('select.option', '-1', JText::_("IS_PUBLISHED"), 'id', 'title'); $categories[] = JHTML::_('select.option', '1', JText::_("PUBLISHED"), 'id', 'title'); $categories[] = JHTML::_('select.option', '0', JText::_("UNPUBLISHED"), 'id', 'title'); $this->lists['published'] = JHTML::_('select.genericlist', $categories, 'ispublished', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'id', 'title', $this->lists['ispublished']); $what = JRequest::getVar('what'); if ($what == "togglefield") { return $this->toggleField(); } parent::display($tpl); }
function CanEnable() { if (FSS_Helper::TableExists("#__uddeim")) { return true; } return "uddeIM not installed"; }
function ImportHikaShop() { $log = ""; // check that the vm products table exists and has products in it $tablename = "#__hikashop_product"; $pid = "product_id"; $ver = 2; if (!FSS_Helper::TableExists($tablename)) { $log = "No HikaShop installation found\n"; return $log; } $db = JFactory::getDBO(); $qry = "SELECT count(*) FROM {$tablename}"; $db->setQuery($qry); $result = $db->loadResult(); if ($result == 0) { $log = "No HikaShop products found, aborting\n"; return $log; } $qry = "SELECT MAX(ordering)+1 as neworder FROM #__fss_prod"; $db->setQuery($qry); $order = $db->loadResult(); $qry = "SELECT * FROM {$tablename} WHERE product_parent_id = 0 ORDER BY product_name"; if ($ver == 2) { $qry = "SELECT p.*, m.file_path FROM {$tablename} as p \n\n\t\t\t\tLEFT JOIN #__hikashop_file as m \n\t\t\t\tON p.product_id = m.file_ref_id\n\n\t\t\t\tWHERE product_parent_id = 0 \n\t\t\t\t\n\t\t\t\tGROUP BY p.product_id\n\t\t\t\t\n\t\t\t\tORDER BY product_name \n\n\t\t\t\t"; } $db->setQuery($qry); $products = $db->loadObjectList(); $log .= "Synchroizing " . count($products) . " Hika Shop products\n"; $pids = array(); // check for any removed products $qry = "SELECT * FROM #__fss_prod WHERE import_id > 0"; $db->setQuery($qry); $existingproducts = $db->loadObjectList('import_id'); $sourcepath = JPATH_SITE . DS . 'media' . DS . 'com_hikashop' . DS . 'upload'; $destbase = JPATH_SITE . DS . 'images' . DS . 'fss' . DS . 'products'; // get existing file list $existingfiles = array(); if (is_dir($destbase)) { if ($dh = opendir($destbase)) { while (($file = readdir($dh)) !== false) { if ($file == "." || $file == "..") { continue; } $existingfiles[$file] = $file; } closedir($dh); } } // products: /** * product_name - title * product_s_desc - description * product_full_image - image file **/ foreach ($products as $product) { // check for existing product $existing = null; if (array_key_exists($product->{$pid}, $existingproducts)) { $existing = $existingproducts[$product->{$pid}]; } // import image $pids[$product->{$pid}] = $product->{$pid}; // check if the image exists or not $imagesource = $product->file_path; $fin = pathinfo($imagesource); $destfile = $fin['basename']; $order = 1; if ($existing) { if ($product->product_name != $existing->title || $product->product_description != $existing->description || $destfile != $existing->image) { $log .= "Product '{$product->product_name}' already exists, updating\n"; $qry = "UPDATE #__fss_prod SET title = '" . FSSJ3Helper::getEscaped($db, $product->product_name) . "', description = '" . FSSJ3Helper::getEscaped($db, $product->product_description) . "', image = '" . FSSJ3Helper::getEscaped($db, $destfile) . "' WHERE id = '{$existing->id}'"; $db->setQuery($qry); $db->query(); } } else { $log .= "Adding product '{$product->product_name}'\n"; $qry = "INSERT INTO #__fss_prod (import_id, title, description, image, published, ordering, inkb, insupport, intest, access) VALUES ("; $qry .= $product->{$pid} . ", "; $qry .= "'" . FSSJ3Helper::getEscaped($db, $product->product_name) . "', "; $qry .= "'" . FSSJ3Helper::getEscaped($db, $product->product_description) . "', "; $qry .= "'" . FSSJ3Helper::getEscaped($db, $destfile) . "', "; $qry .= "1, {$order}, 1, 1, 1, 1)"; $order++; } $db->setQuery($qry); $db->Query(); // not existing, so make a new resized image for this product if ($imagesource && !array_key_exists($destfile, $existingfiles)) { $log .= "Copying and resizing image {$imagesource} for product '{$product->product_name}'\n"; if (!$this->image_resize($sourcepath . DS . $imagesource, $destbase . DS . $destfile, 64, 64, 0)) { copy($sourcepath . DS . $imagesource, $destbase . DS . $destfile); } } } foreach ($existingproducts as $product) { if (!array_key_exists($product->import_id, $pids)) { $log .= "Removing product {$product->title}\n"; $qry = "DELETE FROM #__fss_prod WHERE id = " . FSSJ3Helper::getEscaped($db, $product->id); $db->setQuery($qry); $db->Query(); } } $log .= "Done\n"; return $log; }
function dropTable($table) { $db = JFactory::getDBO(); if (FSS_Helper::TableExists($table)) { $db->setQuery("DROP TABLE {$table}"); $db->query(); return "Removing {$table}<br>"; } return ""; }