Skip to content
Code-Schnipsel Gruppen Projekte
Commit da3c0e24 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

feat: Warenkorb

Übergeordneter 994539e2
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
<?php
/**
* This file contains package_quiqqer_order_ajax_frontend_basket_existsArticle
*/
use QUI\ERP\Products\Handler\Products;
/**
* Is the product still active and available?
*
* @param integer $productId
* @return bool
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_order_ajax_frontend_basket_existsProduct',
function ($productId) {
try {
$Product = Products::getProduct($productId);
$Product->getView();
return true;
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
return false;
},
array('productId')
);
<?php
/**
* This file contains package_quiqqer_order_ajax_frontend_basket_save
*/
/**
* Saves the basket to the temporary order
*
* @param integer $orderId
* @param string $articles
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_order_ajax_frontend_basket_save',
function ($orderId, $articles) {
$Basket = new QUI\ERP\Order\Basket\Basket($orderId);
$Basket->import(json_decode($articles, true));
$Basket->save();
},
array('orderId', 'articles')
);
......@@ -23,10 +23,13 @@ define('package/quiqqer/order/bin/frontend/classes/Basket', [
Extends: QUIDOM,
Type : 'package/quiqqer/order/bin/frontend/classes/Basket',
Binds: [
'$onArticleChange'
],
initialize: function (options) {
this.parent(options);
this.$isLoaded = false;
this.$articles = [];
this.$orders = {};
this.$orderid = false;
......@@ -42,13 +45,14 @@ define('package/quiqqer/order/bin/frontend/classes/Basket', [
// basket from user
if (QUIQQER_USER && QUIQQER_USER.id) {
return this.loadLastOrder().then(function () {
console.warn(this.$articles);
this.$isLoaded = true;
this.fireEvent('refresh', [this]);
}.bind(this));
}
var articles = [],
data = QUI.Storage.get('product-order');
data = QUI.Storage.get('quiqqer-basket-articles');
this.$orderid = String.uniqueID();
......@@ -90,12 +94,12 @@ define('package/quiqqer/order/bin/frontend/classes/Basket', [
return Promise.all(proms).then(function () {
var self = this;
if (this.getAttribute('productsNotExists')) {
if (this.getAttribute('articlesNotExists')) {
QUI.getMessageHandler().then(function (MH) {
MH.addError(
QUILocale.get(lg, 'message.article.removed')
);
self.getAttribute('productsNotExists', false);
self.getAttribute('articlesNotExists', false);
});
}
......@@ -105,8 +109,8 @@ define('package/quiqqer/order/bin/frontend/classes/Basket', [
},
/**
* Return the loading status of the watchlist
* is the watchlist already loaded?
* Return the loading status of the basket
* is the basket already loaded?
*
* @returns {boolean}
*/
......@@ -115,7 +119,7 @@ define('package/quiqqer/order/bin/frontend/classes/Basket', [
},
/**
* Return the quantity of the products in the current list
* Return the quantity of the articles in the current list
*
* @returns {Number}
*/
......@@ -154,6 +158,9 @@ define('package/quiqqer/order/bin/frontend/classes/Basket', [
$loadOrderData: function (data) {
var articles = data.articles;
this.$orderid = data.id;
this.$articles = [];
if (typeof data.articles.articles === 'undefined') {
return Promise.resolve();
}
......@@ -162,13 +169,25 @@ define('package/quiqqer/order/bin/frontend/classes/Basket', [
return Promise.resolve();
}
var promiseList = [];
console.log('######');
console.log(articles);
articles = articles.articles;
return new Promise(function (resolve) {
resolve();
});
for (var i = 0, len = articles.length; i < len; i++) {
promiseList.push(
this.addArticle(
articles[i].id,
articles[i].quantity,
articles[i].fields
)
);
}
if (!promiseList.length) {
return Promise.resolve();
}
return Promise.all(promiseList);
},
/**
......@@ -237,18 +256,20 @@ define('package/quiqqer/order/bin/frontend/classes/Basket', [
quantity = 1;
}
if (typeOf(article) === 'package/quiqqer/watchlist/bin/classes/Product') {
if (typeOf(article) === 'package/quiqqer/order/bin/frontend/classes/Article') {
articleId = parseInt(article.getId());
fields = article.getFields();
quantity = article.getQuantity();
}
return this.existsProduct(articleId).then(function (available) {
if (!available) {
self.setAttribute('productsNotExists', true);
self.setAttribute('articlesNotExists', true);
return Promise.resolve();
}
this.fireEvent('refreshBegin', [this]);
this.fireEvent('addBegin');
self.fireEvent('refreshBegin', [this]);
self.fireEvent('addBegin');
return new Promise(function (resolve) {
require([
......@@ -279,10 +300,111 @@ define('package/quiqqer/order/bin/frontend/classes/Basket', [
self.fireEvent('refresh', [self]);
self.fireEvent('add', [self]);
});
});
});
}).catch(function (err) {
console.error(err);
});
},
/**
* Saves the basket to the temporary order
*
* @param {Boolean} [force] - force the save delay, prevent homemade ddos
* @return {Promise}
*/
save: function (force) {
force = force || false;
return new Promise(function (resolve) {
if (force === false) {
// save delay, prevent homemade ddos
if (this.$saveDelay) {
clearTimeout(this.$saveDelay);
}
this.$saveDelay = (function () {
this.save(true).then(resolve);
}).delay(100, this);
return;
}
if (!this.$orderid) {
resolve();
return;
}
var articles = [];
for (var i = 0, len = this.$articles.length; i < len; i++) {
articles.push(this.$articles[i].getAttributes());
}
// locale storage
if (QUIQQER_USER && QUIQQER_USER.id) {
QUIAjax.post('package_quiqqer_order_ajax_frontend_basket_save', resolve, {
'package': 'quiqqer/order',
orderId : this.$orderid,
articles : JSON.encode(articles)
});
return;
}
var data = QUI.Storage.get('quiqqer-basket-articles');
if (!data) {
data = {};
} else {
data = JSON.decode(data);
if (!data) {
data = {};
}
}
if (typeof data.articles === 'undefined') {
data.articles = {};
}
data.currentList = this.$listid;
data.articles[this.$listid] = articles;
QUI.Storage.set('quiqqer-basket-articles', JSON.encode(data));
resolve();
}.bind(this));
},
/**
* Exists the article? Is it available?
*
* @param {String|Number} productId
* @return {Promise}
*/
existsProduct: function (productId) {
return new Promise(function (resolve, reject) {
QUIAjax.get('package_quiqqer_order_ajax_frontend_basket_existsProduct', resolve, {
'package': 'quiqqer/order',
productId: productId,
onError : reject
});
});
},
/**
* event : on change
*/
$onArticleChange: function () {
this.fireEvent('refreshBegin', [this]);
this.save().then(function () {
this.fireEvent('refresh', [this]);
}.bind(this));
}
});
});
......@@ -5,9 +5,10 @@ define('package/quiqqer/order/bin/frontend/controls/buttons/ProductToBasket', [
'qui/QUI',
'qui/controls/Control',
'package/quiqqer/order/bin/frontend/Basket'
'package/quiqqer/order/bin/frontend/Basket',
'package/quiqqer/order/bin/frontend/classes/Article'
], function (QUI, QUIControl, Basket) {
], function (QUI, QUIControl, Basket, BasketArticle) {
"use strict";
return new Class({
......@@ -76,7 +77,95 @@ define('package/quiqqer/order/bin/frontend/controls/buttons/ProductToBasket', [
* add the product to the watchlist
*/
$addProductToBasket: function () {
console.warn(111);
this.getElm().addClass('disabled');
this.$Text.setStyles({
visibility: 'hidden'
});
var self = this,
count = 0,
size = this.getElm().getSize();
if (this.$Input) {
this.$Input.setStyles({
opacity : 0,
visibility: 'hidden'
});
count = parseInt(this.$Input.value);
}
if (!count) {
count = 0;
}
var Loader = new Element('div', {
html : '<span class="fa fa-spinner fa-spin"></span>',
styles: {
fontSize : (size.y / 3).round(),
height : '100%',
left : 0,
lineHeight: size.y,
position : 'absolute',
textAlign : 'center',
top : 0,
width : '100%'
}
}).inject(this.getElm());
var Article = new BasketArticle({
id: this.getAttribute('productId')
});
// is the button in a produkt?
var fields = {},
ProductElm = this.getElm().getParent('[data-productid]'),
ProductControl = QUI.Controls.getById(ProductElm.get('data-quiid'));
if ("getFieldControls" in ProductControl) {
ProductControl.getFieldControls().each(function (Field) {
fields[Field.getFieldId()] = Field.getValue();
});
}
Article.setFieldValues(fields).then(function () {
return Article.setQuantity(count);
}).then(function () {
return Basket.addArticle(Article);
}).then(function () {
var Span = Loader.getElement('span');
Span.removeClass('fa-spinner');
Span.removeClass('fa-spin');
Span.addClass('success');
Span.addClass('fa-check');
(function () {
Loader.destroy();
self.getElm().removeClass('disabled');
if (self.$Input) {
self.$Input.setStyle('visibility', null);
moofx(self.$Input).animate({
opacity: 1
});
}
self.$Text.setStyle('visibility', null);
moofx(self.$Text).animate({
opacity: 1
});
}).delay(1000);
}.bind(this));
}
});
});
\ No newline at end of file
......@@ -11,6 +11,7 @@
use QUI\ERP\Order\Handler;
use QUI\ERP\Order\Factory;
use QUI\ERP\Order\OrderProcess;
use QUI\ERP\Products\Handler\Products;
/**
* Class Basket
......@@ -59,6 +60,33 @@ public function __construct($orderId = false)
$this->User = $User;
}
/**
* Import a product array
*
* @param array $articles
*/
public function import(array $articles)
{
$this->Order->clearArticles();
foreach ($articles as $article) {
try {
$Product = Products::getProduct($article['id']);
$Unique = $Product->createUniqueProduct();
if (isset($productData['quantity'])) {
$Unique->setQuantity($productData['quantity']);
}
$this->addArticle($Unique->toArticle());
} catch (QUI\Exception $Exception) {
QUI::getMessagesHandler()->addAttention(
$Exception->getMessage()
);
}
}
}
/**
* Create the order
* (Kostenpflichtig bestellen, start the pay process)
......
.quiqqer-order-basket-isEmpty {
padding: 40px 0;
text-align: center;
}
\ No newline at end of file
......@@ -4,8 +4,10 @@
</header>
{if $count}
{$articles}
{$articles}
{else}
<div class="quiqqer-order-basket-isEmpty">
{locale group="quiqqer/order" var="message.basket.is.empty"}
</div>
{/if}
</section>
\ No newline at end of file
......@@ -10,7 +10,7 @@
/**
* Class Basket
* Coordinates the order process, (order -> payment -> invoice)
* Basket display
*
* @package QUI\ERP\Order\Basket
*/
......@@ -37,6 +37,8 @@ public function __construct($attributes = array())
}
parent::__construct($attributes);
$this->addCSSFile(dirname(__FILE__) . '/Basket.css');
}
/**
......
......@@ -48,8 +48,6 @@ public function save($PermissionUser = null)
/**
* @param null $PermissionUser
* @throws QUI\Permissions\Exception
*
* @todo Implement update() method.
*/
public function update($PermissionUser = null)
{
......@@ -68,7 +66,7 @@ public function update($PermissionUser = null)
);
QUI::getDataBase()->update(
Handler::getInstance()->table(),
Handler::getInstance()->tableOrderProcess(),
$data,
array('id' => $this->getId())
);
......
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