Skip to content

Commit

Permalink
Actualizacion
Browse files Browse the repository at this point in the history
  • Loading branch information
Garrarop committed Nov 11, 2020
1 parent 0e28e06 commit 37fb306
Show file tree
Hide file tree
Showing 24 changed files with 676 additions and 333 deletions.
36 changes: 0 additions & 36 deletions Pruebapost.php

This file was deleted.

32 changes: 0 additions & 32 deletions api.php

This file was deleted.

12 changes: 12 additions & 0 deletions config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>dmixadapter</name>
<displayName><![CDATA[Dmix Adapter]]></displayName>
<version><![CDATA[1.0.0]]></version>
<description><![CDATA[]]></description>
<author><![CDATA[Dmix]]></author>

<is_configurable>0</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
</module>
153 changes: 153 additions & 0 deletions config/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

return [
'resources' => [
'products' => [
'query' => [
'selectClause' => 'SELECT p.id_product, pl.name, pl.description_short, pl.description,p.price,i.id_image, pad.id_product_attribute',
'fromClause' => 'FROM ps_product p
INNER JOIN ps_product_lang pl ON pl.id_product = p.id_product
INNER JOIN ps_category_lang cl ON cl.id_category = p.id_category_default AND cl.id_lang = pl.id_lang
LEFT JOIN ps_product_attribute pad ON pad.id_product = p.id_product AND pad.default_on = 1
LEFT JOIN ps_image i ON i.id_product = p.id_product AND i.cover = 1',
'whereClause' => 'WHERE p.active = 1 AND pl.id_lang = 1',
'groupClause' =>'GROUP BY p.id_product',
'orderClause' => ''
],
'with' => [
'combinations' => [
'selectClause' => 'GROUP_CONCAT(distinct pa.id_product_attribute order by pa.id_product_attribute) AS WithCombos',
'fromClause' => 'LEFT JOIN ps_product_attribute pa ON pa.id_product = p.id_product',
'whereClause' => '',
'groupClause' => '',
'orderClause' => ''
],
'categories' => [
'selectClause' => 'GROUP_CONCAT(distinct cp.id_category order by cp.id_category) AS WithCategories',
'fromClause' => 'LEFT JOIN ps_category_product cp ON cp.id_product = p.id_product',
'whereClause' => '',
'groupClause' => '',
'orderClause' => ''
],
'images' => [
'selectClause' => 'GROUP_CONCAT(distinct ie.id_image order by ie.id_image) AS WithImages',
'fromClause' => 'LEFT JOIN ps_image ie ON ie.id_product = p.id_product',
'whereClause' => '',
'groupClause' => '',
'orderClause' => ''
]
]
],
'categories' => [
'query' => [
'selectClause' => 'SELECT c.id_category, cl.name, cl.description, c.level_depth ',
'fromClause' => 'FROM ps_category c
INNER JOIN ps_category_lang cl ON cl.id_category = c.id_category',
'whereClause' => 'WHERE cl.id_lang = 1',
'groupClause' => 'GROUP BY c.id_category',
'orderClause' => 'order by level_depth, id_category'
],
'with' => [
'products' => [
'selectClause' => 'GROUP_CONCAT(cp.id_product) AS id_products',
'fromClause' => 'INNER JOIN ps_category_product cp ON cp.id_category = c.id_category',
'whereClause' => '',
'groupClause' => '',
'orderClause' => ''
],
'parent' => [
'selectClause' => 'c.id_parent',
'fromClause' => '',
'whereClause' => '',
'groupClause' => '',
'orderClause' => ''
]
]
],
'customers' => [
'query' => [
'selectClause' => 'SELECT id_customer, firstname, lastname, email',
'fromClause' => 'FROM ps_customer c',
'whereClause' => '',
'groupClause' => '',
'orderClause' => ''
],
'with' => []
],
'images' => [
'query' => [
'selectClause' => 'SELECT distinct p.id_product, i.id_image,color AS codigo, psatrl.name AS color',
'fromClause' => 'FROM ps_product p
INNER JOIN ps_image i ON p.id_product = i.id_product
INNER JOIN ps_product_attribute atr ON atr.id_product = p.id_product
INNER JOIN ps_product_attribute_image atrimg ON atrimg.id_product_attribute = atr.id_product_attribute AND atrimg.id_image = i.id_image
INNER JOIN ps_product_attribute_combination com ON com.id_product_attribute = atr.id_product_attribute
INNER JOIN ps_attribute psatr ON psatr.id_attribute = com.id_attribute
INNER JOIN ps_attribute_lang psatrl ON psatr.id_attribute = psatrl.id_attribute
INNER JOIN ps_attribute_group ag ON psatr.id_attribute_group = ag.id_attribute_group',
'whereClause' => 'WHERE ag.is_color_group = 1 AND psatrl.id_lang =1',
'groupClause' => '',
'orderClause' => ''
],
'with' => []
],
'combinations' => [
'query' => [
'selectClause' => 'SELECT pac.id_product_attribute, pa.id_product, sum(pa.price) AS price, pai.id_image,
(SELECT SUM(quantity) FROM ps_stock_available WHERE id_product_attribute = pac.id_product_attribute) AS stock,
GROUP_CONCAT(agl.name, "_",al.name ORDER BY agl.id_attribute_group SEPARATOR "-") AS combo,
GROUP_CONCAT(al.id_attribute) AS id_attributes_combo',
'fromClause' => 'FROM ps_product_attribute_combination pac
LEFT JOIN ps_attribute a ON a.id_attribute = pac.id_attribute
LEFT JOIN ps_attribute_group ag ON ag.id_attribute_group = a.id_attribute_group
LEFT JOIN ps_attribute_lang al ON a.id_attribute = al.id_attribute
LEFT JOIN ps_attribute_group_lang agl ON ag.id_attribute_group = agl.id_attribute_group AND agl.id_lang = al.id_lang
LEFT JOIN ps_product_attribute_image pai ON pai.id_product_attribute = pac.id_product_attribute
INNER JOIN ps_product_attribute pa ON pa.id_product_attribute = pac.id_product_attribute',
'whereClause' => 'WHERE al.id_lang = 1',
'groupClause' => 'GROUP BY pac.id_product_attribute, pai.id_image',
'orderClause' => ''
],
'with' => []
],
'carts' => [
'query' => [
'selectClause' => 'SELECT c.id_cart, c.id_customer, CASE WHEN o.id_order IS NULL THEN 0 ELSE 1 END AS active',
'fromClause' => 'FROM ps_cart c
LEFT JOIN ps_orders o ON o.id_cart = c.id_cart',
'whereClause' => '',
'groupClause' => 'GROUP BY id_cart,id_customer',
'orderClause' => ''
],
'with' => [
'products' => [
'selectClause' => 'GROUP_CONCAT(cp.id_product, "_" , cp.quantity) AS id_products ',
'fromClause' => 'INNER JOIN ps_cart_product cp ON cp.id_cart = c.id_cart',
'whereClause' => '',
'groupClause' => '',
'orderClause' => ''
],
'promos' => [
'selectClause' => 'GROUP_CONCAT(ccr.id_cart_rule) AS id_promos ',
'fromClause' => 'LEFT JOIN ps_cart_cart_rule ccr ON ccr.id_cart = c.id_cart',
'whereClause' => '',
'groupClause' => '',
'orderClause' => ''
]
]
],
'promos' => [
'query' => [
'selectClause' => 'SELECT id_cart_rule, code,
CASE WHEN reduction_percent != 0 THEN reduction_percent ELSE reduction_amount END AS value,
CASE WHEN reduction_percent != 0 THEN "percentage" ELSE "fixed" END AS type,
date_from, date_to, description, free_shipping, active',
'fromClause' => 'FROM ps_cart_rule',
'whereClause' => '',
'groupClause' => '',
'orderClause' => ''
],
'with' => []
]
]
];
10 changes: 5 additions & 5 deletions config_es.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>garraroprueba</name>
<displayName><![CDATA[M&oacute;dulo de Prueba]]></displayName>
<name>dmixadapter</name>
<displayName><![CDATA[Digital Mix Adapter]]></displayName>
<version><![CDATA[1.0.0]]></version>
<description><![CDATA[M&oacute;dulo para hacer pruebas en Prestashop]]></description>
<author><![CDATA[Garraro]]></author>
<description><![CDATA[]]></description>
<author><![CDATA[Digital Mix]]></author>
<tab><![CDATA[]]></tab>
<is_configurable>1</is_configurable>
<is_configurable>0</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
115 changes: 115 additions & 0 deletions controllers/classes/queryBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

