Skip to content
Code-Schnipsel Gruppen Projekte
Commit ff25e3da erstellt von Patrick Müller's avatar Patrick Müller
Dateien durchsuchen

feat: ShippingTime field and frontend view

Übergeordneter 95f88e0a
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -175,6 +175,10 @@
<de><![CDATA[ca. [from] bis [to]]]></de>
<en><![CDATA[approx. [from] to [to]]]></en>
</locale>
<locale name="fields.ShippingTimeFrontendView.timeperiod.period">
<de><![CDATA[ca. [period]]]></de>
<en><![CDATA[approx. [period]]]></en>
</locale>
<locale name="fields.ShippingTimeFrontendView.timeperiod.unit_single.second">
<de><![CDATA[Sekunde]]></de>
<en><![CDATA[second]]></en>
......@@ -345,6 +349,15 @@
]]></en>
</locale>
<locale name="shipping.settings.deliveryTimeDefault">
<de><![CDATA[Standard-Lieferzeit]]></de>
<en><![CDATA[Default delivery time]]></en>
</locale>
<locale name="shipping.settings.deliveryTimeDefault.description">
<de><![CDATA[Legt den Standardwert für das "Lieferzeit"-Feld fest, wenn ein Produkt neu angelegt wird bzw. kein Feldwert gesetzt ist.]]></de>
<en><![CDATA[Determines the default value for the "Delivery time" field for newly created products or if no field value is set.]]></en>
</locale>
<locale name="shipping.order.title">
<de><![CDATA[Versand: [shipping]]]></de>
<en><![CDATA[Shipping: [shipping]]]></en>
......
......@@ -15,6 +15,10 @@
<conf name="ruleFields">
<type><![CDATA[string]]></type>
</conf>
<conf name="deliveryTimeDefault">
<type><![CDATA[string]]></type>
<defaultvalue><![CDATA[{"from":"","to":"","unit":"second","option":"immediately_available"}]]></defaultvalue>
</conf>
</section>
<section name="no_rules">
......@@ -76,6 +80,19 @@
<locale group="quiqqer/shipping" var="shipping.settings.ruleFields.description"/>
</description>
</input>
<input type="hidden"
conf="shipping.deliveryTimeDefault"
data-qui="package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTimePeriod"
>
<text>
<locale group="quiqqer/shipping" var="shipping.settings.deliveryTimeDefault"/>
</text>
<description>
<locale group="quiqqer/shipping" var="shipping.settings.deliveryTimeDefault.description"/>
</description>
</input>
</settings>
<settings title="mail" name="mail">
......
......@@ -7,6 +7,7 @@
namespace QUI\ERP\Shipping;
use QUI;
use QUI\ERP\Products\Handler\Fields as ProductFields;
use \Quiqqer\Engine\Collector;
/**
......@@ -23,6 +24,8 @@ class EventHandler
*/
public static function onPackageSetup()
{
// Translations
$languages = QUI\Translator::getAvailableLanguages();
// create locale
......@@ -66,6 +69,9 @@ public static function onPackageSetup()
} catch (QUI\Exception $Exception) {
QUI\System\Log::addNotice($Exception->getMessage());
}
// Product fields
self::createProductFields();
}
/**
......@@ -264,4 +270,58 @@ public static function onUserSaveBegin(QUI\Users\User $User)
QUI\System\Log::writeDebugException($Exception);
}
}
/**
* Create all fixed product fields that quiqqer/shipping provides
*
* @return void
* @throws QUI\Exception
*/
protected static function createProductFields()
{
$fields = [
Shipping::PRODUCT_FIELD_SHIPPING_TIME => [
'title' => [
'de' => 'Lieferzeit',
'en' => 'Delivery time'
],
'type' => Shipping::PRODUCT_FIELD_TYPE_SHIPPING_TIME,
'public' => true,
'standard' => true
]
];
$fieldsCreated = false;
foreach ($fields as $fieldId => $field) {
try {
ProductFields::getField($fieldId);
continue;
} catch (\Exception $Exception) {
// Field does not exist -> create it
}
try {
ProductFields::createField([
'id' => $fieldId,
'type' => $field['type'],
'titles' => $field['title'],
'workingtitles' => $field['title'],
'systemField' => 0,
'standardField' => !empty($field['standard']) ? 1 : 0,
'publicField' => !empty($field['public']) ? 1 : 0,
'options' => !empty($field['options']) ? $field['options'] : null
]);
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
continue;
}
$fieldsCreated = true;
}
if ($fieldsCreated) {
QUI\Translator::publish('quiqqer/products');
}
}
}
......@@ -54,11 +54,17 @@ public function create()
$singleTime = true;
if ($from === $to) {
$valueText = $from;
$valueText = $L->get($lg, 'fields.ShippingTimeFrontendView.timeperiod.period', [
'period' => $from
]);
} elseif (empty($from) && !empty($to)) {
$valueText = $to;
$valueText = $L->get($lg, 'fields.ShippingTimeFrontendView.timeperiod.period', [
'period' => $to
]);
} elseif (!empty($from) && empty($to)) {
$valueText = $from;
$valueText = $L->get($lg, 'fields.ShippingTimeFrontendView.timeperiod.period', [
'period' => $from
]);
} else {
$valueText = $L->get($lg, 'fields.ShippingTimeFrontendView.timeperiod.from_to', [
'from' => $from,
......@@ -80,6 +86,6 @@ public function create()
'valueText' => $valueText
]);
return $Engine->fetch(\dirname(__FILE__).'/UnitSelectFrontendView.html');
return $Engine->fetch(\dirname(__FILE__).'/ShippingTimePeriodFrontendView.html');
}
}
......@@ -59,7 +59,7 @@ public function cleanup($value)
$value = parent::cleanup($value);
if (empty($value)) {
return $value;
return $this->getDefaultValueFromConfig();
}
switch ($value['option']) {
......@@ -69,7 +69,7 @@ public function cleanup($value)
break;
default:
return $this->defaultValue;
return $this->getDefaultValueFromConfig();
}
return $value;
......@@ -92,4 +92,27 @@ public function getFrontendView()
{
return new ShippingTimeFrontendView($this->getFieldDataForView());
}
/**
* Get default value for the ShippingTimePeriod field
*
* @return array|null
*/
protected function getDefaultValueFromConfig()
{
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 null;
}
return \json_decode($defaultValue, true);
}
}
......@@ -17,6 +17,16 @@
*/
class Shipping extends QUI\Utils\Singleton
{
/**
* Product fields provided by quiqqer/shipping
*/
const PRODUCT_FIELD_SHIPPING_TIME = 300;
/**
* Product field types provided by quiqqer/shipping
*/
const PRODUCT_FIELD_TYPE_SHIPPING_TIME = 'shipping.ShippingTimePeriod';
/**
* Continue order if no rule was found
*/
......
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