Skip to content

Commit

Permalink
Merge pull request #251 from oc-shopaholic/develop
Browse files Browse the repository at this point in the history
Release version 1.25.0
  • Loading branch information
kharanenka authored Feb 14, 2020
2 parents 48d795b + d8da026 commit a1154e6
Show file tree
Hide file tree
Showing 32 changed files with 1,079 additions and 20 deletions.
15 changes: 15 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
use Lovata\Shopaholic\Classes\Event\Category\CategoryModelHandler;
//Currency events
use Lovata\Shopaholic\Classes\Event\Currency\CurrencyModelHandler;
//Measure events
use Lovata\Shopaholic\Classes\Event\Measure\MeasureModelHandler;
//Offer events
use Lovata\Shopaholic\Classes\Event\Offer\OfferModelHandler;
use Lovata\Shopaholic\Classes\Event\Offer\ExtendOfferFieldsHandler;
//Price events
use Lovata\Shopaholic\Classes\Event\Price\PriceModelHandler;
//Product events
Expand Down Expand Up @@ -136,6 +139,15 @@ public function registerSettings()
'shopaholic-menu-import-xml-file',
],
],
'shopaholic-menu-measure' => [
'label' => 'lovata.shopaholic::lang.menu.measure',
'description' => 'lovata.shopaholic::lang.menu.measure_description',
'category' => 'lovata.shopaholic::lang.tab.settings',
'url' => Backend::url('lovata/shopaholic/measures'),
'icon' => 'icon-balance-scale',
'permissions' => ['shopaholic-menu-measure'],
'order' => 1650,
],
];
}

Expand All @@ -159,8 +171,11 @@ protected function addEventListener()
Event::subscribe(CategoryModelHandler::class);
//Currency events
Event::subscribe(CurrencyModelHandler::class);
//Measure events
Event::subscribe(MeasureModelHandler::class);
//Offer events
Event::subscribe(OfferModelHandler::class);
Event::subscribe(ExtendOfferFieldsHandler::class);
//Price events
Event::subscribe(PriceModelHandler::class);
//Product events
Expand Down
35 changes: 35 additions & 0 deletions classes/event/measure/MeasureModelHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Measure;

use Lovata\Toolbox\Classes\Event\ModelHandler;

use Lovata\Shopaholic\Models\Measure;
use Lovata\Shopaholic\Classes\Item\MeasureItem;

/**
* Class MeasureModelHandler
* @package Lovata\Shopaholic\Classes\Event\Measure
* @author Andrey Kharanenka, [email protected], LOVATA Group
*/
class MeasureModelHandler extends ModelHandler
{
/** @var Measure */
protected $obElement;

/**
* Get model class name
* @return string
*/
protected function getModelClass()
{
return Measure::class;
}

/**
* Get item class name
* @return string
*/
protected function getItemClass()
{
return MeasureItem::class;
}
}
131 changes: 131 additions & 0 deletions classes/event/offer/ExtendOfferFieldsHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Offer;

use Lang;
use Lovata\Shopaholic\Models\Measure;
use Lovata\Shopaholic\Models\Settings;
use Lovata\Toolbox\Classes\Event\AbstractBackendFieldHandler;

use Lovata\Shopaholic\Models\Offer;
use Lovata\Shopaholic\Controllers\Offers;

