Inheritance: extends Object
示例#1
0
 /**
  * @internal
  *
  * @param \SimpleXMLElement $xml
  *
  * @return ProductType
  */
 public static function fromXml(\SimpleXMLElement $xml)
 {
     $productType = new ProductType();
     $productType->setIsResponse();
     $productType->setCode($xml->Code)->setDescription($xml->Description);
     return $productType;
 }
 public function run()
 {
     if (empty($this->model) || empty($this->type)) {
         return;
     }
     // Определяем тип товара для поиска товаров данного типа
     $productType = ProductType::model()->published()->findByAlias($this->type);
     if (!$productType) {
         return;
     }
     // Определяем товар данного типа с таким же названием, как заданный
     $relatedProduct = Stone::model()->published()->type($productType->id)->with('series')->findByAttributes(array('title' => $this->model->title));
     // Получаем список рандомных товаров данного типа, похожих на заданный по цвету и виду камня
     $criteria = new CDbCriteria();
     $criteria->compare('t.series_id', $this->model->series_id);
     $criteria->compare('t.color_id', $this->model->color_id);
     $notSearchIds = array($this->model->id);
     if ($relatedProduct !== null) {
         $notSearchIds[] = $relatedProduct->id;
     }
     $criteria->addNotInCondition('t.id', $notSearchIds);
     $criteria->order = 'RAND()';
     $criteria->limit = 7;
     $models = Stone::model()->published()->type($productType->id)->with('series')->findAll($criteria);
     if ($relatedProduct !== null) {
         $models = array($relatedProduct) + $models;
     }
     $this->render($this->view, array('productType' => $productType, 'models' => $models, 'model' => $this->model));
 }
 public function loadModel($id)
 {
     if (($model = ProductType::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }
 public function scopeType($query, $id)
 {
     $types = ProductType::lists('name', 'id');
     if ($id != "" && isset($types[$id])) {
         $query->where('product_type_id', $id);
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     //
     $product = Product::find($id);
     $type = ProductType::all();
     $brand = Brand::all();
     return View::make('product.edit')->withProduct($product)->withBrand($brand)->withType($type);
 }
 /**
  * sample_GetProductSellingPages::dispatchCall()
  * 
  * Dispatch the call
  *
  * @param array $params array of parameters for the eBay API call
  * 
  * @return boolean success
  */
 public function dispatchCall($params)
 {
     $req = new GetProductSellingPagesRequestType();
     $req->setUseCase($params['UseCase']);
     $Product = new ProductType();
     $Product->setTypeAttribute('productID', $params['productID']);
     $CharacteristicsSet = new CharacteristicsSetType();
     $CharacteristicsSet->setAttributeSetID($params['AttributeSetID']);
     $Product->setCharacteristicsSet($CharacteristicsSet);
     $req->setProduct($Product);
     $res = $this->proxy->GetProductSellingPages($req);
     if ($this->testValid($res)) {
         $this->dumpObject($res);
         return true;
     } else {
         return false;
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $validation = Validate::TipoproductoValidation(Input::all());
     if ($validation->fails()) {
         return Redirect::to('tipoproducto/create')->withErrors($validation)->withInput();
     } else {
         $tipoproducto = ProductType::find($id);
         $tipoproducto->type = Input::get('type');
         $tipoproducto->save();
         return Redirect::to('tipoproducto');
     }
 }
<?php

require_once "header.php";
if (isset($_GET['id'])) {
    $object = ProductType::get_by_id($_GET['id']);
} else {
    header("location: index.php?negative");
}
if (!$session->is_logged_in()) {
    header("location: index.php?negative");
} else {
    $loggeduser = User::get_by_id($session->userid);
    if ($loggeduser->enabled == DISABLED) {
        header("location: index.php?disabled");
    }
}
$pathinfo = pathinfo($_SERVER["PHP_SELF"]);
$basename = $pathinfo["basename"];
$currentFile = str_replace(".php", "", $basename);
?>

<div class="container-fluid">
<div class="row-fluid">
  <div class="span1"></div>
  <div class="span9">
    <form id="theform" class="form-horizontal" action="#" method="post" enctype="multipart/form-data">
      <fieldset>
      <legend>
        Update
      </legend>
示例#9
0
/**
 * sends an invoice if the status is right
 *
 * @param int   $id    ID of the order
 * @param array $order details of the order
 *
 * @return null
 */
function OnlineStore_sendInvoiceEmail($id, $order = false)
{
    if ($order === false) {
        $order = dbRow("SELECT * FROM online_store_orders WHERE id={$id}");
    }
    $sendAt = (int) dbOne('select val from online_store_vars where name="invoices_by_email"', 'val');
    if ($sendAt == 0 && $order['status'] != '1') {
        return;
    }
    if ($sendAt == 1) {
        // never send
        return;
    }
    if ($sendAt == 2 && $order['status'] != '2') {
        return;
    }
    if ($sendAt == 3 && $order['status'] != '4') {
        return;
    }
    $form_vals = json_decode($order['form_vals']);
    $items = json_decode($order['items']);
    $short_domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
    // { work out from/to
    $page = Page::getInstanceByType('online-store');
    $page->initValues();
    $from = 'noreply@' . $short_domain;
    $bcc = '';
    if ($page && isset($page->vars['online_stores_admin_email']) && $page->vars['online_stores_admin_email']) {
        $from = $page->vars['online_stores_admin_email'];
        $bcc = $page->vars['online_stores_admin_email'];
    }
    if (isset($form_vals->billing_email)) {
        $form_vals->Billing_Email = $form_vals->billing_email;
    }
    if (!isset($form_vals->Billing_Email) || !$form_vals->Billing_Email) {
        $form_vals->Billing_Email = $form_vals->Email;
    }
    $headers = '';
    if ($bcc) {
        $sendToAdmin = (int) dbOne('select val from online_store_vars where name="invoices_by_email_admin"', 'val');
        if (!$sendToAdmin) {
            $headers .= 'BCC: ' . $bcc . "\r\n";
        }
    }
    // }
    Core_trigger('send-invoice', array($order));
    // { send invoice
    if ($form_vals->Billing_Email != 'no-email-supplied@example.com') {
        Core_mail($form_vals->Billing_Email, '[' . $short_domain . '] invoice #' . $id, $order['invoice'], $from, '_body', $headers);
    }
    // }
    // { handle item-specific stuff (vouchers, stock control)
    foreach ($items as $item_index => $item) {
        if (!$item->id) {
            continue;
        }
        $p = Product::getInstance($item->id);
        $pt = ProductType::getInstance($p->vals['product_type_id']);
        if ($pt->is_voucher) {
            $html = $pt->voucher_template;
            // { common replaces
            $html = str_replace('{{$_name}}', $p->name, $html);
            $html = str_replace('{{$description}}', $p->vals['description'], $html);
            $html = str_replace('{{$_recipient}}', $form_vals->Billing_Email, $html);
            $html = str_replace('{{$_amount}}', $p->vals['os_voucher_value'], $html);
            // }
            if (strpos($html, '{{PRODUCTS_QRCODE}}') !== false) {
                // qr code
                $url = 'http://' . $_SERVER['HTTP_HOST'] . '/a/p=online-store/f=checkQrCode/' . 'oid=' . $order['id'] . '/pid=' . $item_index . '/md5=' . md5($order['invoice']);
                $html = str_replace('{{PRODUCTS_QRCODE}}', '<img src="http://' . $_SERVER['HTTP_HOST'] . '/a/p=online-store/f=getQrCode/b64=' . urlencode(base64_encode($url)) . '"/>', $html);
            }
            Core_mail($form_vals->Billing_Email, '[' . $short_domain . '] voucher', $html, $from, '_body', $headers);
        }
        // { stock control
        if (isset($p->vals['online-store'])) {
            $valsOS = $p->vals['online-store'];
            $stock_amount = (int) @$valsOS['_stock_amt'] - $item->amt;
            $valsOS['_stock_amt'] = $stock_amount;
            $sold_amount = (int) @$valsOS['_sold_amt'] + $item->amt;
            $valsOS['_sold_amt'] = $sold_amount;
            dbQuery('update products set' . ' online_store_fields="' . addslashes(json_encode($valsOS)) . '"' . ', os_amount_in_stock=' . $stock_amount . ', os_amount_sold=' . $sold_amount . ', date_edited=now()' . ' where id=' . $item->id);
        }
        // }
    }
    Core_cacheClear('products');
    // }
}
示例#10
0
 * @link     None
 */
$id = (int) $_REQUEST['product_id'];
$product = Product::getInstance($id);
if (!$product) {
    return;
}
$amount = 1;
if (isset($_REQUEST['products-howmany'])) {
    $amount = (int) $_REQUEST['products-howmany'];
}
// { find "custom" values
$price_amendments = 0;
$vals = array();
$md5 = '';
$product_type = ProductType::getInstance($product->vals['product_type_id']);
$long_desc = '';
foreach ($_REQUEST as $k => $v) {
    if (strpos($k, 'products_values_') === 0) {
        $n = str_replace('products_values_', '', $k);
        $data_field = $product_type->getField($n);
        if ($data_field === false || $data_field->u != 1) {
            continue;
        }
        switch ($data_field->t) {
            case 'selectbox':
                // {
                $ok = 0;
                if (@$product->vals[$n]) {
                    // if product has custom values
                    $strs = explode("\n", $product->vals[$n]);
示例#11
0
             $html .= "  <td><img src='" . $item->picture . "' height='40' width='40'/></td>";
             $html .= "  <td>storeid " . $item->storeid . "</td>";
             $html .= "  <td>" . $item->name . "</td>";
             $html .= "  <td>" . $item->description . "</td>";
             $html .= "  <td><a class='btn btn-primary' href='updateproduct.php?id=" . $item->id . "'>Update</a></td>";
             $html .= "  <td><button class='btn btn-danger btndelete'>Delete <span hidden>" . $item->id . "</span></button></td>";
             $html .= "</tr>";
         }
         $filename = 0;
         echo $html;
     } else {
         echo "no data";
     }
 } else {
     if ($_GET['itemtype'] == "producttype") {
         $items = ProductType::search($input);
         if (count($items) > 0) {
             foreach ($items as $item) {
                 $filename++;
                 $random = rand(0, 1);
                 file_put_contents("images/" . $filename . "x" . $random . ".jpg", base64_decode($item->picture));
                 $item->picture = HOST . "includes/webservices/images/" . $filename . "x" . $random . ".jpg";
                 $html .= "<tr>";
                 $html .= "  <td><img src='" . $item->picture . "' height='40' width='40'/></td>";
                 $html .= "  <td>" . $item->name . "</td>";
                 $html .= "  <td><a class='btn btn-primary' href='updateproducttype.php?id=" . $item->id . "'>Update</a></td>";
                 $html .= "  <td><button class='btn btn-danger btndelete'>Delete <span hidden>" . $item->id . "</span></button></td>";
                 $html .= "</tr>";
             }
             $filename = 0;
             echo $html;
示例#12
0
 public function actionDeleteType()
 {
     $typeID = $_POST['typeID'];
     $sql = "SELECT * FROM `product_type` WHERE id=" . $typeID;
     $type = ProductType::model()->findBySql($sql);
     $result = false;
     if ($type) {
         $type->delete();
         $result = true;
     }
     echo $result;
 }
示例#13
0
}
if (isset($_GET['enabled'])) {
    $where .= " AND " . C_PRODUCTTYPE_ENABLED . equallike($_GET['enabled'], "int");
}
//======================================================
if (isset($_GET['limit'])) {
    $limit = " LIMIT " . $_GET['limit'] . " ";
}
if (isset($_GET['sortby']) && isset($_GET['sortorder'])) {
    $sort = " ORDER BY " . $_GET['sortby'] . " " . $_GET['sortorder'] . " ";
}
if (isset($_GET['sortby']) && !isset($_GET['sortorder'])) {
    $sort = " ORDER BY " . $_GET['sortby'] . $sortorder . " ";
}
//======================================================
$items = ProductType::get_by_sql("SELECT * FROM " . T_PRODUCTTYPES . " WHERE " . $where . $sort . $limit);
$filename = 0;
if (!isset($_GET['blob'])) {
    foreach ($items as $item) {
        $filename++;
        $random = rand(0, 1);
        file_put_contents("images/" . $filename . "x" . $random . ".jpg", base64_decode($item->picture));
        $item->picture = HOST . "includes/webservices/images/" . $filename . "x" . $random . ".jpg";
    }
}
echo str_replace('\\/', '/', json_encode($items));
//echo json_encode($items, JSON_UNESCAPED_SLASHES);
function equallike($field, $type)
{
    $string = "";
    if ($type == "string") {
示例#14
0
<?php

/**
 * Products_datatable
 *
 * PHP version 5
 *
 * @category None
 * @package  None
 * @author   Kae Verens <kae@kvsites.ie>
 * @license  GPL 2.0
 * @link     None
 */
$product = $smarty->smarty->tpl_vars['product']->value;
$ptid = $product->get('product_type_id');
$type = ProductType::getInstance($ptid);
if (!$type) {
    $c = __('Missing Product Type: %1', array($ptid), 'core');
}
$datafields = $type->data_fields;
if (!is_array($datafields)) {
    $datafields = array();
}
$c = '<table>';
if (!isset($params['align']) || $params['align'] != 'horizontal') {
    foreach ($datafields as $data) {
        $name = $data->ti ? $data->ti : ucwords(str_replace('_', ' ', $data->n));
        $c .= '<tr><th class="left">';
        $c .= htmlspecialchars(ucfirst($name));
        $c .= '</th><td>';
        if (!isset($product->vals[$data->n])) {
 public function actionSuggestion()
 {
     $criteria = new CDbCriteria();
     $criteria->select = array('t.id,t.name');
     $pro_type = ProductType::model()->findAll($criteria);
     $products = array();
     if (isset($_POST['sel_pro'])) {
         $customer = Customer::model()->findByPk(getCurCusId());
         $customer->sel_products = $_POST['sel_pro'];
         if ($customer->save()) {
             $this->redirect(array('customer/customerreply'));
         }
     }
     foreach ($pro_type as $type) {
         $pro = Product::model()->findAll(array('condition' => "type_id = {$type->id}"));
         //            $products[$type->name] = $pro;
         $products[] = $pro;
     }
     $this->render('suggestion', array('products' => $products, 'types' => $pro_type));
 }
 public function getTypeList()
 {
     return CHtml::listData(ProductType::model()->findAll(), 'id', 'title');
 }
示例#17
0
<?php

require_once "../initialize.php";
$message = "";
if (isset($_POST['name']) && $_POST['name'] != "") {
    $producttype = new ProductType();
    $producttype->name = $_POST['name'];
    $producttype->description = $_POST['description'];
    $producttype->pending = $_POST['pending'];
    $producttype->enabled = $_POST['enabled'];
    if (isset($_FILES['picture'])) {
        $file = new File($_FILES['picture']);
        $producttype->picture = $file->data;
    }
    $producttype->create();
    $log = new Log($session->userid, $clientip, "WEB", "CREATED PRODUCT TYPE: " . $producttype->id);
    $log->create();
    $message .= "success";
} else {
    $message = "You have missed a required field.";
}
echo $message;
示例#18
0
			<tr>
				<td><img src="http://vvfy.me/img/gambar.png"></td>
				<td></td>
				<td></td>
			</tr>
			<tr >
				<td style="padding:20px">
					<p style="color:white !important">
					Thanks for submiting your data :)<br><br>

					<?php 
$pt = ProjectType::model()->findByPk($data->project_type)->name;
$reference = $data->reference == 1 ? "Conceptual Renders" : $data->reference == 2 ? "Realistic Renders" : "Highest Quality Renders";
$deadline = $data->deadline;
$style = $data->project_style == 1 ? "Modern" : "Classic";
$productType = ProductType::model()->findByPk($data->product_type)->name;
?>

					Project type : <?php 
echo $pt;
?>
<br>
					<?php 
if ($data->project_type == 1) {
    ?>
						Views count : <?php 
    echo $data->views_count;
    ?>
<br>
						Style of project : <?php 
    echo $style;
示例#19
0
    $ship_id_arr[] = $shipper->id;
}
echo '.';
foreach ($sugar_demodata['productcategory_seed_data_names'] as $v) {
    $category = new ProductCategory();
    $category->name = $v;
    $category->list_order = "1";
    $key = array_rand($sugar_demodata['users']);
    $category->assigned_user_id = $sugar_demodata['users'][$key]['id'];
    $category->save();
    $productcategory_id_arr[] = $category->id;
}
echo '.';
$list_order = 1;
foreach ($sugar_demodata['producttype_seed_data_names'] as $v) {
    $type = new ProductType();
    $type->name = $v;
    $type->list_order = $list_order;
    $type->save();
    $producttype_id_arr[] = $type->id;
    $list_order++;
}
echo '.';
foreach ($sugar_demodata['taxrate_seed_data'] as $v) {
    $taxrate = new TaxRate();
    $taxrate->name = $v['name'];
    $taxrate->value = $v['value'];
    $taxrate->status = "Active";
    $taxrate->list_order = "1";
    $taxrate->disable_num_format = TRUE;
    $taxrate->save();
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return ProductType the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = ProductType::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
示例#21
0
 public function actionDelete($id)
 {
     ProductType::model()->findByPk($id)->delete();
     $this->redirect(Yii::app()->createUrl('/type/index'));
 }
 public function deleteProductType($id)
 {
     if (Request::ajax()) {
         $arrReturn = ['status' => 'error', 'message' => 'Please refresh and try again.'];
         try {
             $type = ProductType::findorFail($id);
         } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return App::abort(404);
         }
         $name = $type->name;
         if ($type->delete()) {
             $arrReturn = ['status' => 'ok', 'message' => "<b>{$name}</b> has been deleted."];
         }
         $response = Response::json($arrReturn);
         $response->header('Content-Type', 'application/json');
         return $response;
     }
     return App::abort(404);
 }
 public function __construct()
 {
     $productType = ProductType::all();
     View::share('tipo_producto', $productType);
 }
 public function actionSuggestion()
 {
     $criteria = new CDbCriteria();
     $criteria->select = array('t.id,t.name');
     $pro_type = ProductType::model()->findAll($criteria);
     $products = array();
     DynamicCall::GetEdit1stPdf(getCurCusId());
     if (isset($_GET['id'])) {
         $typeid = $_GET['id'];
         if (isset($_POST['sel_pro'])) {
             $customer = Customer::model()->findByPk(getCurCusId());
             $customer->sel_products = $_POST['sel_pro'];
             if ($customer->save()) {
                 $this->redirect(array('customer/customerreply'));
             }
         }
         $pro = Product::model()->findAll(array('condition' => "type_id =" . $typeid));
         $products[] = $pro;
         $pro_desc = array();
         $i = 1;
         foreach ($pro as $p) {
             $product = array('name' => $p->name, 'desc' => $p->desc);
             $pro_desc[$i] = $product;
             $i++;
         }
     }
     $products = isset($products[0]) ? $products[0] : array();
     //        e($products);
     $this->render('suggestion', array('products' => $products, 'types' => $pro_type, 'pro_desc' => $pro_desc));
 }
示例#25
0
 /**
  * Price into indexed is not reliable for composite type.
  * This method detects this.
  *
  * @param string $productTypeId Product type id.
  *
  * @return boolean
  */
 private function isOriginalPriceReliable($productTypeId)
 {
     return !in_array($productTypeId, $this->productType->getCompositeTypes());
 }
示例#26
0
 public static function getTypes()
 {
     $model = ProductType::model()->findAll();
     return CHtml::listData($model, 'id', 'name');
 }
 public function editProduct($productId)
 {
     try {
         $product = Product::with('images')->with('categories')->with('optionGroups')->with('options')->with('priceBreaks')->with('sizeLists')->findorFail($productId);
     } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         return App::abort(404);
     }
     $product = $product->toArray();
     foreach (['option_groups', 'options'] as $value) {
         $tmpData = [];
         if (!empty($product[$value])) {
             foreach ($product[$value] as $v) {
                 $tmpData[] = $v['id'];
             }
         }
         $product[$value] = $tmpData;
         unset($tmpData);
     }
     $product['sell_price'] = number_format($product['sell_price'], 2);
     $arrCategories = [];
     if (!empty($product['categories'])) {
         foreach ($product['categories'] as $category) {
             $arrCategories[] = $category['id'];
         }
     }
     $this->layout->title = 'Edit Product';
     $this->layout->content = View::make('admin.products-one')->with(['product' => $product, 'arrCategories' => ProductCategory::getSource(false, 0, true), 'arrChosenCategories' => $arrCategories, 'types' => ProductType::getSource(), 'option_groups' => ProductOptionGroup::getSource(false, true), 'layouts' => array()]);
 }
示例#28
0
          </div>
        </div>

        <div class="control-group">
          <label class="control-label" for="price">* Price</label>
          <div class="controls">
            <input id="price" name="price" type="text" placeholder="price" class="input-xlarge">
          </div>
        </div>

        <div class="control-group">
          <label class="control-label" for="name">* Product Type</label>
          <div class="controls">
            <select name="producttypeid" id="producttypeid">
              <?php 
$producttypes = ProductType::get_all();
if (count($producttypes) > 0) {
    foreach ($producttypes as $producttype) {
        echo "<option value='" . $producttype->id . "'>" . $producttype->name . "</option>";
    }
} else {
    echo "<option value='0'>no product types yet</option>";
}
?>
            </select>
          </div>
        </div>

        <div class="control-group">
          <label class="control-label" for="name">* Store</label>
          <div class="controls">
示例#29
0
 /**
  * 扩展字段数据的文本框
  * @author wjh 2014-5-20
  * @param BFormModel $model model
  * @param string $attribute attribute
  */
 public static function getExtraTextField($model, $attribute)
 {
     try {
         $otype = null;
         if ($model instanceof Product) {
             $otype = new ProductType();
         } else {
             if ($model instanceof ProductForm) {
                 $otype = new ProductType();
             } else {
                 throw new Exception('model is not null');
             }
         }
         $type = $otype->findByAttributes(array('type_id' => $model->type_id));
         $obj = BJSON::decodeToArray($type->struc);
         $extra = $obj['extra_data'];
         $extraStruct = ProductExtraStruct::model()->find('attributename=:attributename', array(':attributename' => $attribute));
         $extraDate = ProductExtra::model()->find('attributename=:attributename and pid=:pid', array(':attributename' => $attribute, ':pid' => $model->pid));
         if (!isset($extraStruct)) {
             echo 'not set struct ' . $attribute;
             die;
         }
         $value = '';
         if (!is_null($extraDate)) {
             $value = $extraDate->vtype == 'S' ? $extraDate->attributetext : $extraDate->attributevalue;
         }
         //echo CHtml::label($extraStruct->attributelabel, $attribute);
         echo CHtml::textField(sprintf('ExtraForm[%s]', $attribute), $value, array('id' => sprintf('ExtraForm_%s', $attribute)));
         if ($extraStruct->isrequired) {
             echo CHtml::tag('span', array('class' => 'required'), '*');
         }
     } catch (Exception $ex) {
         throw $ex;
     }
 }
示例#30
0
 /**
  * render a list of products to HTML
  *
  * @param object $PAGEDATA      the page object
  * @param int    $start         offset
  * @param int    $limit         how many products to show
  * @param string $order_by      what field to order the search by
  * @param int    $order_dir     order ascending or descending
  * @param int    $limit_start   lowest $start offset allowed
  * @param int    $enabledFilter whether to allow enabled/disabled products
  *
  * @return string the HTML of the products list
  */
 function render($PAGEDATA, $start = 0, $limit = 0, $order_by = '', $order_dir = 0, $limit_start = 0, $enabledFilter = 0)
 {
     global $cdnprefix;
     $c = '';
     // { sort based on $order_by
     $md5 = md5('ps-sorted-' . join(',', $this->product_ids) . '|' . $order_by . '|' . $order_dir . '|' . $enabledFilter);
     $tmpprods = -1;
     if ($order_dir != 2) {
         $tmpprods = Core_cacheLoad('products', $md5, -1);
     }
     if ($tmpprods == -1) {
         if ($order_by != '') {
             $native = substr($order_by, 0, 1) === '_';
             $tmpprods1 = array();
             $prods = $this->product_ids;
             $sql = 'select id';
             if (!$native) {
                 $sql .= ',data_fields';
             }
             $sql .= ' from products where id in (' . join(', ', $this->product_ids) . ')';
             if ($enabledFilter == 0) {
                 $sql .= ' and enabled';
             }
             if ($enabledFilter == 1) {
             }
             if ($enabledFilter == 2) {
                 $sql .= ' and !enabled';
             }
             if ($native) {
                 $sql .= ' order by ' . substr($order_by, 1, strlen($order_by) - 1);
                 if ($order_dir == 1) {
                     $sql .= ' desc';
                 }
             }
             $values = dbAll($sql, '', 'products');
             if ($native) {
                 $tmpprods = array();
                 if (is_array($values)) {
                     foreach ($values as $v) {
                         $tmpprods[] = $v['id'];
                     }
                     if ($order_dir == 2) {
                         shuffle($tmpprods);
                     }
                 }
             } else {
                 if (is_array($values)) {
                     foreach ($values as $v) {
                         $vals = json_decode($v['data_fields'], true);
                         $key2 = '';
                         foreach ($vals as $v2) {
                             if ($v2['n'] == $order_by) {
                                 $key2 = __FromJSON($v2['v']);
                             }
                         }
                         if (!isset($tmpprods1[$key2])) {
                             $tmpprods1[$key2] = array();
                         }
                         $tmpprods1[$key2][] = $v['id'];
                     }
                 }
                 if ($order_dir == 1) {
                     krsort($tmpprods1);
                 } else {
                     if ($order_dir == 0) {
                         ksort($tmpprods1);
                     } else {
                         if ($order_dir == 2) {
                             shuffle($tmpprods1);
                         }
                     }
                 }
                 $tmpprods = array();
                 foreach ($tmpprods1 as $pids) {
                     foreach ($pids as $pid) {
                         $tmpprods[] = $pid;
                     }
                 }
                 foreach ($prods as $key => $pid) {
                     $tmpprods[] = $pid;
                 }
             }
         } else {
             $tmpprods = $this->product_ids;
         }
         Core_cacheSave('products', $md5, $tmpprods);
     }
     // }
     // { sanitise the limits
     $cnt = count($tmpprods);
     if (!$limit) {
         $limit = $cnt;
         $start = 0;
     } else {
         if ($start && $start >= count($this->product_ids)) {
             $start = $cnt - $limit;
         }
     }
     // }
     // { build array of items
     $prevnext = '';
     $total_found = count($tmpprods);
     if ($cnt == $limit) {
         $prods =& $tmpprods;
     } else {
         $prods = array();
         for ($i = $start; $i < $limit + $start; ++$i) {
             if (isset($tmpprods[$i])) {
                 $prods[] = $tmpprods[$i];
             }
         }
         $prefix = '';
         if ($PAGEDATA->vars['products_what_to_show'] == 2) {
             $cat = ProductCategory::getInstance($PAGEDATA->vars['products_category_to_show']);
             if ($cat) {
                 $prefix = $cat->getRelativeUrl();
             }
         }
         if (!$prefix) {
             $prefix = $PAGEDATA->getRelativeUrl();
         }
         if ($start > $limit_start) {
             $prevnext .= '<a class="products-prev" href="' . $prefix . '?start=' . ($start - $limit) . '">' . __('Previous') . '</a>';
         }
         if ($limit && $start + $limit < $cnt) {
             if ($start) {
                 $prevnext .= ' | ';
             }
             $prevnext .= '<a class="products-next" href="' . $prefix . '?start=' . ($start + $limit) . '">' . __('Next') . '</a>';
         }
     }
     $prevnext = '<div class="products-pagination">' . $prevnext . '</div>';
     // }
     // { see if there are search results
     if (isset($PAGEDATA->vars['products_add_a_search_box']) && $PAGEDATA->vars['products_add_a_search_box']) {
         $c .= '<div class="products-num-results">' . __('<strong>%1</strong> results found.', array($total_found), 'core') . '</div>';
     }
     // }
     if (!isset($PAGEDATA->vars['products_show_multiple_with'])) {
         $PAGEDATA->vars['products_show_multiple_with'] = 0;
     }
     $prods = array_unique($prods);
     switch ($PAGEDATA->vars['products_show_multiple_with']) {
         case 1:
             // { horizontal table, headers on top
             $c .= Product_datatableMultiple($prods, 'horizontal');
             break;
             // }
         // }
         case 2:
             // { vertical table, headers on left
             $c .= Product_datatableMultiple($prods, 'vertical');
             break;
             // }
         // }
         case 3:
             // { map view
             WW_addScript('products');
             WW_addCSS('/ww.plugins/products/products.css');
             return '<div id="products-mapview"></div>';
             // }
         // }
         case 4:
             // { carousel
             WW_addScript('products');
             $c = '<div id="products-carousel"><ul id="products-carousel-slider">';
             foreach ($prods as $pid) {
                 $product = Product::getInstance($pid, false, $enabledFilter);
                 if ($product && isset($product->id) && $product->id) {
                     $typeID = $product->get('product_type_id');
                     $type = ProductType::getInstance($typeID);
                     if (!$type) {
                         $c .= '<li>' . __('Missing Product Type: %1', array($typeID), 'core') . '</li>';
                     } else {
                         $c .= '<li id="products-' . $product->id . '" class="products-product">' . $type->render($product, 'multiview', 0) . '</li>';
                     }
                 }
             }
             $c .= '</ul></div>';
             WW_addScript('/j/jsor-jcarousel-7bb2e0a/jquery.jcarousel.min.js');
             WW_addCSS('/ww.plugins/products/products.css');
             return $c;
             // }
         // }
         default:
             // { use template
             if (count($prods)) {
                 // display the first item's header
                 $product = Product::getInstance($prods[0], false, $enabledFilter);
                 $type = ProductType::getInstance($product->get('product_type_id'));
                 if ($type) {
                     $smarty = Products_setupSmarty();
                     $c .= $smarty->fetch(USERBASE . '/ww.cache/products/templates/types_multiview_' . $type->id . '_header');
                 }
             }
             foreach ($prods as $pid) {
                 $product = Product::getInstance($pid, false, $enabledFilter);
                 if ($product && isset($product->id) && $product->id) {
                     $typeID = $product->get('product_type_id');
                     $type = ProductType::getInstance($typeID);
                     if (!$type) {
                         $c .= __('Missing Product Type: %1', array($typeID), 'core');
                     } else {
                         if (isset($_REQUEST['product_id'])) {
                             $c .= $type->render($product, 'singleview');
                         } else {
                             $c .= $type->render($product, 'multiview');
                         }
                     }
                 }
             }
             if (isset($type) && $type && count($prods)) {
                 // display first item's header
                 $smarty = Products_setupSmarty();
                 $c .= $smarty->fetch(USERBASE . '/ww.cache/products/templates/types_multiview_' . $type->id . '_footer');
             }
             // }
     }
     $categories = '';
     if (!isset($_REQUEST['products-search']) && isset($this->subCategories) && count($this->subCategories) && !@$PAGEDATA->vars['products_dont_show_sub_categories']) {
         $categories = '<ul class="products-categories categories">';
         foreach ($this->subCategories as $cr) {
             $cat = ProductCategory::getInstance($cr['id']);
             $categories .= '<li><a href="' . $cat->getRelativeUrl() . '">';
             $icon = '/products/categories/' . $cr['id'] . '/icon.png';
             if (file_exists(USERBASE . 'f' . $icon)) {
                 $subcatW = (int) $cat->vals['thumbsize_w'];
                 $subcatH = (int) $cat->vals['thumbsize_h'];
                 $categories .= '<img src="' . $cdnprefix . '/a/f=getImg/w=' . $subcatW . '/h=' . $subcatH . '/fmt=' . filemtime(USERBASE . 'f' . $icon) . $icon . '"/>';
             }
             $categories .= '<span>' . htmlspecialchars($cr['name']) . '</span>' . '</a></li>';
         }
         $categories .= '</ul>';
     }
     return $categories . $prevnext . '<div class="products">' . $c . '</div>' . $prevnext;
 }