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

Merge branch 'dev' of https://dev.quiqqer.com/quiqqer/shipping into dev

Übergeordnete dc2bd2db 322343ec
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -31,7 +31,9 @@ define('package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTi
selectOptions: [
'timeperiod', 'unavailable', 'immediately_available',
'on_request', 'available_soon', 'custom_text'
]
],
show_default_option: true
},
initialize: function (options) {
......@@ -72,6 +74,10 @@ define('package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTi
var options = this.getAttribute('selectOptions'),
lgPrefix = 'controls.products.fields.ShippingTimePeriod.';
if (this.getAttribute('show_default_option')) {
options.unshift('use_default');
}
for (var i = 0, len = options.length; i < len; i++) {
var option = options[i];
......
......@@ -63,6 +63,10 @@
<de><![CDATA[Standard Versand]]></de>
<en><![CDATA[Standard shipping]]></en>
</locale>
<locale name="shipping.DigitalType.title">
<de><![CDATA[Digitaler Versand]]></de>
<en><![CDATA[Digital shipping]]></en>
</locale>
<locale name="shipping.free.workingTitle">
<de><![CDATA[Standard Versand]]></de>
<en><![CDATA[Standard shipping]]></en>
......@@ -763,6 +767,14 @@
<de><![CDATA[Individueller Text]]></de>
<en><![CDATA[Custom text]]></en>
</locale>
<locale name="controls.products.fields.ShippingTimePeriod.option.custom_text">
<de><![CDATA[Individueller Text]]></de>
<en><![CDATA[Custom text]]></en>
</locale>
<locale name="controls.products.fields.ShippingTimePeriod.option.use_default">
<de><![CDATA[Standard-Einstellung benutzen]]></de>
<en><![CDATA[Use default setting]]></en>
</locale>
<locale name="control.search.ShippingWindow.title">
<de><![CDATA[Versandarten durchsuchen]]></de>
......
......@@ -85,6 +85,7 @@
<input type="hidden"
conf="shipping.deliveryTimeDefault"
data-qui="package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTimePeriod"
data-qui-options-show_default_option="0"
>
<text>
<locale group="quiqqer/shipping" var="shipping.settings.deliveryTimeDefault"/>
......
<?php
namespace QUI\ERP\Shipping\Methods\Digital;
use QUI;
use QUI\ERP\Areas\Utils as AreaUtils;
use QUI\ERP\Products\Handler\Products;
use QUI\ERP\Shipping\Debug;
use QUI\ERP\Products\Product\Types\DigitalProduct;
/**
* Class DigitalType
*
* Shipping for digital products that are deliverd via download and/or email.
*/
class ShippingType extends QUI\ERP\Shipping\Api\AbstractShippingType
{
/**
* @param null $Locale
* @return array|string
*/
public function getTitle($Locale = null)
{
if ($Locale === null) {
$Locale = QUI::getLocale();
}
return $Locale->get('quiqqer/shipping', 'shipping.DigitalType.title');
}
/**
* @return string
*/
public function getIcon()
{
return QUI\ERP\Shipping\Shipping::getInstance()->getHost().
URL_OPT_DIR
.'quiqqer/shipping/bin/images/shipping/default.png';
}
/**
* @param QUI\ERP\Order\OrderInterface $Order
* @param QUI\ERP\Shipping\Types\ShippingEntry $ShippingEntry
* @return bool
*/
public function canUsedInOrder(
QUI\ERP\Order\OrderInterface $Order,
QUI\ERP\Shipping\Types\ShippingEntry $ShippingEntry
) {
if ($ShippingEntry->isActive() === false) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: is not active");
return false;
}
if (!$ShippingEntry->isValid()) {
return false;
}
// Check if order contains NON-digital products
/** @var QUI\ERP\Accounting\Article $Article */
foreach ($Order->getArticles() as $Article) {
try {
// Do not parse coupon codes / discounts
if (empty($Article->getId()) || !\is_numeric($Article->getId())) {
continue;
}
$Product = Products::getProduct($Article->getId());
// If a non-digital product is part of the order -> digital shipping is not possible
if (!($Product instanceof DigitalProduct)) {
Debug::addLog(
"{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: contains at least one NON-DIGITAL"
." product that must be shipped physically."
);
return false;
}
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
// Check restriction to certain products / product categories
$articles = $ShippingEntry->getAttribute('articles');
$categories = $ShippingEntry->getAttribute('categories');
$toInt = function ($article) {
return (int)$article;
};
if (!empty($articles)) {
$articles = \array_map($toInt, \explode(',', $articles));
} else {
$articles = [];
}
if (!empty($categories)) {
$categories = \array_map($toInt, \explode(',', $categories));
} else {
$categories = [];
}
// if articles and categories are empty, its allowed
if (empty($articles) && empty($categories)) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: no products or categories [ok]");
return true;
}
$ArticleList = $Order->getArticles();
$orderArticles = $ArticleList->getArticles();
foreach ($orderArticles as $Article) {
try {
$productId = $Article->getId();
if (!empty($articles) && \in_array($productId, $articles)) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: product {$productId} is in allowed list [ok]");
return true;
}
if (\is_array($categories)) {
$Product = QUI\ERP\Products\Handler\Products::getProduct($productId);
$articleCategories = $Product->getCategories();
/* @var $Category QUI\ERP\Products\Category\Category */
foreach ($articleCategories as $Category) {
$categoryId = $Category->getId();
if (\in_array($categoryId, $categories)) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: category {$categoryId} is in allowed list [ok]");
return true;
}
}
}
} catch (QUI\Exception $Exception) {
return false;
}
}
Debug::addLog("{$this->getTitle()} :: no products found in this order which are fit");
return false;
}
/**
* @param QUI\Interfaces\Users\User $User
* @param QUI\ERP\Shipping\Api\ShippingInterface $ShippingEntry
* @param QUI\ERP\Order\AbstractOrder $Order
* @return bool
*/
public function canUsedBy(
QUI\Interfaces\Users\User $User,
QUI\ERP\Shipping\Api\ShippingInterface $ShippingEntry,
QUI\ERP\Order\AbstractOrder $Order
) {
if ($ShippingEntry->isActive() === false) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: is not active");
return false;
}
if ($User instanceof QUI\ERP\User) {
try {
$User = QUI::getUsers()->get($User->getId());
} catch (QUI\Exception $Exception) {
}
}
// assignment
$userGroupValue = $ShippingEntry->getAttribute('user_groups');
$areasValue = $ShippingEntry->getAttribute('areas');
// if groups and areas are empty, everybody is allowed
if (empty($userGroupValue) && empty($areasValue)) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: users + areas are empty [OK]");
return true;
}
$Address = $Order->getDeliveryAddress();
$areasValue = \trim($areasValue);
$areasValue = \trim($areasValue, ',');
$areasValue = \explode(',', $areasValue);
$areasValue = \array_filter($areasValue);
// not in area
if (!empty($areasValue) && !AreaUtils::isAddressInArea($Address, $areasValue)) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: User is not in areas");
return false;
}
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: User is in areas");
$userGroups = QUI\Utils\UserGroups::parseUsersGroupsString(
$ShippingEntry->getAttribute('user_groups')
);
$discountUsers = $userGroups['users'];
$discountGroups = $userGroups['groups'];
if (empty($discountUsers) && empty($discountGroups)) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: no discounts [OK]");
return true;
}
// user checking
foreach ($discountUsers as $uid) {
if ($User->getId() == $uid) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: user found {$uid} [OK]");
return true;
}
}
// group checking
$groupsOfUser = $User->getGroups();
/* @var $Group QUI\Groups\Group */
foreach ($discountGroups as $gid) {
foreach ($groupsOfUser as $Group) {
if ($Group->getId() == $gid) {
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: group found {$gid} [OK]");
return true;
}
}
}
Debug::addLog("{$this->getTitle()} :: {$ShippingEntry->getTitle()} ::User is not in allowed users or groups");
return false;
}
}
......@@ -8,6 +8,8 @@
use QUI;
use QUI\ERP\Areas\Utils as AreaUtils;
use QUI\ERP\Products\Handler\Products;
use QUI\ERP\Products\Product\Types\DigitalProduct;
use QUI\ERP\Shipping\Debug;
/**
......@@ -60,6 +62,37 @@ public function canUsedInOrder(
return false;
}
// Check if order contains only digital products
$digitalProductsOnly = true;
/** @var QUI\ERP\Accounting\Article $Article */
foreach ($Order->getArticles() as $Article) {
try {
// Do not parse coupon codes / discounts
if (empty($Article->getId()) || !\is_numeric($Article->getId())) {
continue;
}
$Product = Products::getProduct($Article->getId());
// If a non-digital product is part of the order -> digital shipping is not possible
if (!($Product instanceof DigitalProduct)) {
$digitalProductsOnly = false;
break;
}
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
if ($digitalProductsOnly) {
Debug::addLog(
"{$this->getTitle()} :: {$ShippingEntry->getTitle()} :: contains only DIGITAL products"
. " that cannot be shipped physically."
);
return false;
}
// assignment
$articles = $ShippingEntry->getAttribute('articles');
......
......@@ -105,4 +105,29 @@ public function create()
return $Engine->fetch(\dirname(__FILE__).'/ShippingTimePeriodFrontendView.html');
}
/**
* Return the current value
*
* @return string|array
*/
public function getValue()
{
if (!empty($this->value['option']) && $this->value['option'] === ShippingTimePeriod::OPTION_USE_DEFAULT) {
try {
$Conf = QUI::getPackage('quiqqer/shipping')->getConfig();
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
return null;
}
$defaultValue = $Conf->get('shipping', 'deliveryTimeDefault');
if (!empty($defaultValue)) {
return \json_decode($defaultValue, true);
}
}
return parent::getValue();
}
}
......@@ -18,6 +18,7 @@ class ShippingTimePeriod extends TimePeriod
const OPTION_ON_REQUEST = 'on_request';
const OPTION_AVAILABLE_SOON = 'available_soon';
const OPTION_CUSTOM_TEXT = 'custom_text';
const OPTION_USE_DEFAULT = 'use_default';
/**
* Check the value
......@@ -92,6 +93,7 @@ public function cleanup($value)
case self::OPTION_IMMEDIATELY_AVAILABLE:
case self::OPTION_ON_REQUEST:
case self::OPTION_AVAILABLE_SOON:
case self::OPTION_USE_DEFAULT:
break;
case self::OPTION_CUSTOM_TEXT:
......
......@@ -22,7 +22,8 @@ class Provider extends AbstractShippingProvider
public function getShippingTypes()
{
return [
Methods\Standard\ShippingType::class
Methods\Standard\ShippingType::class,
Methods\Digital\ShippingType::class
];
}
}
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren