Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once MODX_CORE_PATH . 'model/modx/modrequest.class.php';
- $txt = '';
- $config = $modx->config;
- $dsn = $config['dsn'];
- $user = $config['username'];
- $password = $config['password'];
- $request = new modRequest($modx);
- if($request->getParameters('models_id')) {
- try {
- $dbh = new PDO($dsn, $user, $password);
- } catch (PDOException $e) {
- echo 'Connection failed: ' . $e->getMessage();
- }
- $query = $dbh->prepare("
- SELECT paramvalues.id as model_id, paramvalues.value as model_name, pv.id as mark_id, pv.value as mark_name
- FROM paramvalues
- JOIN paramvalues pv ON paramvalues.parent = pv.id
- WHERE paramvalues.id = :id
- ");
- $txt .= $modx->getChunk('startProductsBlock');
- $models = array($request->getParameters('models_id'));
- foreach($models as $modelId) {
- $query->execute(array('id' => $modelId));
- $selected = $query->fetch(PDO::FETCH_OBJ);
- $modx->setPlaceholder('model', $selected->model_name);
- $modx->setPlaceholder('mark', $selected->mark_name);
- $modx->setPlaceholder('model_id', $selected->model_id);
- $modx->setPlaceholder('mark_id', $selected->mark_id);
- $txt .= $modx->getChunk('productBreadcrumb');
- }
- $txt .= $modx->getChunk('startProductTable');
- foreach($models as $modelId) {
- $query = $dbh->prepare("
- SELECT * FROM params WHERE paramnames_id = '13616' AND paramvalues_id = :parent
- ");
- $query->execute(array('parent' => $modelId));
- $result = $query->fetchAll();
- $i = 0;
- foreach($result as $row) {
- if($i%2 == 0) $txt .= "<tr>";
- $i++;
- $query = $dbh->prepare("
- SELECT *
- FROM params
- LEFT JOIN paramvalues ON params.paramvalues_id = paramvalues.id
- LEFT JOIN nomenkl ON params.nomenkl_id = nomenkl.id
- WHERE `nomenkl_id` = :parent AND (params.paramnames_id = '6' OR params.paramnames_id = '13618' OR params.paramnames_id = '13613' OR params.paramnames_id = '13619' OR params.paramnames_id = '13615')
- ");
- $query->execute(array('parent' => $row['nomenkl_id']));
- $product = $query->fetchAll();
- $res = array();
- foreach($product as $tmp) {
- $res[$tmp['paramnames_id']] = $tmp['value'];
- }
- $modx->setPlaceholder('price', $res['6']);
- $modx->setPlaceholder('description', $res['13615']);
- $modx->setPlaceholder('image', $res['13619']);
- $modx->setPlaceholder('article', $product[0]['article']);
- $modx->setPlaceholder('quantity', $product[0]['quantity']);
- $modx->setPlaceholder('title', $product[0]['nomenklname']);
- $modx->setPlaceholder('cat', $res['13618']);
- $modx->setPlaceholder('product_id', $row['nomenkl_id']);
- $txt .= $modx->getChunk('product');
- if($i%2 == 0) $txt .= "</tr>";
- }
- }
- $txt .= $modx->getChunk('endProductTable');
- $txt .= $modx->getChunk('endProductsBlock');
- return $txt;
- }
Add Comment
Please, Sign In to add comment