Skip to content
Code-Schnipsel Gruppen Projekte
Bestätigt Commit 8ca266e8 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

feat: quiqqer/products#153

Übergeordneter ee62cf79
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -20,9 +20,9 @@ function ($basketId, $orderHash) {
return false;
}
$Basket = new QUI\ERP\Order\Basket\Basket($basketId, $User);
$Basket = new QUI\ERP\Order\Basket\Basket($basketId, $User);
$OrderHandler = QUI\ERP\Order\Handler::getInstance();
$Order = null;
$Order = null;
if (!empty($orderHash)) {
try {
......@@ -44,6 +44,7 @@ function ($basketId, $orderHash) {
$Basket->toOrder($Order);
}
return $Order->getHash();
},
['basketId', 'orderHash']
......
<?php
/**
* This file contains package_quiqqer_order_ajax_frontend_order_hasBasketEquivalent
*/
/**
* Return the articles of an order
*
* @param integer $orderHash
* @return array
*/
use QUI\ERP\Order\Handler as OrderHandler;
use QUI\ERP\Products\Utils\Products as ProductUtils;
use QUI\ERP\Products\Field\Types\BasketConditions;
QUI::$Ajax->registerFunction(
'package_quiqqer_order_ajax_frontend_order_hasBasketEquivalent',
function ($orderHash) {
try {
$Order = QUI\ERP\Order\Handler::getInstance()->getOrderByHash($orderHash);
} catch (QUI\Exception $Exception) {
return true;
}
$Basket = OrderHandler::getInstance()->getBasketFromUser(QUI::getUserBySession());
if ($Basket->count() !== $Order->count()) {
return false;
}
$products = $Basket->getProducts()->getProducts();
$articles = $Order->getArticles()->toArray();
$articles = $articles['articles'];
$isInArticles = function ($productId) use ($articles) {
foreach ($articles as $article) {
if ($article['id'] === $productId) {
return true;
}
}
return false;
};
/* @var $Product \QUI\ERP\Order\Basket\Product */
foreach ($products as $Product) {
$condition = ProductUtils::getBasketCondition($Product);
switch ($condition) {
case BasketConditions::TYPE_2:
case BasketConditions::TYPE_6:
return false;
}
if ($isInArticles($Product->getId()) === false) {
return false;
}
}
return true;
},
['orderHash']
);
<?php
/**
* This file contains package_quiqqer_order_ajax_frontend_order_getStep
*/
/**
* Return the wanted step
*
* @param integer $orderId
* @param string $current
* @return array
*/
use QUI\ERP\Order\Basket\BasketOrder;
QUI::$Ajax->registerFunction(
'package_quiqqer_order_ajax_frontend_order_setQuantity',
function ($orderHash, $pos, $quantity) {
try {
QUI\ERP\Order\Handler::getInstance()->getOrderByHash($orderHash);
} catch (QUI\Exception $Exception) {
return;
}
$quantity = (int)$quantity;
$pos = (int)$pos - 1;
$Basket = new BasketOrder($orderHash);
$Products = $Basket->getProducts();
$products = $Products->getProducts(); // get as array
if (isset($products[$pos])) {
$products[$pos]->setQuantity($quantity);
}
$Basket->toOrder();
},
['orderHash', 'pos', 'quantity']
);
......@@ -423,8 +423,9 @@ define('package/quiqqer/order/bin/frontend/classes/Basket', [
}
// create a new order
if (basketConditionValue === 2) {
if (basketConditionValue === 2 || basketConditionValue === 6) {
// 2 = Kann nur alleine in den Warenkorb
// 6 = Kann nur alleine in den Warenkorb
// daher neue order in process
let newHash;
......@@ -457,7 +458,7 @@ define('package/quiqqer/order/bin/frontend/classes/Basket', [
'BASKET_CONDITION_PRODUCT_NOT_ALLOWED',
'REPLACED WITH ARTICLE POS ' + (p + 1)
);
return self.removeProductPos(p + 1).then(() => {
return Product.setQuantity(quantity);
});
......
......@@ -37,10 +37,10 @@ define('package/quiqqer/order/bin/frontend/controls/basket/Basket', [
this.getAttribute('basketId', Basket.getId());
}
this.$Loader = new QUILoader();
this.$Loader = new QUILoader();
this.$isInOrder = null;
this.$Order = null;
this.$isLoaded = false;
this.$Order = null;
this.$isLoaded = false;
this.addEvents({
onInject : this.$onInject,
......@@ -104,7 +104,7 @@ define('package/quiqqer/order/bin/frontend/controls/basket/Basket', [
}
Loaded.then(function () {
var products = [];
var products = [];
var basketProducts = Basket.getProducts();
for (var i = 0, len = basketProducts.length; i < len; i++) {
......@@ -158,20 +158,20 @@ define('package/quiqqer/order/bin/frontend/controls/basket/Basket', [
* - article changing
*/
$setEvents: function () {
var self = this,
Order = this.getOrderProcess();
const self = this,
Order = this.getOrderProcess();
// remove
this.getElm().getElements('.fa-trash').getParent('button').addEvent('click', function (event) {
event.stop();
self.$Loader.show();
var Article = this.getParent('.quiqqer-order-basket-small-articles-article');
let Article = this.getParent('.quiqqer-order-basket-small-articles-article');
// big basket
if (!Article) {
var Node = this;
Article = Node.getParent('.quiqqer-order-basket-articles-article');
let Node = this;
Article = Node.getParent('.quiqqer-order-basket-articles-article');
if (Node.nodeName !== 'BUTTON') {
Node = Node.getParent('button');
......@@ -205,7 +205,7 @@ define('package/quiqqer/order/bin/frontend/controls/basket/Basket', [
this.getElm().getElements('[name="quantity"]').addEvent('focus', function () {
this.set('data-quantity', parseInt(this.value));
var Parent = this.parentNode;
const Parent = this.parentNode;
if (!Parent.getElement('.quiqqer-order-basket-articles-article-quantity-refresh')) {
new Element('button', {
......@@ -220,11 +220,12 @@ define('package/quiqqer/order/bin/frontend/controls/basket/Basket', [
});
this.getElm().getElements('[name="quantity"]').addEvent('blur', function () {
var Article = this.getParent('.quiqqer-order-basket-small-articles-article');
var quantity = this.value;
var oldQuantity = this.get('data-quantity');
var Parent = this.parentNode;
var Refresh = Parent.getElement('.quiqqer-order-basket-articles-article-quantity-refresh');
const Parent = this.parentNode;
const Refresh = Parent.getElement('.quiqqer-order-basket-articles-article-quantity-refresh');
let Article = this.getParent('.quiqqer-order-basket-small-articles-article');
let quantity = this.value;
let oldQuantity = this.get('data-quantity');
if (Refresh) {
Refresh.destroy();
......@@ -245,20 +246,28 @@ define('package/quiqqer/order/bin/frontend/controls/basket/Basket', [
Article = this.getParent('.quiqqer-order-basket-articles-article');
}
var pos = Article.get('data-pos');
let pos = Article.get('data-pos');
this.set('data-quantity', quantity);
Basket.setQuantity(pos, quantity).then(function () {
if (self.isInOrderProcess()) {
return Basket.toOrder(self.getOrderHash()).then(function () {
if (Order) {
Order.enable();
}
self.refresh();
});
// check if basket is an order in process
// check if the order in process has no basket
self.$hasBasketEquivalent().then((status) => {
if (status === false) {
return self.$setQuantity(pos, quantity);
}
return Basket.setQuantity(pos, quantity).then(function () {
if (self.isInOrderProcess()) {
return Basket.toOrder(self.getOrderHash()).then(function () {
if (Order) {
Order.enable();
}
self.refresh();
});
}
});
}).then(() => {
self.refresh();
if (Order) {
......@@ -268,6 +277,30 @@ define('package/quiqqer/order/bin/frontend/controls/basket/Basket', [
});
},
$hasBasketEquivalent: function () {
console.log('$hasBasketEquivalent');
return new Promise((resolve) => {
QUIAjax.get('package_quiqqer_order_ajax_frontend_order_hasBasketEquivalent', resolve, {
'package': 'quiqqer/order',
orderHash: this.getOrderHash(),
});
});
},
$setQuantity: function (pos, quantity) {
console.log('$setQuantity');
return new Promise((resolve) => {
QUIAjax.get('package_quiqqer_order_ajax_frontend_order_setQuantity', resolve, {
'package': 'quiqqer/order',
orderHash: this.getOrderHash(),
pos : pos,
quantity : quantity
});
});
},
/**
* Is the user a guest?
*
......
......@@ -7,8 +7,16 @@
namespace QUI\ERP\Order\Utils;
use QUI;
use QUI\ERP\Products\Field\Types\BasketConditions;
use function date;
use function is_array;
use function mb_strlen;
use function mb_substr;
use function method_exists;
use function str_replace;
use function strftime;
use function strpos;
/**
* Class Utils
......@@ -188,8 +196,8 @@ public static function getOrderProfileUrl(QUI\Projects\Project $Project, $Order)
$ending = false;
if (\strpos($url, '.html')) {
$url = \str_replace('.html', '', $url);
if (strpos($url, '.html')) {
$url = str_replace('.html', '', $url);
$ending = true;
}
......@@ -217,20 +225,20 @@ public static function getOrderPrefix(): string
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
return \date('Y') . '-';
return date('Y') . '-';
}
if ($setting === false) {
return \date('Y') . '-';
return date('Y') . '-';
}
$prefix = \strftime($setting);
$prefix = strftime($setting);
if (\mb_strlen($prefix) < 100) {
if (mb_strlen($prefix) < 100) {
return $prefix;
}
return \mb_substr($prefix, 0, 100);
return mb_substr($prefix, 0, 100);
}
/**
......@@ -263,6 +271,8 @@ public static function importProductsToBasketList(
$products = [];
}
$count = count($products);
foreach ($products as $productData) {
if (!isset($productData['id'])) {
continue;
......@@ -316,7 +326,7 @@ public static function importProductsToBasketList(
]
);
if ($Order && \method_exists($Order, 'addFrontendMessage')) {
if ($Order && method_exists($Order, 'addFrontendMessage')) {
$Order->addFrontendMessage($message);
} else {
if (!QUI::getUsers()->isSystemUser(QUI::getUserBySession())) {
......@@ -327,16 +337,31 @@ public static function importProductsToBasketList(
continue;
}
$Product = new QUI\ERP\Order\Basket\Product($productData['id'], $productData);
$Product = new QUI\ERP\Order\Basket\Product($productData['id'], $productData);
$condition = QUI\ERP\Products\Utils\Products::getBasketCondition($Product);
if (isset($productData['quantity'])) {
if ($condition === BasketConditions::TYPE_2 ||
$condition === BasketConditions::TYPE_6) {
// if several products are to be imported and a Type2 and Type6 are to be imported.
// this product is ignored and not imported
if ($count >= 2) {
continue;
}
}
if ($condition === BasketConditions::TYPE_2 ||
$condition === BasketConditions::TYPE_3 ||
$condition === BasketConditions::TYPE_5
) {
// quantity stays at 1
$Product->setQuantity(1);
} elseif (isset($productData['quantity'])) {
$Product->setQuantity($productData['quantity']);
}
$List->addProduct($Product);
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeDebugException($Exception);
// @todo produkt existiert nicht, dummy product
}
}
......@@ -425,12 +450,13 @@ public static function isBasketProductEditable($product): bool
} catch (QUI\Exception $Exception) {
return false;
}
// TYPE_1 Kann ohne Einschränkung in den Warenkorb
// TYPE_2 Kann nur alleine in den Warenkorb
// TYPE_2 Kann nur alleine und nur einmalig in den Warenkorb
// TYPE_3 Kann mit anderen Produkten einmalig in den Warenkorb
// TYPE_4 Kann mit anderen Produkten diesen Typs nicht in den Warenkorb
// TYPE_5 Kann mit anderen Produkten diesen Typs einmalig in den Warenkorb
// TYPE_6 Kann nur alleine und mehrmalig in den Warenkorb
if ($condition === QUI\ERP\Products\Field\Types\BasketConditions::TYPE_2
|| $condition === QUI\ERP\Products\Field\Types\BasketConditions::TYPE_3
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren