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

refactor: shipping stuff

Übergeordneter 17142ddf
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
werden angezeigt mit 1917 Ergänzungen und 2 Löschungen
<?php
/**
* This file contains package_quiqqer_shipping_ajax_backend_activate
*/
use QUI\ERP\Shipping\Types\Factory;
/**
* Activate a shipping
*
* @param integer $shippingId
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_shipping_ajax_backend_activate',
function ($shippingId) {
$Shipping = new Factory();
$ShippingEntry = $Shipping->getChild($shippingId);
$ShippingEntry->activate();
QUI::getMessagesHandler()->addSuccess(
QUI::getLocale()->get(
'quiqqer/shipping',
'message.shipping.activate.successfully',
['shipping' => $ShippingEntry->getTitle()]
)
);
return $ShippingEntry->toArray();
},
['shippingId'],
'Permission::checkAdminUser'
);
<?php
/**
* This file contains package_quiqqer_shipping_ajax_backend_create
*/
use \QUI\ERP\Shipping\Types\Factory;
use \QUI\ERP\Shipping\Shipping;
/**
* Create a new shipping method
*
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_shipping_ajax_backend_create',
function ($shippingType) {
$Type = Shipping::getInstance()->getShippingType($shippingType);
$Factory = new Factory();
$Shipping = $Factory->createChild([
'shipping_type' => \get_class($Type)
]);
return $Shipping->getId();
},
['shippingType'],
'Permission::checkAdminUser'
);
<?php
/**
* This file contains package_quiqqer_shipping_ajax_backend_deactivate
*/
use \QUI\ERP\Shipping\Types\Factory;
/**
* Deactivate a shipping
*
* @param integer $shippingId
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_shipping_ajax_backend_deactivate',
function ($shippingId) {
$factory = new Factory();
$Shipping = $factory->getChild($shippingId);
$Shipping->deactivate();
QUI::getMessagesHandler()->addSuccess(
QUI::getLocale()->get(
'quiqqer/shipping',
'message.shipping.deactivate.successfully',
['shipping' => $Shipping->getTitle()]
)
);
return $Shipping->toArray();
},
['shippingId'],
'Permission::checkAdminUser'
);
<?php
/**
* This file contains package_quiqqer_shipping_ajax_backend_delete
*/
use QUI\ERP\Shipping\Types\Factory;
/**
* Delete the shipping entry
*
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_shipping_ajax_backend_delete',
function ($shippingId) {
$Factory = new Factory();
$Factory->getChild($shippingId)->delete();
},
['shippingId'],
'Permission::checkAdminUser'
);
<?php
/**
* This file contains package_quiqqer_shipping_ajax_backend_getShippingEntries
*/
use QUI\ERP\Shipping\Shipping;
use QUI\ERP\Shipping\Types\ShippingEntry;
/**
* Return all active shipping entries
*
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_shipping_ajax_backend_getShippingEntries',
function () {
$shippingEntries = Shipping::getInstance()->getShippingList();
$result = [];
foreach ($shippingEntries as $ShippingEntry) {
/* @var $ShippingEntry ShippingEntry */
$result[] = $ShippingEntry->toArray();
}
$current = QUI::getLocale()->getCurrent();
\usort($result, function ($a, $b) use ($current) {
$aTitle = $a['title'][$current];
$bTitle = $b['title'][$current];
if (!empty($a['workingTitle'][$current])) {
$aTitle = $a['workingTitle'][$current];
}
if (!empty($b['workingTitle'][$current])) {
$bTitle = $b['workingTitle'][$current];
}
return \strcmp($aTitle, $bTitle);
});
return $result;
},
false,
'Permission::checkAdminUser'
);
<?php
/**
* This file contains package_quiqqer_shipping_ajax_backend_getShippingEntry
*/
use QUI\ERP\Shipping\Shipping;
/**
* Return all active shipping
*
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_shipping_ajax_backend_getShippingEntry',
function ($shippingId) {
return Shipping::getInstance()->getShippingEntry($shippingId)->toArray();
},
['shippingId'],
'Permission::checkAdminUser'
);
<?php
/**
* This file contains package_quiqqer_shipping_ajax_backend_getShippingTypes
*/
use QUI\ERP\Shipping\Shipping;
/**
* Return all active shipping
*
* @return array
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_shipping_ajax_backend_getShippingTypes',
function () {
return \array_map(function ($Shipping) {
/* @var $Shipping \QUI\ERP\Shipping\Methods\Free\ShippingType */
return $Shipping->toArray(QUI::getLocale());
}, Shipping::getInstance()->getShippingTypes());
},
false,
'Permission::checkAdminUser'
);
<?php
/**
* This file contains package_quiqqer_shipping_ajax_backend_update
*/
use QUI\ERP\Shipping\Types\Factory;
/**
* Update a shipping entry
*
* @param integer $shippingId - Shipping ID
* @param array $data - Shipping Data
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_shipping_ajax_backend_update',
function ($shippingId, $data) {
$Factory = new Factory();
$ShippingEntry = $Factory->getChild($shippingId);
$data = \json_decode($data, true);
/* @var $ShippingEntry \QUI\ERP\Shipping\Types\ShippingEntry */
if (isset($data['title'])) {
$ShippingEntry->setTitle($data['title']);
}
if (isset($data['workingTitle'])) {
$ShippingEntry->setWorkingTitle($data['workingTitle']);
}
if (isset($data['description'])) {
$ShippingEntry->setDescription($data['description']);
}
if (isset($data['icon'])) {
$ShippingEntry->setIcon($data['icon']);
}
$ShippingEntry->setAttributes($data);
$ShippingEntry->update();
QUI::getMessagesHandler()->addSuccess(
QUI::getLocale()->get(
'quiqqer/shipping',
'message.shipping.saved.successfully',
[
'shipping' => $ShippingEntry->getTitle()
]
)
);
return $ShippingEntry->toArray();
},
['shippingId', 'data'],
'Permission::checkAdminUser'
);
/**
* Global Shipping Handler
*/
define('package/quiqqer/shipping/bin/backend/Shipping', [
'package/quiqqer/shipping/bin/backend/classes/Handler'
], function (Shipping) {
"use strict";
return new Shipping();
});
\ No newline at end of file
/**
* @module package/quiqqer/shipping/bin/backend/classes/Handler
* @author www.pcsg.de (Henning Leutz)
*
* @event onShippingDeactivate [self, shippingId, data]
* @event onShippingActivate [self, shippingId, data]
* @event onShippingDelete [self, shippingId]
* @event onShippingCreate [self, shippingId]
* @event onShippingUpdate [self, shippingId, data]
*/
define('package/quiqqer/shipping/bin/backend/classes/Handler', [
'qui/QUI',
'qui/classes/DOM',
'Ajax'
], function (QUI, QUIDOM, QUIAjax) {
"use strict";
return new Class({
Extends: QUIDOM,
Type : 'package/quiqqer/shipping/bin/Manager',
initialize: function (options) {
this.parent(options);
this.$shippings = null;
},
/**
* Return active shipping
*
* @return {Promise}
*/
getShippings: function () {
if (this.$shippings) {
return window.Promise.resolve(this.$shippings);
}
var self = this;
return new Promise(function (resolve, reject) {
QUIAjax.get('package_quiqqer_shipping_ajax_backend_getShippings', function (result) {
self.$shippings = result;
resolve(self.$shippings);
}, {
'package': 'quiqqer/shipping',
onError : reject
});
});
},
/**
* Return the shipping data
*
* @param {String|Number} shippingId
* @return {Promise}
*/
getShipping: function (shippingId) {
return new Promise(function (resolve, reject) {
QUIAjax.get('package_quiqqer_shipping_ajax_backend_getShipping', resolve, {
'package' : 'quiqqer/shipping',
onError : reject,
shippingId: shippingId
});
});
},
/**
* Return all available shipping methods
*
* @return {Promise}
*/
getShippingTypes: function () {
return new Promise(function (resolve, reject) {
QUIAjax.get('package_quiqqer_shipping_ajax_backend_getShippingTypes', resolve, {
'package': 'quiqqer/shipping',
onError : reject
});
});
},
/**
* Create a new inactive shipping type
*
* @param {String} shippingType - Hash of the shipping type
* @return {Promise}
*/
createShipping: function (shippingType) {
var self = this;
return new Promise(function (resolve, reject) {
QUIAjax.get('package_quiqqer_shipping_ajax_backend_create', function (shippingId) {
self.$shippings = null;
require([
'package/quiqqer/translator/bin/Translator'
], function (Translator) {
Translator.refreshLocale().then(function () {
self.fireEvent('shippingCreate', [self, shippingId]);
resolve(shippingId);
});
});
}, {
'package' : 'quiqqer/shipping',
onError : reject,
shippingType: shippingType
});
});
},
/**
* Update a shipping
*
* @param {Number|String} shippingId - Shipping ID
* @param {Object} data - Data of the shipping
* @return {Promise}
*/
updateShipping: function (shippingId, data) {
var self = this;
return new Promise(function (resolve, reject) {
QUIAjax.get('package_quiqqer_shipping_ajax_backend_update', function (result) {
self.$shippings = null;
require([
'package/quiqqer/translator/bin/Translator'
], function (Translator) {
Translator.refreshLocale().then(function () {
self.fireEvent('shippingUpdate', [self, shippingId, result]);
resolve(result);
});
});
}, {
'package' : 'quiqqer/shipping',
onError : reject,
shippingId: shippingId,
data : window.JSON.encode(data)
});
});
},
/**
*
* @param {String|Number} shippingId
* @return {Promise}
*/
deleteShipping: function (shippingId) {
var self = this;
return new Promise(function (resolve, reject) {
self.$shippings = null;
QUIAjax.get('package_quiqqer_shipping_ajax_backend_delete', function () {
self.fireEvent('shippingDelete', [self, shippingId]);
resolve();
}, {
'package' : 'quiqqer/shipping',
onError : reject,
shippingId: shippingId
});
});
},
/**
* Activate a shipping
*
* @param {String|Number} shippingId
* @return {Promise}
*/
activateShipping: function (shippingId) {
var self = this;
return new Promise(function (resolve, reject) {
self.$shippings = null;
QUIAjax.get('package_quiqqer_shipping_ajax_backend_activate', function (result) {
self.fireEvent('shippingActivate', [self, shippingId, result]);
resolve(result);
}, {
'package' : 'quiqqer/shipping',
onError : reject,
shippingId: shippingId
});
});
},
/**
* Deactivate a shipping
*
* @param {String|Number} shippingId
* @return {Promise}
*/
deactivateShipping: function (shippingId) {
var self = this;
return new Promise(function (resolve, reject) {
self.$shippings = null;
QUIAjax.get('package_quiqqer_shipping_ajax_backend_deactivate', function (result) {
self.fireEvent('shippingDeactivate', [self, shippingId, result]);
resolve(result);
}, {
'package' : 'quiqqer/shipping',
onError : reject,
shippingId: shippingId
});
});
}
});
});
\ No newline at end of file
/**
* @module package/quiqqer/shipping/bin/backend/controls/Shipping
* @author www.pcsg.de (Henning Leutz)
*
* Shipping Panel
*/
define('package/quiqqer/shipping/bin/backend/controls/Shipping', [
'qui/QUI',
'qui/controls/desktop/Panel',
'qui/controls/windows/Confirm',
'qui/controls/buttons/Button',
'package/quiqqer/shipping/bin/backend/Shipping',
'controls/grid/Grid',
'Mustache',
'Locale'
], function (QUI, QUIPanel, QUIConfirm, QUIButton, Shipping, Grid, Mustache, QUILocale) {
"use strict";
var lg = 'quiqqer/shipping';
var current = QUILocale.getCurrent();
return new Class({
Extends: QUIPanel,
Type : 'package/quiqqer/shipping/bin/backend/controls/Shipping',
Binds: [
'refresh',
'$onCreate',
'$onInject',
'$onResize',
'$onDestroy',
'$onEditClick',
'$onShippingChange',
'$openCreateDialog',
'$openDeleteDialog',
'$refreshButtonStatus'
],
initialize: function (options) {
this.parent(options);
this.$Grid = null;
this.setAttributes({
icon : 'fa fa-credit-card-alt',
title: QUILocale.get(lg, 'menu.erp.shipping.title')
});
this.addEvents({
onCreate : this.$onCreate,
onInject : this.$onInject,
onResize : this.$onResize,
onDestroy: this.$onDestroy
});
Shipping.addEvents({
onShippingDeactivate: this.$onShippingChange,
onShippingActivate : this.$onShippingChange,
onShippingDelete : this.$onShippingChange,
onShippingCreate : this.$onShippingChange,
onShippingUpdate : this.$onShippingChange
});
},
/**
* Refresh the value and the display
*/
refresh: function () {
if (!this.$Elm) {
return;
}
this.Loader.show();
var self = this;
this.$Grid.getButtons().filter(function (Btn) {
return Btn.getAttribute('name') === 'edit';
})[0].disable();
this.$Grid.getButtons().filter(function (Btn) {
return Btn.getAttribute('name') === 'delete';
})[0].disable();
Shipping.getShippings().then(function (result) {
var toggle = function (Btn) {
var data = Btn.getAttribute('data'),
shippingId = data.id,
status = parseInt(data.active);
Btn.setAttribute('icon', 'fa fa-spinner fa-spin');
if (status) {
Shipping.deactivateShipping(shippingId);
return;
}
Shipping.activateShipping(shippingId);
};
for (var i = 0, len = result.length; i < len; i++) {
if (parseInt(result[i].active)) {
result[i].status = {
icon : 'fa fa-check',
styles: {
lineHeight: 20,
padding : 0,
width : 20
},
events: {
onClick: toggle
}
};
} else {
result[i].status = {
icon : 'fa fa-remove',
styles: {
lineHeight: 20,
padding : 0,
width : 20
},
events: {
onClick: toggle
}
};
}
result[i].shippingType_display = '';
result[i].title = result[i].title[current];
result[i].workingTitle = result[i].workingTitle[current];
if ("shippingType" in result[i] && result[i].shippingType) {
result[i].shippingType_display = result[i].shippingType.title;
}
}
self.$Grid.setData({
data: result
});
self.Loader.hide();
});
},
/**
* event: on create
*/
$onCreate: function () {
var Container = new Element('div', {
styles: {
minHeight: 300,
width : '100%'
}
}).inject(this.getContent());
this.$Grid = new Grid(Container, {
buttons : [{
name : 'add',
text : QUILocale.get('quiqqer/quiqqer', 'add'),
textimage: 'fa fa-plus',
events : {
onClick: this.$openCreateDialog
}
}, {
type: 'separator'
}, {
name : 'edit',
text : QUILocale.get('quiqqer/quiqqer', 'edit'),
textimage: 'fa fa-edit',
disabled : true,
events : {
onClick: this.$onEditClick
}
}, {
name : 'delete',
text : QUILocale.get('quiqqer/system', 'delete'),
textimage: 'fa fa-trash',
disabled : true,
events : {
onClick: this.$openDeleteDialog
}
}],
columnModel: [{
header : QUILocale.get('quiqqer/system', 'priority'),
dataIndex: 'priority',
dataType : 'number',
width : 50
}, {
header : QUILocale.get('quiqqer/system', 'status'),
dataIndex: 'status',
dataType : 'button',
width : 60
}, {
header : QUILocale.get('quiqqer/system', 'title'),
dataIndex: 'title',
dataType : 'string',
width : 200
}, {
header : QUILocale.get('quiqqer/system', 'workingtitle'),
dataIndex: 'workingTitle',
dataType : 'string',
width : 200
}, {
header : QUILocale.get('quiqqer/system', 'id'),
dataIndex: 'id',
dataType : 'number',
width : 30
}, {
header : QUILocale.get(lg, 'shipping.type'),
dataIndex: 'shippingType_display',
dataType : 'string',
width : 200
}]
});
this.$Grid.addEvents({
onRefresh : this.refresh,
onClick : this.$refreshButtonStatus,
onDblClick: this.$onEditClick
});
},
/**
* event : on inject
*/
$onInject: function () {
this.refresh();
},
/**
* event: on destroy
*/
$onDestroy: function () {
Shipping.removeEvents({
onShippingDeactivate: this.$onShippingChange,
onShippingActivate : this.$onShippingChange,
onShippingDelete : this.$onShippingChange,
onShippingCreate : this.$onShippingChange,
onShippingUpdate : this.$onShippingChange
});
},
/**
* event : on resize
*/
$onResize: function () {
if (!this.$Grid) {
return;
}
var Body = this.getContent();
if (!Body) {
return;
}
var size = Body.getSize();
this.$Grid.setHeight(size.y - 40);
this.$Grid.setWidth(size.x - 40);
},
/**
* event : on shipping change
* if a shipping changed
*/
$onShippingChange: function () {
this.refresh();
},
/**
* open the edit dialog
*/
openShipping: function (shippingId) {
require([
'package/quiqqer/shipping/bin/backend/controls/ShippingEntry',
'utils/Panels'
], function (ShippingEntry, Utils) {
Utils.openPanelInTasks(
new ShippingEntry({
shippingId: shippingId
})
);
});
},
/**
* event: on edit
*/
$onEditClick: function () {
var data = this.$Grid.getSelectedData();
if (data.length) {
this.openShipping(data[0].id);
}
},
/**
* open the add dialog
*/
$openCreateDialog: function () {
var self = this;
new QUIConfirm({
icon : 'fa fa-plus',
texticon : 'fa fa-plus',
title : QUILocale.get(lg, 'window.create.title'),
text : QUILocale.get(lg, 'window.create.title'),
information: QUILocale.get(lg, 'window.create.information'),
autoclose : false,
maxHeight : 400,
maxWidth : 600,
events : {
onOpen : function (Win) {
var Content = Win.getContent(),
Body = Content.getElement('.textbody');
Win.Loader.show();
var Container = new Element('div', {
html : QUILocale.get(lg, 'window.create.shippingType'),
styles: {
clear : 'both',
'float' : 'left',
marginTop : 20,
paddingLeft: 80,
width : '100%'
}
}).inject(Body, 'after');
var Select = new Element('select', {
styles: {
marginTop: 10,
maxWidth : '100%',
width : 300
}
}).inject(Container);
Shipping.getShippingTypes().then(function (result) {
for (var i in result) {
if (!result.hasOwnProperty(i)) {
continue;
}
new Element('option', {
value: result[i].name,
html : result[i].title
}).inject(Select);
}
Win.Loader.hide();
}).catch(function () {
Win.Loader.hide();
});
},
onSubmit: function (Win) {
Win.Loader.show();
var Select = Win.getContent().getElement('select');
Shipping.createShipping(Select.value).then(function (newId) {
Win.close();
self.refresh();
self.openShipping(newId);
}).catch(function () {
Win.Loader.hide();
});
}
}
}).open();
},
/**
* open the add dialog
*/
$openDeleteDialog: function () {
var selected = this.$Grid.getSelectedData();
if (!selected.length) {
return;
}
var self = this,
shipping = selected[0].title,
shippingId = selected[0].id;
if (shipping === '') {
shipping = shippingId;
}
new QUIConfirm({
texticon : 'fa fa-trash',
icon : 'fa fa-trash',
title : QUILocale.get(lg, 'window.delete.title'),
information: QUILocale.get(lg, 'window.delete.information', {
shipping: shipping
}),
text : QUILocale.get(lg, 'window.delete.text', {
shipping: shipping
}),
autoclose : false,
maxHeight : 400,
maxWidth : 600,
ok_button : {
text : QUILocale.get('quiqqer/system', 'delete'),
textimage: 'fa fa-trash'
},
events : {
onSubmit: function (Win) {
Win.Loader.show();
Shipping.deleteShipping(shippingId).then(function () {
Win.close();
self.refresh();
});
}
}
}).open();
},
/**
* refresh the button disable enable status
* looks at the grid
*/
$refreshButtonStatus: function () {
var selected = this.$Grid.getSelectedIndices(),
buttons = this.$Grid.getButtons();
var Edit = buttons.filter(function (Btn) {
return Btn.getAttribute('name') === 'edit';
})[0];
var Delete = buttons.filter(function (Btn) {
return Btn.getAttribute('name') === 'delete';
})[0];
if (!selected.length) {
Edit.disable();
Delete.disable();
return;
}
Edit.enable();
Delete.enable();
}
});
});
\ No newline at end of file
<?php
/**
* This file contains \QUI\ERP\Shipping\Api\AbstractShippingEntry
*/
namespace QUI\ERP\Shipping\Api;
use QUI;
use QUI\ERP\Order\AbstractOrder;
/**
* Shipping abstract class
* This is the parent shipping class for all shipping methods
*
* @author www.pcsg.de (Henning Leutz)
*/
abstract class AbstractShippingEntry implements ShippingInterface
{
/**
* @var int
*/
const SUCCESS_TYPE_PAY = 1;
/**
* @var int
*/
const SUCCESS_TYPE_BILL = 2;
/**
* shipping fields - extra fields for the shipping / accounting
*
* @var array
*/
protected $shippingFields = [];
/**
* default settings
*
* @var array
*/
protected $defaults = [];
/**
* Locale object for the shipping
*
* @var QUI\Locale
*/
protected $Locale = null;
/**
* Set the locale object to the shipping
*
* @param QUI\Locale $Locale
*/
public function setLocale(QUI\Locale $Locale)
{
$this->Locale = $Locale;
}
/**
* Return the Locale of the shipping
*
* @return QUI\Locale
*/
public function getLocale()
{
if ($this->Locale === null) {
$this->Locale = QUI::getLocale();
}
return $this->Locale;
}
/**
* @return string
*/
public function getName()
{
return md5(get_class($this));
}
/**
* Return the class of the instance
*
* @return string
*/
public function getClass()
{
return \get_class($this);
}
/**
* @return string
*/
abstract public function getTitle();
/**
* @return string
*/
abstract public function getDescription();
/**
* Is the shipping successful?
* This method returns the shipping success type
*
* @param string $hash - Vorgangsnummer - hash number - procedure number
* @return bool
*/
abstract public function isSuccessful($hash);
/**
* Return the shipping icon (the URL path)
* Can be overwritten
*
* @return string
*/
public function getIcon()
{
return URL_OPT_DIR.'quiqqer/shipping/bin/shipping/default.png';
}
/**
* Return the shipping as an array
*
* @return array
*/
public function toArray()
{
return [
'name' => $this->getName(),
'title' => $this->getTitle(),
'description' => $this->getDescription()
];
}
/**
* Is the shipping a gateway shipping?
*
* @return bool
*/
public function isGateway()
{
return false;
}
/**
* Is the shipping be visible in the frontend?
* Every shipping method can determine this by itself (API for developers)
*
* @return bool
*/
public function isVisible()
{
return true;
}
/**
* This flag indicates whether the shipping module can be created more than once
*
* @return bool
*/
public function isUnique()
{
return false;
}
// /**
// * @return bool
// */
// public function refundSupport()
// {
// return false;
// }
// /**
// * If the Shipping method is a shipping gateway, it can return a gateway display
// *
// * @param AbstractOrder $Order
// * @param QUI\ERP\Order\Controls\AbstractOrderingStep|null $Step
// * @return string
// *
// * @throws QUI\ERP\Order\ProcessingException
// */
// public function getGatewayDisplay(AbstractOrder $Order, $Step = null)
// {
// return '';
// }
//
// /**
// * Execute the request from the shipping provider
// *
// * @param QUI\ERP\Shipping\Gateway\Gateway $Gateway
// *
// * @throws QUI\ERP\Accounting\Payments\Exception
// */
// public function executeGatewayPayment(QUI\ERP\Accounting\Payments\Gateway\Gateway $Gateway)
// {
// }
//region text messages
/**
* Return the extra text for the invoice
*
* @param QUI\ERP\Accounting\Invoice\Invoice|QUI\ERP\Accounting\Invoice\InvoiceTemporary|QUI\ERP\Accounting\Invoice\InvoiceView $Invoice
* @return mixed
*/
public function getInvoiceInformationText($Invoice)
{
return '';
}
//endregion
}
<?php
/**
* This file contains QUI\ERP\Shipping\Api\ShippingInterface
*/
namespace QUI\ERP\Shipping\Api;
/**
* Interface for a Shipping Entry
* All Shipping modules must implement this interface
*/
interface ShippingInterface
{
/**
* @return string
*/
public function getTitle();
/**
* @return string
*/
public function getDescription();
}
<?php
/**
* This File contains \QUI\ERP\Shipping\Exceptions\ShippingCanNotBeUsed
*/
namespace QUI\ERP\Shipping\Exceptions;
use QUI;
/**
* ShippingCanNotBeUsed
* Exception: shipping can't be used
*
* @author www.pcsg.de (Henning Leutz)
*/
class ShippingCanNotBeUsed extends QUI\Exception
{
}
<?php
/**
* This file contains QUI\ERP\Shipping\Methods\Free\Shipping
*/
namespace QUI\ERP\Shipping\Methods\Free;
use QUI;
use QUI\ERP\Shipping\Shipping as ShippingHandler;
/**
* Class Shipping
*
* @package QUI\ERP\Shipping\Methods\Free\Shipping
*/
class Shipping extends QUI\ERP\Shipping\Api\AbstractShippingEntry
{
/**
* free shipping id
*/
const ID = -1;
/**
* @return array|string
*/
public function getTitle()
{
return $this->getLocale()->get(
'quiqqer/shipping',
'shipping.free.title'
);
}
/**
* @return array|string
*/
public function getWorkingTitle()
{
return $this->getLocale()->get(
'quiqqer/shipping',
'shipping.free.workingTitle'
);
}
/**
* @return array|string
*/
public function getDescription()
{
return $this->getLocale()->get(
'quiqqer/shipping',
'shipping.free.description'
);
}
/**
* @return bool
*/
public function isGateway()
{
return false;
}
/**
* @param string $hash
* @return bool
*/
public function isSuccessful($hash)
{
try {
$Order = QUI\ERP\Order\Handler::getInstance()->getOrderByHash($hash);
$Calculation = $Order->getPriceCalculation();
if ($Calculation->getSum() === 0) {
return true;
}
} catch (\Exception $Exception) {
}
return false;
}
/**
* @return bool
*/
public function refundSupport()
{
return false;
}
/**
* Return the shipping icon (the URL path)
* Can be overwritten
*
* @return string
*/
public function getIcon()
{
return ShippingHandler::getInstance()->getHost().
URL_OPT_DIR.
'quiqqer/shipping/bin/shipping/Free.png';
}
}
<?php
/**
* This file contains QUI\ERP\Shipping\Methods\Free\ShippingType
*/
namespace QUI\ERP\Shipping\Methods\Free;
use QUI;
/**
* Class ShippingType
* - This class is a placeholder / helper class for the free shipping
* - if an order has no value of goods, this shipping will be used
*
* @package QUI\ERP\Shipping\Methods\Free\ShippingType
*/
class ShippingType extends QUI\QDOM implements QUI\ERP\Shipping\Api\ShippingInterface
{
/**
* @return array
*/
public function toArray()
{
$lg = 'quiqqer/shipping';
$Locale = QUI::getLocale();
return [
'title' => $Locale->get($lg, 'shipping.free.title'),
'description' => $Locale->get($lg, 'shipping.free.description'),
'workingTitle' => $Locale->get($lg, 'shipping.free.workingTitle'),
'shippingType' => false,
'icon' => ''
];
}
/**
* @param string $hash
* @return bool
*/
public function isSuccessful($hash)
{
return true;
}
/**
* @return int
*/
public function getId()
{
return -1;
}
/**
* @param $Locale
* @return array|string
*/
public function getTitle($Locale = null)
{
$ShippingType = $this->getShippingType();
if ($Locale !== null) {
$ShippingType->setLocale($Locale);
}
return $ShippingType->getTitle();
}
/**
* @param $Locale
* @return array|string
*/
public function getWorkingTitle($Locale = null)
{
$ShippingType = $this->getShippingType();
if ($Locale !== null) {
$ShippingType->setLocale($Locale);
}
return $ShippingType->getWorkingTitle();
}
/**
* @param $Locale
* @return array|string
*/
public function getDescription($Locale = null)
{
$ShippingType = $this->getShippingType();
if ($Locale !== null) {
$ShippingType->setLocale($Locale);
}
return $ShippingType->getDescription();
}
/**
* @return string
*/
public function getIcon()
{
return $this->getShippingType()->getIcon();
}
/**
* @return Shipping
*/
public function getShippingType()
{
return new Shipping();
}
/**
* @param QUI\Interfaces\Users\User $User
* @return bool
*/
public function canUsedBy(QUI\Interfaces\Users\User $User)
{
return true;
}
}
<?php
/**
* This file contains QUI\ERP\Accounting\Payments\Provider
* This file contains QUI\ERP\Shipping\Provider
*/
namespace QUI\ERP\Shipping;
......@@ -22,7 +22,7 @@ class Provider extends AbstractShippingProvider
public function getShippingTypes()
{
return [
Methods\Free\ShippingType::class
];
}
}
<?php
/**
* This class contains \QUI\ERP\Shipping\Shipping
*/
namespace QUI\ERP\Shipping;
use QUI;
use QUI\ERP\Shipping\Api\ShippingInterface;
use QUI\ERP\Shipping\Types\Factory;
use QUI\ERP\Shipping\Types\ShippingEntry;
use QUI\ERP\Shipping\Api\AbstractShippingProvider;
use QUI\ERP\Shipping\Api\AbstractShippingEntry;
/**
* Shipping
*
* @author www.pcsg.de (Henning Leutz)
*/
class Shipping extends QUI\Utils\Singleton
{
/**
* @var array
*/
protected $shipping = [];
/**
* Return all available shipping provider
*
* @return array
*/
public function getShippingProviders()
{
$cacheProvider = 'package/quiqqer/shipping/provider';
try {
$providers = QUI\Cache\Manager::get($cacheProvider);
} catch (QUI\Cache\Exception $Exception) {
$packages = \array_map(function ($package) {
return $package['name'];
}, QUI::getPackageManager()->getInstalled());
$providers = [];
foreach ($packages as $package) {
try {
$Package = QUI::getPackage($package);
if ($Package->isQuiqqerPackage()) {
$providers = array_merge($providers, $Package->getProvider('shipping'));
}
} catch (QUI\Exception $Exception) {
}
}
try {
QUI\Cache\Manager::set($cacheProvider, $providers);
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
// filter provider
$result = [];
foreach ($providers as $provider) {
if (!class_exists($provider)) {
continue;
}
$Provider = new $provider();
if (!($Provider instanceof AbstractShippingProvider)) {
continue;
}
$result[] = $Provider;
}
return $result;
}
/**
* Return all available Shipping methods
*
* @return array
*/
public function getShippingTypes()
{
$shipping = [];
$providers = $this->getShippingProviders();
foreach ($providers as $Provider) {
$providerShipping = $Provider->getShippingTypes();
foreach ($providerShipping as $providerShippingEntry) {
if (!\class_exists($providerShippingEntry)) {
continue;
}
$ShippingEntry = new $providerShippingEntry();
if ($ShippingEntry instanceof AbstractShippingEntry) {
$shipping[$ShippingEntry->getName()] = $ShippingEntry;
}
}
}
return $shipping;
}
/**
* @param $shippingHash
* @return AbstractShippingEntry
* @throws Exception
*/
public function getShippingType($shippingHash)
{
$types = $this->getShippingTypes();
/* @var $Shipping AbstractShippingEntry */
foreach ($types as $Shipping) {
if ($Shipping->getName() === $shippingHash) {
return $Shipping;
}
}
throw new Exception([
'quiqqer/shipping',
'exception.shipping.type.not.found',
['shippingType' => $shippingHash]
]);
}
/**
* Return a shipping
*
* @param int|string $shippingId - ID of the shipping type
* @return QUI\ERP\Shipping\Api\AbstractShippingEntry
*
* @throws Exception
*/
public function getShippingEntry($shippingId)
{
if ((int)$shippingId == Methods\Free\Shipping::ID) {
return new Methods\Free\Shipping();
}
try {
return Factory::getInstance()->getChild($shippingId);
} catch (QUI\Exception $Exception) {
throw new Exception([
'quiqqer/shipping',
'exception.shipping.not.found'
]);
}
}
/**
* Return all active shipping
*
* @param array $queryParams
* @return QUI\ERP\Shipping\Types\ShippingEntry[]
*/
public function getShippingList($queryParams = [])
{
if (!isset($queryParams['order'])) {
$queryParams['order'] = 'priority ASC';
}
try {
return Factory::getInstance()->getChildren($queryParams);
} catch (QUi\Exception $Exception) {
return [];
}
}
/**
* Return all shipping entries for the user
*
* @param \QUI\Interfaces\Users\User|null $User - optional
* @return array
*/
public function getUserShipping($User = null)
{
if ($User === null) {
$User = QUI::getUserBySession();
}
$shipping = \array_filter($this->getShippingList(), function ($Shipping) use ($User) {
/* @var $Shipping QUI\ERP\Shipping\Types\ShippingEntry */
return $Shipping->canUsedBy($User);
});
return $shipping;
}
/**
* @return bool|string
*/
public function getHost()
{
try {
$Project = QUI::getRewrite()->getProject();
} catch (QUI\Exception $Exception) {
try {
$Project = QUI::getProjectManager()->getStandard();
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeException($Exception);
return '';
}
}
$host = $Project->getVHost(true, true);
$host = trim($host, '/');
return $host;
}
}
<?php
/**
* This file contains QUI\ERP\Shipping\Types\Factory
*/
namespace QUI\ERP\Shipping\Types;
use QUI;
use QUI\Permissions\Permission;
/**
* Class Factory
*
* @package QUI\ERP\Shipping\Types
*/
class Factory extends QUI\CRUD\Factory
{
/**
* Handler constructor.
*/
public function __construct()
{
parent::__construct();
$self = $this;
$this->Events->addEvent('onCreateBegin', function () {
Permission::checkPermission('quiqqer.shipping.create');
});
// create new translation var for the area
$this->Events->addEvent('onCreateEnd', function () use ($self) {
QUI\Translator::publish('quiqqer/shipping');
});
}
/**
* @param array $data
*
* @return ShippingEntry
*
* @throws QUI\ERP\Shipping\Exception
* @throws QUI\Exception
*/
public function createChild($data = [])
{
if (!isset($data['active']) || !is_integer($data['active'])) {
$data['active'] = 0;
}
if (!isset($data['purchase_quantity_from']) || !is_integer($data['purchase_quantity_from'])) {
$data['purchase_quantity_from'] = 0;
}
if (!isset($data['purchase_quantity_until']) || !is_integer($data['purchase_quantity_until'])) {
$data['purchase_quantity_until'] = 0;
}
if (!isset($data['priority']) || !is_integer($data['priority'])) {
$data['priority'] = 0;
}
if (!isset($data['shipping_type']) || !class_exists($data['shipping_type'])) {
throw new QUI\ERP\Shipping\Exception([
'quiqqer/shipping',
'exception.create.shipping.class.not.found'
]);
}
QUI::getEvents()->fireEvent('shippingCreateBegin', [$data['shipping_type']]);
$shipping = $data['shipping_type'];
$ShippingMethod = new $shipping();
/* @var $ShippingMethod QUI\ERP\Shipping\Api\AbstractShippingEntry */
if ($ShippingMethod->isUnique()) {
// if the shipping is unique, we must check, if a shipping method already exists
$Shipping = QUI\ERP\Shipping\Shipping::getInstance();
$children = $Shipping->getShippingList([
'where' => [
'shipping_type' => $shipping
]
]);
if (count($children)) {
throw new QUI\ERP\Shipping\Exception([
'quiqqer/shipping',
'exception.create.unique.shipping.already.exists'
]);
}
}
/* @var $NewChild ShippingEntry */
$NewChild = parent::createChild($data);
$this->createShippingLocale(
'shipping.'.$NewChild->getId().'.title',
'[quiqqer/shipping] new.shipping.placeholder'
);
$this->createShippingLocale(
'shipping.'.$NewChild->getId().'.workingTitle',
'[quiqqer/shipping] new.shipping.placeholder'
);
$this->createShippingLocale(
'shipping.'.$NewChild->getId().'.description',
'&nbsp;'
);
try {
QUI\Translator::publish('quiqqer/shipping');
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
QUI::getEvents()->fireEvent('shippingCreateEnd', [$NewChild]);
return $NewChild;
}
/**
* @return string
*/
public function getDataBaseTableName()
{
return 'shipping';
}
/**
* @return string
*/
public function getChildClass()
{
return ShippingEntry::class;
}
/**
* @return array
*/
public function getChildAttributes()
{
return [
'id',
'shipping_type',
'active',
'icon',
'date_from',
'date_until',
'purchase_quantity_from',
'purchase_quantity_until',
'purchase_value_from',
'purchase_value_until',
'priority',
'areas',
'articles',
'categories',
'user_groups'
];
}
/**
* @param int $id
*
* @return QUI\ERP\Shipping\Api\AbstractShippingEntry
*
* @throws QUI\Exception
*/
public function getChild($id)
{
/* @var QUI\ERP\Shipping\Api\AbstractShippingEntry $Shipping */
$Shipping = parent::getChild($id);
return $Shipping;
}
/**
* Creates a locale
*
* @param $var
* @param $title
*/
protected function createShippingLocale($var, $title)
{
$current = QUI::getLocale()->getCurrent();
if (QUI::getLocale()->isLocaleString($title)) {
$parts = QUI::getLocale()->getPartsOfLocaleString($title);
$title = QUI::getLocale()->get($parts[0], $parts[1]);
}
try {
QUI\Translator::addUserVar('quiqqer/shipping', $var, [
$current => $title,
'datatype' => 'php,js',
'package' => 'quiqqer/shipping'
]);
} catch (QUI\Exception $Exception) {
QUI\System\Log::addNotice($Exception->getMessage());
}
}
}
<?php
namespace QUI\ERP\Shipping\Types;
use QUI;
/**
* Interface ShippingInterface
*
* @package QUI\ERP\Accounting\Shipping\Types
*/
interface ShippingInterface
{
//region general
/**
* @return integer
*/
public function getId();
/**
* @param null|QUI\Locale $Locale
* @return string
*/
public function getTitle($Locale = null);
/**
* @param null|QUI\Locale $Locale
* @return string
*/
public function getDescription($Locale = null);
/**
* @param null|QUI\Locale $Locale
* @return string
*/
public function getWorkingTitle($Locale = null);
//endregion
/**
* @return array
*/
public function toArray();
/**
* @param string $hash - order hash
* @return bool
*/
public function isSuccessful($hash);
/**
* @return \QUI\ERP\Shipping\Api\AbstractShippingEntry
*/
public function getShippingType();
/**
* @param QUI\Interfaces\Users\User $User
* @return bool
*/
public function canUsedBy(QUI\Interfaces\Users\User $User);
}
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