Skip to content

Commit

Permalink
Merge pull request #29 from logeecom/3.5-4.0
Browse files Browse the repository at this point in the history
Release version 1.0.6
  • Loading branch information
pkrstojevic-logeecom authored Jan 26, 2021
2 parents 727ecac + 0e162b1 commit a1ffb12
Show file tree
Hide file tree
Showing 14 changed files with 712 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php


namespace Mollie\Gambio\Entity\Repository;

/**
* Class GambioOrderProductRepository
*
* @package Mollie\Gambio\Entity\Repository
*/
class GambioOrderProductRepository extends GambioBaseRepository
{
/**
* Returns list of orders products filtered by order id with following details
* - orders_products_id
* - products_id
* - products_quantity
* - products_properties_combis_id
* - products_attributes_filename
* - date_purchased
*
* @param string $orderId
*
* @return array
*/
public function getOrderProductsWithAttributes($orderId)
{
return $this->queryBuilder->query($this->getOrderProductsWithDetailsQuery($orderId))->result_array();
}

/**
* @inheritDoc
* @return string
*/
protected function _getTableName()
{
return TABLE_ORDERS_PRODUCTS;
}

/**
* @inheritDoc
* @return string
*/
protected function _getIdentifierKey()
{
return 'orders_products_id';
}

/**
* @param string $orderId
*
* @return string
*/
private function getOrderProductsWithDetailsQuery($orderId)
{
return 'SELECT DISTINCT
op.orders_products_id,
op.products_id,
op.products_quantity,
opp.products_properties_combis_id,
pad.products_attributes_filename,
o.date_purchased
FROM ' . TABLE_ORDERS_PRODUCTS . ' op
LEFT JOIN ' . TABLE_ORDERS . ' o
ON op.orders_id = o.orders_id
LEFT JOIN orders_products_properties opp
ON opp.orders_products_id = op.orders_products_id
LEFT JOIN ' . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . ' `opa`
ON opa.orders_products_id = op.orders_products_id
LEFT JOIN ' . TABLE_PRODUCTS_ATTRIBUTES . ' pa
ON op.products_id = pa.products_id
AND opa.options_id = pa.options_id
AND opa.options_values_id = pa.options_values_id
LEFT JOIN ' . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
ON pa.products_attributes_id=pad.products_attributes_id
WHERE
op.orders_id = '" . xtc_db_input($orderId) . "'";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php


namespace Mollie\Gambio\Entity\Repository;

/**
* Class GambioProductPropertiesRepository
*
* @package Mollie\Gambio\Entity\Repository
*/
class GambioProductAttributesRepository extends GambioBaseRepository
{
/**
* Returns product attributes list filtered by order id and order product id in format:
* - products_options
* - products_options_values
*
* @param int $orderId
* @param int $ordersProductsId
*
* @return array
*/
public function getOrdersAttributes($orderId, $ordersProductsId)
{
return $this->queryBuilder
->select('products_options, products_options_values')
->where('orders_id', $orderId, true)
->where('orders_products_id', $ordersProductsId, true)
->get($this->_getTableName())
->result('array');
}

/**
* @param int $productsId
* @param string $productsOptions
* @param string $productsOptionsValues
*
* @return mixed
*/
public function getProductAttributesId($productsId, $productsOptions, $productsOptionsValues)
{
$query = "SELECT pa.products_attributes_id
FROM products_options_values pov,
products_options po,
products_attributes pa
WHERE po.products_options_name = '" . addslashes($productsOptions) . "'
AND po.products_options_id = pa.options_id
AND pov.products_options_values_id = pa.options_values_id
AND pov.products_options_values_name = '" . addslashes($productsOptionsValues) . "'
AND pa.products_id = '" . $productsId . "'
LIMIT 1";

$result = $this->queryBuilder->query($query)->result_array();

return !empty($result[0]['products_attributes_id']) ? $result[0]['products_attributes_id'] : null;
}

/**
* Increases attributes stock
*
* @param int $productAttributesId
* @param int $quantity
*/
public function increaseAttributesStock($productAttributesId, $quantity)
{
$query = 'UPDATE products_attributes
SET attributes_stock = attributes_stock + ' . (int)$quantity . "
WHERE products_attributes_id = '" . (int)$productAttributesId . "'";

$this->queryBuilder->query($query);
}

/**
* @inheritDoc
*/
protected function _getTableName()
{
return TABLE_ORDERS_PRODUCTS_ATTRIBUTES;
}

/**
* @inheritDoc
*/
protected function _getIdentifierKey()
{
return 'products_attributes_id';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php


namespace Mollie\Gambio\Entity\Repository;

/**
* Class ProductPropertiesCombisRepository
*
* @package Mollie\Gambio\Entity\Repository
*/
class GambioProductPropertiesCombisRepository extends GambioBaseRepository
{

/**
* Returns row count specified by productId
*
* @param int $productId
*
* @return int
*/
public function countByProductId($productId)
{
return $this->queryBuilder
->select('products_properties_combis_id')
->from($this->_getTableName())
->where('products_id', $productId)
->get()
->num_rows();
}

/**
* Increases combi quantity by productId
*
* @param int $productId
* @param int $productsPropertiesCombisId
* @param int $quantity
*/
public function increaseCombiQuantity($productId, $productsPropertiesCombisId, $quantity)
{
$this->queryBuilder->query($this->getUpdateProductPropertiesCombiesQuery($productId, $productsPropertiesCombisId, $quantity));
}

/**
* @inheritDoc
*/
protected function _getTableName()
{
return 'products_properties_combis';
}

/**
* @inheritDoc
*/
protected function _getIdentifierKey()
{
return 'products_properties_combis_values_id';
}

/**
* @param int $productId
* @param int $productsPropertiesCombisId
* @param int $quantity
*
* @return string
*/
private function getUpdateProductPropertiesCombiesQuery($productId, $productsPropertiesCombisId, $quantity)
{
return 'UPDATE ' . $this->_getTableName() . '
SET combi_quantity = combi_quantity + ' . (int)$quantity . "
WHERE products_properties_combis_id = '" . (int)$productsPropertiesCombisId . "'
AND products_id = '" . (int)$productId . "'";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,49 @@
*/
class GambioProductRepository extends GambioBaseRepository
{
const INCREASE_OPERATOR = '+';
const DECREASE_OPERATOR = '-';
const PRODUCT_QUANTITY_COLUMN = 'products_quantity';
const ORDERED_QUANTITY_COLUMN = 'products_ordered';


/**
* Increases products stock by given value for specific product
*
* @param int $productId
* @param int $quantity
*/
public function increaseProductQuantity($productId, $quantity)
{
$this->updateQuantity($productId, $quantity, self::PRODUCT_QUANTITY_COLUMN, self::INCREASE_OPERATOR);
}

/**
* Decreases ordered quantity by given value for specific product
*
* @param int $productId
* @param int $quantity
*/
public function decreaseProductOrderedQuantity($productId, $quantity)
{
$this->updateQuantity($productId, $quantity, self::ORDERED_QUANTITY_COLUMN, self::DECREASE_OPERATOR);
}

/**
* @param int $productId
* @param int $quantity
* @param string $columnName
* @param string $operator
*/
private function updateQuantity($productId, $quantity, $columnName, $operator)
{
$query = 'UPDATE ' .$this->_getTableName() . '
SET ' . $columnName . ' = ' . $columnName . $operator . (int)$quantity . "
WHERE products_id = '" . (int)$productId . "'";

$this->queryBuilder->query($query);
}

/**
* @return string
*/
Expand All @@ -25,6 +68,4 @@ protected function _getIdentifierKey()
{
return 'products_id';
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php


namespace Mollie\Gambio\Entity\Repository;

/**
* Class GambioSpecialsRepository
*
* @package Mollie\Gambio\Entity\Repository
*/
class GambioSpecialsRepository extends GambioBaseRepository
{
/**
* Counts specials records filtered by productId and datePurchased
*
* @param string $productId
* @param string $datePurchased
*h
* @return int
*/
public function countByProductAndDate($productId, $datePurchased)
{
return $this->queryBuilder->query($this->getFilterByProductAndDateQuery($productId, $datePurchased))->num_rows();
}

/**
* Increase current specials quantity with the given value
*
* @param string $productId
* @param int $quantity
*/
public function increaseProductsQuantity($productId, $quantity)
{
$this->queryBuilder->query($this->getIncreaseQuantityQuery($productId, $quantity));
}

/**
* @inheritDoc
*/
protected function _getTableName()
{
return TABLE_SPECIALS;
}

/**
* @inheritDoc
*/
protected function _getIdentifierKey()
{
return 'specials_id';
}

/**
* @param string $productId
* @param string $datePurchased
*
* @return string
*/
private function getFilterByProductAndDateQuery($productId, $datePurchased)
{
return 'SELECT (specials_date_added)
FROM ' . $this->_getTableName() . "
WHERE specials_date_added < '" . $datePurchased . "'
AND products_id = '" . $productId . "'";
}

/**
* @param int $productId
* @param int $quantity
*
* @return string
*/
private function getIncreaseQuantityQuery($productId, $quantity)
{
return 'UPDATE ' . TABLE_SPECIALS . '
SET specials_quantity = specials_quantity + ' . (int)$quantity . "
WHERE products_id = '" . (int)$productId . "'";
}
}
Loading

0 comments on commit a1ffb12

Please sign in to comment.