/**
*
*/
class QueryBuilder
{
private $selectClause = "";
private $fromClause = "";
private $whereClause = "";
private $groupClause = "";
private $orderClause = "";
private $modifiers = [];

function __construct($array)
{
$this->selectClause = $array['query']['selectClause'];
$this->fromClause = $array['query']['fromClause'];
$this->whereClause = $array['query']['whereClause'];
$this->groupClause = $array['query']['groupClause'];
$this->orderClause = $array['query']['orderClause'];

foreach ($array['with'] as $modifier => $data) {
$this->modifiers[$modifier] = $data;
}

}
public function addSelect($select)
{
if ($select != ""){
if ($this->selectClause != ""){
$this->selectClause .= ", $select";
} else {
$this->selectClause = "select $select";
}
}
}

public function addFrom($from)
{
if ($from != ""){
if ($this->fromClause != ""){
$this->fromClause .= " $from";
} else {
$this->fromClause = "from $from";
}
}
}

public function addWhereM($where)
{
if ($where != "") {
if ($this->whereClause != ""){
$this->whereClause .= " $where";
} else {
$this->whereClause = "where $where";
}
}
}

public function addWhere($key, $value, $operator = "=")
{
if ($key != "")
if ($this->whereClause != ""){
$this->whereClause .= " and $key $operator $value";
} else {
$this->whereClause = "Where $key $operator $value";
}
}

public function addGroup($group)
{
if ($group != "") {
if ($this->groupClause != ""){
$this->groupClause .= ", $group";
} else {
$this->groupClause = "group by $group";
}
}
}

public function addOrder($order)
{
if ($order != "") {
if ($this->orderClause != ""){
$this->orderClause .= ", $order";
} else {
$this->orderClause = "order by $order";
}
}
}
public function getM()
{
return $this->modifiers;
}
public function addModifiers($array)
{
foreach ($array as $key => $modifier) {
foreach ($this->modifiers as $tModifier => $data) {
if ($tModifier == $modifier){
$this->addSelect($this->modifiers[$tModifier]['selectClause']);
$this->addFrom($this->modifiers[$tModifier]['fromClause']);
$this->addWhereM($this->modifiers[$tModifier]['whereClause']);
$this->addGroup($this->modifiers[$tModifier]['groupClause']);
$this->addOrder($this->modifiers[$tModifier]['orderClause']);
}
}
}
}

public function toString(){
return $this->selectClause . " " . $this->fromClause . " " . $this->whereClause . " " .
$this->groupClause . " " . $this->orderClause;
}
}
Loading

0 comments on commit 37fb306

Please sign in to comment.