/**
* Class ExtendOfferFieldsHandler
* @package Lovata\Shopaholic\Classes\Event\Offer
* @author Andrey Kharanenka, [email protected], LOVATA Group
*/
class ExtendOfferFieldsHandler extends AbstractBackendFieldHandler
{
protected $iPriority = 15000;

/**
* Extend form fields
* @param \Backend\Widgets\Form $obWidget
*/
protected function extendFields($obWidget)
{
$arAdditionFields = [
'weight' => [
'label' => $this->getWeightFieldLabel(),
'type' => 'number',
'span' => 'left',
'tab' => 'lovata.shopaholic::lang.tab.dimensions',
],
'height' => [
'label' => $this->getDimensionsFieldLabel('lovata.toolbox::lang.field.height'),
'type' => 'number',
'span' => 'left',
'tab' => 'lovata.shopaholic::lang.tab.dimensions',
],
'length' => [
'label' => $this->getDimensionsFieldLabel('lovata.toolbox::lang.field.length'),
'type' => 'number',
'span' => 'left',
'tab' => 'lovata.shopaholic::lang.tab.dimensions',
],
'width' => [
'label' => $this->getDimensionsFieldLabel('lovata.toolbox::lang.field.width'),
'type' => 'number',
'span' => 'left',
'tab' => 'lovata.shopaholic::lang.tab.dimensions',
],
'quantity_in_unit' => [
'label' => 'lovata.shopaholic::lang.field.quantity_in_unit',
'type' => 'number',
'span' => 'left',
'tab' => 'lovata.shopaholic::lang.tab.dimensions',
],
'measure_of_unit' => [
'label' => 'lovata.shopaholic::lang.field.measure_of_unit',
'type' => 'relation',
'span' => 'left',
'emptyOption' => 'lovata.toolbox::lang.field.empty',
'tab' => 'lovata.shopaholic::lang.tab.dimensions',
],
];

$obWidget->addTabFields($arAdditionFields);
}

/**
* Get weight field label
* @return string
*/
protected function getWeightFieldLabel()
{
$sLabel = Lang::get('lovata.toolbox::lang.field.weight');
$iMeasureID = Settings::getValue('weight_measure');
if (empty($iMeasureID)) {
return $sLabel;
}

$obMeasure = Measure::find($iMeasureID);
if (empty($obMeasure)) {
return $sLabel;
}

$sLabel .= " ({$obMeasure->name})";

return $sLabel;
}

/**
* Get dimensions field label
* @param string $sLangPath
* @return string
*/
protected function getDimensionsFieldLabel($sLangPath)
{
$sLabel = Lang::get($sLangPath);
$iMeasureID = Settings::getValue('dimensions_measure');
if (empty($iMeasureID)) {
return $sLabel;
}

$obMeasure = Measure::find($iMeasureID);
if (empty($obMeasure)) {
return $sLabel;
}

$sLabel .= " ({$obMeasure->name})";

return $sLabel;
}

/**
* Get model class name
* @return string
*/
protected function getModelClass() : string
{
return Offer::class;
}

/**
* Get controller class name
* @return string
*/
protected function getControllerClass() : string
{
return Offers::class;
}
}
40 changes: 40 additions & 0 deletions classes/helper/MeasureHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php namespace Lovata\Shopaholic\Classes\Helper;

use October\Rain\Support\Traits\Singleton;

use Lovata\Shopaholic\Classes\Item\MeasureItem;
use Lovata\Shopaholic\Models\Settings;

/**
* Class MeasureHelper
* @package Lovata\Shopaholic\Classes\Helper
* @author Andrey Kharanenka, [email protected], LOVATA Group
*/
class MeasureHelper
{
use Singleton;

/**
* Get dimensions unit measure
* @return MeasureItem
*/
public function getDimensionsMeasureItem()
{
$iMeasureID = Settings::getValue('dimensions_measure');
$obMeasureItem = MeasureItem::make($iMeasureID);

return $obMeasureItem;
}

/**
* Get weight unit measure
* @return MeasureItem
*/
public function getWeightMeasureItem()
{
$iMeasureID = Settings::getValue('weight_measure');
$obMeasureItem = MeasureItem::make($iMeasureID);

return $obMeasureItem;
}
}
28 changes: 28 additions & 0 deletions classes/import/ImportOfferModelFromCSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Lovata\Toolbox\Classes\Helper\AbstractImportModelFromCSV;

use Lovata\Shopaholic\Models\Measure;
use Lovata\Shopaholic\Models\Offer;
use Lovata\Shopaholic\Models\Product;

Expand Down Expand Up @@ -36,6 +37,7 @@ protected function prepareImportData()
$this->setActiveField();
$this->setProductField();
$this->setQuantityField();
$this->setMeasureField();

$this->initPreviewImage();
$this->initImageList();
Expand Down Expand Up @@ -94,4 +96,30 @@ protected function setQuantityField()

$this->arImportData['quantity'] = $iQuantity;
}

/**
* Set measure filed value
*/
protected function setMeasureField()
{
$sMeasure = array_get($this->arImportData, 'measure_of_unit');
array_forget($this->arImportData, 'measure_of_unit');
if ($sMeasure === null) {
return;
}

if (empty($sMeasure)) {
$this->arImportData['measure_of_unit_id'] = null;
return;
}

$obMeasure = Measure::getByName($sMeasure)->first();
if (empty($obMeasure)) {
$obMeasure = Measure::create([
'name' => $sMeasure,
]);
}

$this->arImportData['measure_of_unit_id'] = $obMeasure->id;
}
}
58 changes: 46 additions & 12 deletions classes/import/ImportOfferModelFromXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Lang;
use Lovata\Toolbox\Classes\Helper\AbstractImportModelFromXML;

use Lovata\Shopaholic\Models\Measure;
use Lovata\Shopaholic\Models\Offer;
use Lovata\Shopaholic\Models\Product;
use Lovata\Shopaholic\Models\PriceType;
Expand Down Expand Up @@ -45,18 +46,24 @@ public function __construct()
public function getFields() : array
{
$this->arFieldList = [
'external_id' => Lang::get('lovata.toolbox::lang.field.external_id'),
'product_id' => Lang::get('lovata.shopaholic::lang.field.product_id'),
'active' => Lang::get('lovata.toolbox::lang.field.active'),
'name' => Lang::get('lovata.toolbox::lang.field.name'),
'code' => Lang::get('lovata.toolbox::lang.field.code'),
'price' => Lang::get('lovata.shopaholic::lang.field.price'),
'old_price' => Lang::get('lovata.shopaholic::lang.field.old_price'),
'quantity' => Lang::get('lovata.shopaholic::lang.field.quantity'),
'preview_text' => Lang::get('lovata.toolbox::lang.field.preview_text'),
'description' => Lang::get('lovata.toolbox::lang.field.description'),
'preview_image' => Lang::get('lovata.toolbox::lang.field.preview_image'),
'images' => Lang::get('lovata.toolbox::lang.field.images'),
'external_id' => Lang::get('lovata.toolbox::lang.field.external_id'),
'product_id' => Lang::get('lovata.shopaholic::lang.field.product_id'),
'active' => Lang::get('lovata.toolbox::lang.field.active'),
'name' => Lang::get('lovata.toolbox::lang.field.name'),
'code' => Lang::get('lovata.toolbox::lang.field.code'),
'price' => Lang::get('lovata.shopaholic::lang.field.price'),
'old_price' => Lang::get('lovata.shopaholic::lang.field.old_price'),
'quantity' => Lang::get('lovata.shopaholic::lang.field.quantity'),
'weight' => Lang::get('lovata.toolbox::lang.field.weight'),
'height' => Lang::get('lovata.toolbox::lang.field.height'),
'length' => Lang::get('lovata.toolbox::lang.field.length'),
'width' => Lang::get('lovata.toolbox::lang.field.width'),
'quantity_in_unit' => Lang::get('lovata.shopaholic::lang.field.quantity_in_unit'),
'measure_of_unit' => Lang::get('lovata.shopaholic::lang.field.measure_of_unit'),
'preview_text' => Lang::get('lovata.toolbox::lang.field.preview_text'),
'description' => Lang::get('lovata.toolbox::lang.field.description'),
'preview_image' => Lang::get('lovata.toolbox::lang.field.preview_image'),
'images' => Lang::get('lovata.toolbox::lang.field.images'),
];

//Get price types
Expand Down Expand Up @@ -92,6 +99,7 @@ protected function prepareImportData()
$this->setActiveField();
$this->setProductField();
$this->setQuantityField();
$this->setMeasureField();

$this->initPreviewImage();
$this->initImageList();
Expand Down Expand Up @@ -153,6 +161,32 @@ protected function setQuantityField()
$this->arImportData['quantity'] = $iQuantity;
}

/**
* Set measure filed value
*/
protected function setMeasureField()
{
$sMeasure = array_get($this->arImportData, 'measure_of_unit');
array_forget($this->arImportData, 'measure_of_unit');
if ($sMeasure === null) {
return;
}

if (empty($sMeasure)) {
$this->arImportData['measure_of_unit_id'] = null;
return;
}

$obMeasure = Measure::getByName($sMeasure)->first();
if (empty($obMeasure)) {
$obMeasure = Measure::create([
'name' => $sMeasure,
]);
}

$this->arImportData['measure_of_unit_id'] = $obMeasure->id;
}

/**
* Prepare import settings
*/
Expand Down
Loading

0 comments on commit a1154e6

Please sign in to comment.