first initial commit

This commit is contained in:
merdan 2021-06-04 11:26:26 +05:00
parent c7bfcbda6b
commit 25d8b45b27
5354 changed files with 466146 additions and 125 deletions

5
.gitignore vendored
View File

@ -30,3 +30,8 @@ _ide_helper.php
.DS_Store
package-lock.json
/node_modules
#storage
/storage/app
/storage/framework/cache
/storage/framework/sessions

View File

@ -137,7 +137,7 @@ return [
|
*/
'key' => 'CHANGE_ME!!!!!!!!!!!!!!!!!!!!!!!',
'key' => 'S6g15W4dDKtMwoxFbvFRPEtFlEMDT661',
'cipher' => 'AES-256-CBC',

View File

@ -131,7 +131,7 @@ return [
|
*/
'disableCoreUpdates' => false,
'disableCoreUpdates' => true,
/*
|--------------------------------------------------------------------------
@ -371,7 +371,7 @@ return [
|
*/
'defaultMask' => ['file' => null, 'folder' => null],
'defaultMask' => ['file' => '644', 'folder' => '755'],
/*
|--------------------------------------------------------------------------

View File

@ -55,11 +55,11 @@ return [
'mysql' => [
'driver' => 'mysql',
'engine' => 'InnoDB',
'host' => 'localhost',
'host' => '192.168.1.2',
'port' => 3306,
'database' => 'database',
'username' => 'root',
'password' => '',
'database' => 'birzha',
'username' => 'orient',
'password' => 'orient',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',

View File

@ -64,11 +64,6 @@ class FileUpload extends FormWidgetBase
*/
public $maxFilesize;
/**
* @var integer|null Max files number.
*/
public $maxFiles;
/**
* @var array Options used for generating thumbnails.
*/
@ -114,7 +109,6 @@ class FileUpload extends FormWidgetBase
'imageHeight',
'fileTypes',
'maxFilesize',
'maxFiles',
'mimeTypes',
'thumbOptions',
'useCaption',
@ -158,14 +152,13 @@ class FileUpload extends FormWidgetBase
$this->vars['singleFile'] = $fileList->first();
$this->vars['displayMode'] = $this->getDisplayMode();
$this->vars['emptyIcon'] = $this->getConfig('emptyIcon', 'icon-upload');
$this->vars['imageHeight'] = (is_int($this->imageHeight)) ? $this->imageHeight : null;
$this->vars['imageWidth'] = (is_int($this->imageWidth)) ? $this->imageWidth : null;
$this->vars['imageHeight'] = $this->imageHeight;
$this->vars['imageWidth'] = $this->imageWidth;
$this->vars['acceptedFileTypes'] = $this->getAcceptedFileTypes(true);
$this->vars['maxFilesize'] = (is_int($this->maxFilesize)) ? $this->maxFilesize : null;
$this->vars['maxFilesize'] = $this->maxFilesize;
$this->vars['cssDimensions'] = $this->getCssDimensions();
$this->vars['cssBlockDimensions'] = $this->getCssDimensions('block');
$this->vars['useCaption'] = $this->useCaption;
$this->vars['maxFiles'] = (is_int($this->maxFiles)) ? $this->maxFiles : null;
$this->vars['prompt'] = $this->getPromptText();
}

View File

@ -34,7 +34,7 @@
FileUpload.prototype = Object.create(BaseProto)
FileUpload.prototype.constructor = FileUpload
FileUpload.prototype.init = function () {
FileUpload.prototype.init = function() {
if (this.options.isMulti === null) {
this.options.isMulti = this.$el.hasClass('is-multi')
}
@ -69,7 +69,7 @@
}
FileUpload.prototype.dispose = function () {
FileUpload.prototype.dispose = function() {
this.$el.off('click', '.upload-object.is-success', this.proxy(this.onClickSuccessObject))
this.$el.off('click', '.upload-object.is-error', this.proxy(this.onClickErrorObject))
@ -94,25 +94,18 @@
// Uploading
//
FileUpload.prototype.bindUploader = function () {
FileUpload.prototype.bindUploader = function() {
this.uploaderOptions = {
url: this.options.url,
paramName: this.options.paramName,
clickable: this.$uploadButton.get(0),
previewsContainer: this.$filesContainer.get(0),
maxFiles: !this.options.isMulti ? 1 : null,
maxFilesize: this.options.maxFilesize,
timeout: 0,
headers: {}
}
if (!this.options.isMulti) {
this.uploaderOptions.maxFiles = 1
} else if (this.options.maxFiles) {
this.uploaderOptions.maxFiles = this.options.maxFiles
} else {
this.uploaderOptions.maxFiles = null
}
if (this.options.fileTypes) {
this.uploaderOptions.acceptedFiles = this.options.fileTypes
}
@ -138,43 +131,13 @@
}
this.dropzone = new Dropzone(this.$el.get(0), this.uploaderOptions)
this.dropzone.on('addedfile', this.proxy(this.onUploadAddedFile))
this.dropzone.on('sending', this.proxy(this.onUploadSending))
this.dropzone.on('success', this.proxy(this.onUploadSuccess))
this.dropzone.on('error', this.proxy(this.onUploadError))
this.dropzone.on('maxfilesreached', this.proxy(this.removeEventListeners))
this.dropzone.on('removedfile', this.proxy(this.setupEventListeners))
this.loadAlreadyUploadedFiles()
}
FileUpload.prototype.removeEventListeners = function () {
this.dropzone.removeEventListeners()
}
FileUpload.prototype.setupEventListeners = function () {
if (this.dropzone.files.length < this.dropzone.options.maxFiles) {
this.dropzone.setupEventListeners()
}
}
FileUpload.prototype.loadAlreadyUploadedFiles = function () {
var self = this
this.$el.find('.server-file').each(function () {
var file = $(this).data()
self.dropzone.files.push(file)
self.dropzone.emit('addedfile', file)
self.dropzone.emit('success', file, file)
$(this).remove()
})
self.dropzone._updateMaxFilesReachedClass()
}
FileUpload.prototype.onResizeFileInfo = function (file) {
FileUpload.prototype.onResizeFileInfo = function(file) {
var info,
targetWidth,
targetHeight
@ -223,12 +186,12 @@
this.evalIsPopulated()
}
FileUpload.prototype.onUploadSending = function (file, xhr, formData) {
FileUpload.prototype.onUploadSending = function(file, xhr, formData) {
this.addExtraFormData(formData)
xhr.setRequestHeader('X-OCTOBER-REQUEST-HANDLER', this.options.uploadHandler)
}
FileUpload.prototype.onUploadSuccess = function (file, response) {
FileUpload.prototype.onUploadSuccess = function(file, response) {
var $preview = $(file.previewElement),
$img = $('.image img', $preview)
@ -244,7 +207,7 @@
this.triggerChange();
}
FileUpload.prototype.onUploadError = function (file, error) {
FileUpload.prototype.onUploadError = function(file, error) {
var $preview = $(file.previewElement)
$preview.addClass('is-error')
}
@ -252,11 +215,11 @@
/*
* Trigger change event (Compatibility with october.form.js)
*/
FileUpload.prototype.triggerChange = function () {
FileUpload.prototype.triggerChange = function() {
this.$el.closest('[data-field-name]').trigger('change.oc.formwidget')
}
FileUpload.prototype.addExtraFormData = function (formData) {
FileUpload.prototype.addExtraFormData = function(formData) {
if (this.options.extraData) {
$.each(this.options.extraData, function (name, value) {
formData.append(name, value)
@ -271,10 +234,10 @@
}
}
FileUpload.prototype.removeFileFromElement = function ($element) {
FileUpload.prototype.removeFileFromElement = function($element) {
var self = this
$element.each(function () {
$element.each(function() {
var $el = $(this),
obj = $el.data('dzFileObject')
@ -291,7 +254,7 @@
// Sorting
//
FileUpload.prototype.bindSortable = function () {
FileUpload.prototype.bindSortable = function() {
var
self = this,
placeholderEl = $('<div class="upload-object upload-placeholder"/>').css({
@ -313,15 +276,16 @@
})
}
FileUpload.prototype.onSortAttachments = function () {
FileUpload.prototype.onSortAttachments = function() {
if (this.options.sortHandler) {
/*
* Build an object of ID:ORDER
*/
var orderData = {}
this.$el.find('.upload-object.is-success')
.each(function (index) {
.each(function(index){
var id = $(this).data('id')
orderData[id] = index + 1
})
@ -336,16 +300,16 @@
// User interaction
//
FileUpload.prototype.onRemoveObject = function (ev) {
FileUpload.prototype.onRemoveObject = function(ev) {
var self = this,
$object = $(ev.target).closest('.upload-object')
$(ev.target)
.closest('.upload-remove-button')
.one('ajaxPromise', function () {
.one('ajaxPromise', function(){
$object.addClass('is-loading')
})
.one('ajaxDone', function () {
.one('ajaxDone', function(){
self.removeFileFromElement($object)
self.evalIsPopulated()
self.triggerChange()
@ -370,9 +334,9 @@
extraData: { file_id: $target.data('id') }
})
$target.one('popupComplete', function (event, element, modal) {
$target.one('popupComplete', function(event, element, modal){
modal.one('ajaxDone', 'button[type=submit]', function (e, context, data) {
modal.one('ajaxDone', 'button[type=submit]', function(e, context, data) {
if (data.displayName) {
$('[data-dz-name]', $target).text(data.displayName)
}
@ -380,7 +344,7 @@
})
}
FileUpload.prototype.onClickErrorObject = function (ev) {
FileUpload.prototype.onClickErrorObject = function(ev) {
var
self = this,
$target = $(ev.target).closest('.upload-object'),
@ -402,7 +366,7 @@
})
var $container = $target.data('oc.popover').$container
$container.one('click', '[data-remove-file]', function () {
$container.one('click', '[data-remove-file]', function() {
$target.data('oc.popover').hide()
self.removeFileFromElement($target)
self.evalIsPopulated()
@ -413,7 +377,7 @@
// Helpers
//
FileUpload.prototype.evalIsPopulated = function () {
FileUpload.prototype.evalIsPopulated = function() {
var isPopulated = !!$('.upload-object', this.$filesContainer).length
this.$el.toggleClass('is-populated', isPopulated)

View File

@ -9,7 +9,6 @@
data-max-filesize="<?= $maxFilesize ?>"
<?php if ($useCaption): ?>data-config-handler="<?= $this->getEventHandler('onLoadAttachmentConfig') ?>"<?php endif ?>
<?php if ($acceptedFileTypes): ?>data-file-types="<?= $acceptedFileTypes ?>"<?php endif ?>
<?php if ($maxFiles): ?>data-max-files="<?= $maxFiles ?>"<?php endif ?>
<?= $this->formField->getAttributes() ?>
>
@ -21,14 +20,27 @@
<!-- Existing files -->
<div class="upload-files-container">
<?php foreach ($fileList as $file): ?>
<div class="server-file"
data-id="<?= $file->id ?>"
data-path="<?= $file->pathUrl ?>"
data-thumb="<?= $file->thumbUrl ?>"
data-name="<?= e($file->title ?: $file->file_name) ?>"
data-size="<?= e($file->file_size) ?>"
data-accepted="true"
></div>
<div class="upload-object is-success" data-id="<?= $file->id ?>" data-path="<?= $file->pathUrl ?>">
<div class="icon-container">
<i class="icon-file"></i>
</div>
<div class="info">
<h4 class="filename">
<span data-dz-name><?= e($file->title ?: $file->file_name) ?></span>
<a
href="javascript:;"
class="upload-remove-button"
data-request="<?= $this->getEventHandler('onRemoveAttachment') ?>"
data-request-confirm="<?= e(trans('backend::lang.fileupload.remove_confirm')) ?>"
data-request-data="file_id: <?= $file->id ?>"
><i class="icon-times"></i></a>
</h4>
<p class="size"><?= e($file->sizeToString()) ?></p>
</div>
<div class="meta">
<a href="javascript:;" class="drag-handle"><i class="icon-bars"></i></a>
</div>
</div>
<?php endforeach ?>
</div>
</div>

View File

@ -9,7 +9,6 @@
data-max-filesize="<?= $maxFilesize ?>"
<?php if ($useCaption): ?>data-config-handler="<?= $this->getEventHandler('onLoadAttachmentConfig') ?>"<?php endif ?>
<?php if ($acceptedFileTypes): ?>data-file-types="<?= $acceptedFileTypes ?>"<?php endif ?>
<?php if ($maxFiles): ?>data-max-files="<?= $maxFiles ?>"<?php endif ?>
<?= $this->formField->getAttributes() ?>
>
@ -21,14 +20,27 @@
<!-- Existing files -->
<div class="upload-files-container">
<?php foreach ($fileList as $file): ?>
<div class="server-file"
data-id="<?= $file->id ?>"
data-path="<?= $file->pathUrl ?>"
data-thumb="<?= $file->thumbUrl ?>"
data-name="<?= e($file->title ?: $file->file_name) ?>"
data-size="<?= e($file->file_size) ?>"
data-accepted="true"
></div>
<div class="upload-object is-success" data-id="<?= $file->id ?>" data-path="<?= $file->pathUrl ?>">
<div class="icon-container image">
<img src="<?= $file->thumbUrl ?>" alt="" />
</div>
<div class="info">
<h4 class="filename">
<span data-dz-name><?= e($file->title ?: $file->file_name) ?></span>
<a
href="javascript:;"
class="upload-remove-button"
data-request="<?= $this->getEventHandler('onRemoveAttachment') ?>"
data-request-confirm="<?= e(trans('backend::lang.fileupload.remove_confirm')) ?>"
data-request-data="file_id: <?= $file->id ?>"
><i class="icon-times"></i></a>
</h4>
<p class="size"><?= e($file->sizeToString()) ?></p>
</div>
<div class="meta">
<a href="javascript:;" class="drag-handle"><i class="icon-bars"></i></a>
</div>
</div>
<?php endforeach ?>
</div>
</div>

View File

@ -19,7 +19,7 @@
<li class="taglist__item"><?= e(trans($option)) ?></li>
<?php endforeach ?>
</ul>
<?php if (is_array($field->value)): ?>
<?php if ($field->readOnly && is_array($field->value)): ?>
<?php foreach ($displayOnlyOptions as $option): ?>
<input
type="hidden"

View File

@ -392,7 +392,11 @@ class Filter extends WidgetBase
$query = $model->newQuery();
$query->limit(200);
/*
* The 'group' scope has trouble supporting more than 500 records at a time
* @todo Introduce a more advanced version with robust list support.
*/
$query->limit(500);
/**
* @event backend.filter.extendQuery
@ -418,17 +422,7 @@ class Filter extends WidgetBase
$this->fireSystemEvent('backend.filter.extendQuery', [$query, $scope]);
if (!$searchQuery) {
// If scope has active filter(s) run additional query and merge it with base query
if ($scope->value) {
$modelIds = array_keys($scope->value);
$activeOptions = $model::findMany($modelIds);
}
$modelOptions = isset($activeOptions)
? $query->get()->merge($activeOptions)
: $query->get();
return $modelOptions;
return $query->get();
}
$searchFields = [$model->getKeyName(), $this->getScopeNameFrom($scope)];

View File

@ -290,17 +290,18 @@
active = this.scopeValues[this.activeScopeName],
available = this.scopeAvailable[this.activeScopeName],
fromItems = isDeselect ? active : available,
toItems = isDeselect ? available : active,
testFunc = function(active){ return active.id == itemId },
item = $.grep(fromItems, testFunc).pop() ?? {'id': itemId, 'name': $item.text()},
item = $.grep(fromItems, testFunc).pop(),
filtered = $.grep(fromItems, testFunc, true)
if (isDeselect) {
if (isDeselect)
this.scopeValues[this.activeScopeName] = filtered
this.scopeAvailable[this.activeScopeName].push(item)
} else {
else
this.scopeAvailable[this.activeScopeName] = filtered
this.scopeValues[this.activeScopeName].push(item)
}
if (item)
toItems.push(item)
this.toggleFilterButtons(active)
this.updateScopeSetting(this.$activeScope, isDeselect ? filtered.length : active.length)

View File

@ -3163,10 +3163,13 @@ $item.addClass('animate-enter').prependTo($otherContainer).one('webkitAnimationE
if(!this.scopeValues[this.activeScopeName])
return
var
itemId=$item.data('item-id'),active=this.scopeValues[this.activeScopeName],available=this.scopeAvailable[this.activeScopeName],fromItems=isDeselect?active:available,testFunc=function(active){return active.id==itemId},item=$.grep(fromItems,testFunc).pop()??{'id':itemId,'name':$item.text()},filtered=$.grep(fromItems,testFunc,true)
if(isDeselect){this.scopeValues[this.activeScopeName]=filtered
this.scopeAvailable[this.activeScopeName].push(item)}else{this.scopeAvailable[this.activeScopeName]=filtered
this.scopeValues[this.activeScopeName].push(item)}
itemId=$item.data('item-id'),active=this.scopeValues[this.activeScopeName],available=this.scopeAvailable[this.activeScopeName],fromItems=isDeselect?active:available,toItems=isDeselect?available:active,testFunc=function(active){return active.id==itemId},item=$.grep(fromItems,testFunc).pop(),filtered=$.grep(fromItems,testFunc,true)
if(isDeselect)
this.scopeValues[this.activeScopeName]=filtered
else
this.scopeAvailable[this.activeScopeName]=filtered
if(item)
toItems.push(item)
this.toggleFilterButtons(active)
this.updateScopeSetting(this.$activeScope,isDeselect?filtered.length:active.length)
this.isActiveScopeDirty=true

View File

@ -0,0 +1,19 @@
# MIT license
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,146 @@
<?php namespace Indikator\User;
use System\Classes\PluginBase;
use RainLab\User\Controllers\Users as UsersController;
use RainLab\User\Models\User as UserModel;
use Lang;
class Plugin extends PluginBase
{
public $require = ['RainLab.User'];
public function pluginDetails()
{
return [
'name' => 'indikator.user::lang.plugin.name',
'description' => 'indikator.user::lang.plugin.description',
'author' => 'indikator.user::lang.plugin.author',
'icon' => 'icon-user-plus',
'homepage' => 'https://github.com/gergo85/oc-user-plus'
];
}
public function registerReportWidgets()
{
return [
'Indikator\User\ReportWidgets\Users' => [
'label' => 'indikator.user::lang.widget.title',
'context' => 'dashboard',
'permissions' => ['indikator.user.widget']
]
];
}
public function registerPermissions()
{
return [
'indikator.user.widget' => [
'tab' => 'indikator.user::lang.plugin.name',
'label' => 'indikator.user::lang.widget.permission',
'roles' => ['publisher']
]
];
}
public function boot()
{
UserModel::extend(function($model)
{
$model->addFillable([
'iu_gender',
'iu_telephone',
'iu_job',
'iu_company',
'iu_about',
'iu_webpage',
'iu_blog',
'iu_facebook',
'iu_twitter',
'iu_skype',
'iu_icq',
'iu_comment'
]);
});
UsersController::extendFormFields(function($form, $model, $context)
{
if (!$model instanceof UserModel) {
return;
}
$form->addTabFields([
'iu_gender' => [
'label' => 'indikator.user::lang.personal.gender',
'tab' => 'indikator.user::lang.personal.tab',
'type' => 'dropdown',
'options' => [
'unknown' => Lang::get('indikator.user::lang.gender.unknown'),
'female' => Lang::get('indikator.user::lang.gender.female'),
'male' => Lang::get('indikator.user::lang.gender.male')
],
'span' => 'auto'
],
'iu_telephone' => [
'label' => 'indikator.user::lang.personal.telephone',
'tab' => 'indikator.user::lang.personal.tab',
'span' => 'auto'
],
'iu_job' => [
'label' => 'indikator.user::lang.personal.job',
'tab' => 'indikator.user::lang.personal.tab',
'span' => 'auto'
],
'iu_company' => [
'label' => 'indikator.user::lang.personal.company',
'tab' => 'indikator.user::lang.personal.tab',
'span' => 'auto'
],
'iu_about' => [
'label' => 'indikator.user::lang.personal.about',
'tab' => 'indikator.user::lang.personal.tab',
'type' => 'textarea',
'size' => 'small',
'span' => 'full'
],
'iu_webpage' => [
'label' => 'indikator.user::lang.internet.webpage',
'tab' => 'indikator.user::lang.internet.tab',
'span' => 'auto'
],
'iu_blog' => [
'label' => 'indikator.user::lang.internet.blog',
'tab' => 'indikator.user::lang.internet.tab',
'span' => 'auto'
],
'iu_facebook' => [
'label' => 'indikator.user::lang.internet.facebook',
'tab' => 'indikator.user::lang.internet.tab',
'span' => 'auto'
],
'iu_twitter' => [
'label' => 'indikator.user::lang.internet.twitter',
'tab' => 'indikator.user::lang.internet.tab',
'span' => 'auto'
],
'iu_skype' => [
'label' => 'indikator.user::lang.internet.skype',
'tab' => 'indikator.user::lang.internet.tab',
'span' => 'auto'
],
'iu_icq' => [
'label' => 'indikator.user::lang.internet.icq',
'tab' => 'indikator.user::lang.internet.tab',
'span' => 'auto'
]
]);
$form->addSecondaryTabFields([
'iu_comment' => [
'label' => 'indikator.user::lang.comment',
'type' => 'textarea',
'size' => 'small'
]
]);
});
}
}

View File

@ -0,0 +1,36 @@
# User Plus plugin
This plugin extend the [RainLab User](https://github.com/rainlab/user-plugin) plugin to some new fields.
## New fields
Name | Code
---------- | -----------
Gender | iu_gender
Telephone | iu_telephone
Job | iu_job
Company | iu_company
About me | iu_about
Webpage | iu_webpage
Blog | iu_blog
Facebook | iu_facebook
Twitter | iu_twitter
Skype | iu_skype
ICQ | iu_icq
Comment | iu_comment
## Available languages
* en - English
* de - Deutsch
* fr - Français
* hu - Magyar
* cs - Czech
## Installation
1. Go to the __Settings > Updates & Plugins__ page in the Backend.
1. Click on the __Install plugins__ button.
1. Type the __User Plus__ text in the search field.
1. Select the __first hit__ in the list.
## Add widget
1. Go to the __Dashboard__ page in the Backend.
1. Click on the __Manage widgets > Add widget__ button.
1. Select the __User Plus widget__ from the list.

View File

@ -0,0 +1,8 @@
{
"name": "indikator/user-plugin",
"type": "october-plugin",
"description": "None",
"require": {
"composer/installers": "~1.0"
}
}

View File

@ -0,0 +1,47 @@
<?php
return [
'plugin' => [
'name' => 'Uživatelé Plus',
'description' => 'Přidává nové pole do RainLab User pluginu.',
'author' => 'Gergő Szabó'
],
'personal' => [
'tab' => 'Osobní',
'gender' => 'Pohlaví',
'telephone' => 'Telefon',
'job' => 'Pracovní pozice',
'company' => 'Firma',
'about' => 'O osobě'
],
'internet' => [
'tab' => 'Internet',
'webpage' => 'Webové stránky',
'blog' => 'Blog',
'facebook' => 'Facebook',
'twitter' => 'Twitter',
'skype' => 'Skype',
'icq' => 'ICQ'
],
'gender' => [
'unknown' => 'neznámé',
'female' => 'žena',
'male' => 'muž'
],
'comment' => 'Komentář',
'widget' => [
'title' => 'Uživatelské statistiky',
'show_total' => 'Zobrazit celkový počet',
'show_active' => 'Zobrazit aktivní',
'show_inactive' => 'Zobrazit neaktivní',
'show_deleted' => 'Zobrazit smazané',
'show_guest' => 'Zobrazit host',
'show_superuser' => 'Zobrazit superuser',
'total' => 'Celkem',
'active' => 'Aktivní',
'inactive' => 'Neaktivní',
'deleted' => 'Smazané',
'guest' => 'Host',
'superuser' => 'Superuser'
]
];

View File

@ -0,0 +1,47 @@
<?php
return [
'plugin' => [
'name' => 'User-Plus',
'description' => 'Hinzugefügt einige nützliche Felder für RainLab Benutzer Plugin.',
'author' => 'Gergő Szabó'
],
'personal' => [
'tab' => 'Persönlich',
'gender' => 'Geschlecht',
'telephone' => 'Telefon',
'job' => 'Arbeit',
'company' => 'Unternehmen',
'about' => 'Über mich'
],
'internet' => [
'tab' => 'Internet',
'webpage' => 'Webseite',
'blog' => 'Blog',
'facebook' => 'Facebook',
'twitter' => 'Twitter',
'skype' => 'Skype',
'icq' => 'ICQ'
],
'gender' => [
'unknown' => 'unbekannt',
'female' => 'weiblich',
'male' => 'männlich'
],
'comment' => 'Kommentar',
'widget' => [
'title' => 'User-Stat',
'show_total' => 'Gesamt Zeige',
'show_active' => 'Zeigen Aktiv',
'show_inactive' => 'Zeigen Inaktiv',
'show_deleted' => 'Zeigen Gelöscht',
'show_guest' => 'Zeigen Gast',
'show_superuser' => 'Zeigen Superuser',
'total' => 'Gesamt',
'active' => 'Aktiv',
'inactive' => 'Inaktiv',
'deleted' => 'Gelöscht',
'guest' => 'Gast',
'superuser' => 'Superuser'
]
];

View File

@ -0,0 +1,48 @@
<?php
return [
'plugin' => [
'name' => 'User Plus',
'description' => 'Added some new fields for RainLab User plugin.',
'author' => 'Gergő Szabó'
],
'personal' => [
'tab' => 'Personal',
'gender' => 'Gender',
'telephone' => 'Telephone',
'job' => 'Job',
'company' => 'Company',
'about' => 'About me'
],
'internet' => [
'tab' => 'Internet',
'webpage' => 'Webpage',
'blog' => 'Blog',
'facebook' => 'Facebook',
'twitter' => 'Twitter',
'skype' => 'Skype',
'icq' => 'ICQ'
],
'gender' => [
'unknown' => 'unknown',
'female' => 'female',
'male' => 'male'
],
'comment' => 'Comment',
'widget' => [
'title' => 'User Stat',
'show_total' => 'Show total',
'show_active' => 'Show active',
'show_inactive' => 'Show inactive',
'show_deleted' => 'Show deleted',
'show_guest' => 'Show guest',
'show_superuser' => 'Show superuser',
'total' => 'Total',
'active' => 'Active',
'inactive' => 'Inactive',
'deleted' => 'Deleted',
'guest' => 'Guest',
'superuser' => 'Superuser',
'permission' => 'Manage the widget on Dashboard'
]
];

View File

@ -0,0 +1,47 @@
<?php
return [
'plugin' => [
'name' => 'User Plus',
'description' => 'Quelques champs supplémentaires pour le Plugin User de RainLab.',
'author' => 'Gergő Szabó'
],
'personal' => [
'tab' => 'Infos personnelles',
'gender' => 'Genre',
'telephone' => 'Téléphone',
'job' => 'Profession',
'company' => 'Compagnie',
'about' => 'Présentation'
],
'internet' => [
'tab' => 'Internet',
'webpage' => 'Page Web',
'blog' => 'Blog',
'facebook' => 'Facebook',
'twitter' => 'Twitter',
'skype' => 'Skype',
'icq' => 'ICQ'
],
'gender' => [
'unknown' => 'indéterminé',
'female' => 'femme',
'male' => 'homme'
],
'comment' => 'Commentaire',
'widget' => [
'title' => 'Statistiques de l\'utilisateur',
'show_total' => 'Afficher totale',
'show_active' => 'Afficher actif',
'show_inactive' => 'Afficher inactive',
'show_deleted' => 'Afficher supprimé',
'show_guest' => 'Afficher client',
'show_superuser' => 'Afficher superuser',
'total' => 'Global',
'active' => 'Actif',
'inactive' => 'Inactif',
'deleted' => 'Supprimé',
'guest' => 'Client',
'superuser' => 'Superuser'
]
];

View File

@ -0,0 +1,48 @@
<?php
return [
'plugin' => [
'name' => 'Felhasználók Plusz',
'description' => 'Néhány új mezővel egészíti ki a Felhasználók bővítményt.',
'author' => 'Szabó Gergő'
],
'personal' => [
'tab' => 'Személyes',
'gender' => 'Neme',
'telephone' => 'Telefonszám',
'job' => 'Foglalkozás',
'company' => 'Munkahely',
'about' => 'Rólam'
],
'internet' => [
'tab' => 'Internet',
'webpage' => 'Weboldal',
'blog' => 'Blog',
'facebook' => 'Facebook',
'twitter' => 'Twitter',
'skype' => 'Skype',
'icq' => 'ICQ'
],
'gender' => [
'unknown' => 'ismeretlen',
'female' => 'nő',
'male' => 'férfi'
],
'comment' => 'Megjegyzés',
'widget' => [
'title' => 'Felhasználói statisztika',
'show_total' => 'Összes mutatása',
'show_active' => 'Aktívak mutatása',
'show_inactive' => 'Inaktívak mutatása',
'show_deleted' => 'Töröltek mutatása',
'show_guest' => 'Vendégek mutatása',
'show_superuser' => 'Adminok mutatása',
'total' => 'Összes',
'active' => 'Aktív',
'inactive' => 'Inaktív',
'deleted' => 'Törölt',
'guest' => 'Vendég',
'superuser' => 'Admin',
'permission' => 'Widget kezelése a Vezérlőpulton'
]
];

View File

@ -0,0 +1,93 @@
<?php namespace Indikator\User\ReportWidgets;
use Backend\Classes\ReportWidgetBase;
use Exception;
use Schema;
use Db;
class Users extends ReportWidgetBase
{
public function render()
{
try {
$this->loadData();
}
catch (Exception $ex) {
$this->vars['error'] = $ex->getMessage();
}
return $this->makePartial('widget');
}
public function defineProperties()
{
return [
'title' => [
'title' => 'backend::lang.dashboard.widget_title_label',
'default' => 'indikator.user::lang.widget.title',
'type' => 'string',
'validationPattern' => '^.+$',
'validationMessage' => 'backend::lang.dashboard.widget_title_error'
],
'total' => [
'title' => 'indikator.user::lang.widget.show_total',
'default' => true,
'type' => 'checkbox'
],
'active' => [
'title' => 'indikator.user::lang.widget.show_active',
'default' => true,
'type' => 'checkbox'
],
'inactive' => [
'title' => 'indikator.user::lang.widget.show_inactive',
'default' => true,
'type' => 'checkbox'
],
'deleted' => [
'title' => 'indikator.user::lang.widget.show_deleted',
'default' => true,
'type' => 'checkbox'
],
'guest' => [
'title' => 'indikator.user::lang.widget.show_guest',
'default' => true,
'type' => 'checkbox'
],
'superuser' => [
'title' => 'indikator.user::lang.widget.show_superuser',
'default' => true,
'type' => 'checkbox'
]
];
}
protected function loadData()
{
$this->vars['active'] = Db::table('users')->where('is_activated', 1)->count();
$this->vars['inactive'] = Db::table('users')->where('is_activated', 0)->count();
if (Schema::hasColumn('users', 'deleted_at')) {
$this->vars['deleted'] = Db::table('users')->where('deleted_at', '>', 0)->count();
}
else {
$this->vars['deleted'] = 0;
}
if (Schema::hasColumn('users', 'is_guest')) {
$this->vars['guest'] = Db::table('users')->where('is_guest', 1)->count();
}
else {
$this->vars['guest'] = 0;
}
if (Schema::hasColumn('users', 'is_superuser')) {
$this->vars['superuser'] = Db::table('users')->where('is_superuser', 1)->count();
}
else {
$this->vars['superuser'] = 0;
}
$this->vars['total'] = $this->vars['active'] + $this->vars['inactive'];
}
}

View File

@ -0,0 +1,49 @@
<div class="report-widget">
<h3><?= e(trans($this->property('title'))) ?></h3>
<?php if (!isset($error)): ?>
<div class="control-status-list">
<ul>
<?php if ($this->property('total')): ?>
<li>
<span class="status-text"><?= e(trans('indikator.user::lang.widget.total')) ?></span>
<span class="status-label primary"><?= $total ?></span>
</li>
<?php endif ?>
<?php if ($this->property('active')): ?>
<li>
<span class="status-text"><?= e(trans('indikator.user::lang.widget.active')) ?></span>
<span class="status-label primary"><?= $active ?></span>
</li>
<?php endif ?>
<?php if ($this->property('inactive')): ?>
<li>
<span class="status-text"><?= e(trans('indikator.user::lang.widget.inactive')) ?></span>
<span class="status-label primary"><?= $inactive ?></span>
</li>
<?php endif ?>
<?php if ($this->property('deleted')): ?>
<li>
<span class="status-text"><?= e(trans('indikator.user::lang.widget.deleted')) ?></span>
<span class="status-label primary"><?= $deleted ?></span>
</li>
<?php endif ?>
<?php if ($this->property('guest')): ?>
<li>
<span class="status-text"><?= e(trans('indikator.user::lang.widget.guest')) ?></span>
<span class="status-label primary"><?= $guest ?></span>
</li>
<?php endif ?>
<?php if ($this->property('superuser')): ?>
<li>
<span class="status-text"><?= e(trans('indikator.user::lang.widget.superuser')) ?></span>
<span class="status-label primary"><?= $superuser ?></span>
</li>
<?php endif ?>
</ul>
</div>
<?php else: ?>
<p class="flash-message static warning"><?= e($error) ?></p>
<?php endif ?>
</div>

View File

@ -0,0 +1,24 @@
<?php namespace Indikator\User\Updates;
use October\Rain\Database\Updates\Migration;
use Schema;
class AddNewFieldsToUsersTable extends Migration
{
public function up()
{
Schema::table('users', function($table)
{
$table->string('iu_telephone', 100)->nullable();
$table->string('iu_company', 100)->nullable();
});
}
public function down()
{
Schema::table('users', function($table)
{
$table->dropColumn(['iu_telephone', 'iu_company']);
});
}
}

View File

@ -0,0 +1,37 @@
<?php namespace Indikator\User\Updates;
use October\Rain\Database\Updates\Migration;
use Schema;
class AddProfileFieldsToUsersTable extends Migration
{
public function up()
{
Schema::table('users', function($table)
{
$table->string('iu_first_name', 100)->nullable();
$table->string('iu_last_name', 100)->nullable();
$table->string('iu_gender', 7)->nullable();
$table->string('iu_job', 100)->nullable();
$table->string('iu_about')->nullable();
$table->string('iu_webpage', 200)->nullable();
$table->string('iu_blog', 200)->nullable();
$table->string('iu_facebook', 100)->nullable();
$table->string('iu_twitter', 100)->nullable();
$table->string('iu_skype', 50)->nullable();
$table->string('iu_icq', 8)->nullable();
$table->string('iu_comment')->nullable();
});
}
public function down()
{
Schema::table('users', function($table)
{
$table->dropColumn([
'iu_first_name', 'iu_last_name', 'iu_gender', 'iu_job', 'iu_about', 'iu_webpage', 'iu_blog',
'iu_facebook', 'iu_twitter', 'iu_skype', 'iu_icq', 'iu_comment'
]);
});
}
}

View File

@ -0,0 +1,24 @@
<?php namespace Indikator\User\Updates;
use October\Rain\Database\Updates\Migration;
use Schema;
class RemoveFirstAndLastNames extends Migration
{
public function up()
{
Schema::table('users', function($table)
{
$table->dropColumn(['iu_first_name', 'iu_last_name']);
});
}
public function down()
{
Schema::table('users', function($table)
{
$table->string('iu_first_name', 100)->nullable();
$table->string('iu_last_name', 100)->nullable();
});
}
}

View File

@ -0,0 +1,23 @@
1.0.0: First version of User Plus.
1.0.1:
- Added profile fields to users table.
- add_profile_fields_to_users_table.php
1.0.2: Added German language.
1.0.3: Minor improvements and bugfix.
1.0.4:
- Remove the first and the last name.
- remove_first_and_last_names.php
1.0.5: Added French language.
1.0.6: Fixed the uninstall error.
1.0.7: Added the plugin icon.
1.0.8: Added the dashboard widget.
1.1.0:
- Added new Telephone and Company fields.
- add_new_fields_to_users_table.php
1.1.1: Added Czech language.
1.1.2: Fixed the uninstall and update issue.
1.1.3: Improved the dashboard widget.
1.1.4: Changed the plugin description.
1.1.5: Redesigned the report widget.
1.1.6: Fixed the column check issue.
1.1.7: Added permission to Dashboard widgets.

View File

@ -0,0 +1,28 @@
---
plugins:
duplication:
enabled: true
config:
languages:
php:
mass_threshold: 45
fixme:
enabled: true
phpmd:
enabled: true
config:
file_extensions: "php"
rulesets: "controversial,design,unusedcode,PHPMD_custom.xml"
phpcodesniffer:
enabled: true
config:
standard: "Symfony2"
sonar-php:
enabled: true
ratings:
paths:
- "**.php"
exclude_patterns:
- 'tests/'
- 'lang/'
- 'updates/'

View File

@ -0,0 +1,27 @@
# Defining consistent coding styles between different editors and IDEs
# Support info @ http://editorconfig.org/#download
# editorconfig.org
# Top-most EditorConfig file
root = true
# General settings
[*]
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
# CSS settings
[*.css]
indent_size = 2
# YAML settings
[*.yml]
indent_size = 2
# Markdown settings
[*.md]
trim_trailing_whitespace = false

View File

@ -0,0 +1,3 @@
# These are supported funding model platforms
open_collective: oc-shopaholic

92
plugins/lovata/shopaholic/.gitignore vendored Normal file
View File

@ -0,0 +1,92 @@
/node_modules
Homestead.yaml
/_ide_helper.php
build.sh
#site
pdf/
_backup/
cgi-bin/
*.log
*.bin
*.komodoproject
/.komodotools/
# PhpStorm
.idea
# Eclipse
*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
.externalToolBuilders/
*.launch
.cproject
.buildpath
# SublimeText
/*.sublime-project
*.sublime-workspace
# NetBeans
nbproject/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
# Windows system files
$RECYCLE.BIN/
Thumbs.db
ehthumbs.db
Desktop.ini
# OSX system files
.DS_store
.AppleDouble
.LSOverride
Icon
._*
.Spotlight-V100
.Trashes
# SVN/CVS
.svn
/CVS/*
*/CVS/*
.cvsignore
*/.cvsignore
# temporary files/folders
tmp*
~*
*.~*
*.bak
*.swp
build/
png/
psd/
doc/
svg/
vendors/
pixelPerfect/
node_modules/
docs/
_ide_helper.php

View File

@ -0,0 +1,60 @@
# Contributing
When contributing to this repository, please first discuss the change you wish to make via issue with the owners of this repository before making a change.
Please note we have a code of conduct, please follow it in all your interactions with the project.
## Pull Request Process
1. Ensure any install or build dependencies are removed before the end of the layer when doing a build.
2. Cover your code contribution with unit tests and ensure your Pull Request passes all the tests.
3. Open a Pull Request to a `develop` branch.
4. Add to the Pull Request details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters.
5. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you.
## Code of Conduct
### Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
### Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language.
* Being respectful of differing viewpoints and experiences.
* Gracefully accepting constructive criticism.
* Focusing on what is best for the community.
* Showing empathy towards other community members.
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances.
* Trolling, insulting/derogatory comments, and personal or political attacks.
* Public or private harassment.
* Publishing others' private information, such as a physical or electronic address, without explicit permission.
* Other conduct which could reasonably be considered inappropriate in a professional setting.
### Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
### Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
### Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [support@lovata.com](mailto:support@lovata.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
### Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -0,0 +1,91 @@
<?xml version="1.0"?>
<ruleset name="PHPMD rule set for project" xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>Custom rules for checking project LOVATA Group</description>
<!--Code size rule set-->
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
<properties>
<property name="reportLevel" value="10" />
<property name="showClassesComplexity" value="true" />
<property name="showMethodsComplexity" value="true" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/NPathComplexity">
<properties>
<property name="minimum" value="200" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
<properties>
<property name="minimum" value="100" />
<property name="ignore-whitespace" value="true" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveClassLength">
<properties>
<property name="minimum" value="1000" />
<property name="ignore-whitespace" value="true" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList">
<properties>
<property name="minimum" value="8" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessivePublicCount">
<properties>
<property name="minimum" value="45" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/TooManyFields">
<properties>
<property name="maxfields" value="20" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/TooManyMethods">
<properties>
<property name="maxmethods" value="25" />
<property name="ignorepattern" value="(^(set|get))i" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/TooManyPublicMethods">
<properties>
<property name="maxmethods" value="10" />
<property name="ignorepattern" value="(^(set|get))i" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
<properties>
<property name="maximum" value="50" />
</properties>
</rule>
<!--Naming rules-->
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="minimum" value="4" />
</properties>
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="maximum" value="25" />
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName">
<properties>
<property name="minimum" value="3" />
<property name="exceptions" value="up" />
</properties>
</rule>
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass">
</rule>
<rule ref="rulesets/naming.xml/ConstantNamingConventions">
</rule>
<rule ref="rulesets/naming.xml/BooleanGetMethodName">
<properties>
<property name="checkParameterizedMethods" value="false" />
</properties>
</rule>
</ruleset>

View File

@ -0,0 +1,207 @@
<?php namespace Lovata\Shopaholic;
use Event;
use Backend;
use System\Classes\PluginBase;
//Console command
use Lovata\Shopaholic\Classes\Console\CheckTableIntegrity;
use Lovata\Shopaholic\Classes\Console\ImportFromXML;
use Lovata\Shopaholic\Classes\Console\PreconfigureImportSettingsFromXML;
//Event list
use Lovata\Shopaholic\Classes\Event\ExtendMenuHandler;
//Brand events
use Lovata\Shopaholic\Classes\Event\Brand\BrandModelHandler;
//Category events
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
use Lovata\Shopaholic\Classes\Event\Product\ProductModelHandler;
use Lovata\Shopaholic\Classes\Event\Product\ProductRelationHandler;
//Promo block events
use Lovata\Shopaholic\Classes\Event\PromoBlock\PromoBlockModelHandler;
use Lovata\Shopaholic\Classes\Event\PromoBlock\PromoBlockRelationHandler;
//Tax events
use Lovata\Shopaholic\Classes\Event\Tax\TaxModelHandler;
use Lovata\Shopaholic\Classes\Event\Tax\TaxRelationHandler;
use Lovata\Shopaholic\Classes\Event\Tax\ExtendTaxFieldsHandler;
/**
* Class Plugin
* @package Lovata\Shopaholic
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class Plugin extends PluginBase
{
/** @var array Plugin dependencies */
public $require = ['Lovata.Toolbox'];
/**
* Register artisan command
*/
public function register()
{
$this->registerConsoleCommand('shopaholic:check.table.integrity', CheckTableIntegrity::class);
$this->registerConsoleCommand('shopaholic:import_from_xml', ImportFromXML::class);
$this->registerConsoleCommand('shopaholic:preconfigure_import_from_xml', PreconfigureImportSettingsFromXML::class);
}
/**
* @return array
*/
public function registerComponents()
{
return [
'Lovata\Shopaholic\Components\CategoryList' => 'CategoryList',
'Lovata\Shopaholic\Components\CategoryPage' => 'CategoryPage',
'Lovata\Shopaholic\Components\CategoryData' => 'CategoryData',
'Lovata\Shopaholic\Components\Breadcrumbs' => 'CatalogBreadcrumbs',
'Lovata\Shopaholic\Components\CurrencyList' => 'CurrencyList',
'Lovata\Shopaholic\Components\ProductData' => 'ProductData',
'Lovata\Shopaholic\Components\ProductPage' => 'ProductPage',
'Lovata\Shopaholic\Components\ProductList' => 'ProductList',
'Lovata\Shopaholic\Components\BrandData' => 'BrandData',
'Lovata\Shopaholic\Components\BrandPage' => 'BrandPage',
'Lovata\Shopaholic\Components\BrandList' => 'BrandList',
'Lovata\Shopaholic\Components\PromoBlockData' => 'PromoBlockData',
'Lovata\Shopaholic\Components\PromoBlockPage' => 'PromoBlockPage',
'Lovata\Shopaholic\Components\PromoBlockList' => 'PromoBlockList',
];
}
/**
* @return array
*/
public function registerSettings()
{
return [
'shopaholic-menu-main-settings' => [
'label' => 'lovata.shopaholic::lang.menu.main_settings',
'description' => 'lovata.shopaholic::lang.menu.main_settings_description',
'category' => 'lovata.shopaholic::lang.tab.settings',
'icon' => 'oc-icon-book',
'class' => 'Lovata\Shopaholic\Models\Settings',
'order' => 100,
'permissions' => [
'shopaholic-settings',
],
],
'shopaholic-menu-currency' => [
'label' => 'lovata.shopaholic::lang.menu.currency',
'description' => 'lovata.shopaholic::lang.menu.currency_description',
'category' => 'lovata.shopaholic::lang.tab.settings',
'icon' => 'oc-icon-usd',
'url' => Backend::url('lovata/shopaholic/currencies'),
'order' => 1800,
'permissions' => [
'shopaholic-menu-currency',
],
],
'shopaholic-menu-tax' => [
'label' => 'lovata.shopaholic::lang.menu.tax',
'description' => 'lovata.shopaholic::lang.menu.tax_description',
'category' => 'lovata.shopaholic::lang.tab.settings',
'icon' => 'oc-icon-percent',
'url' => Backend::url('lovata/shopaholic/taxes'),
'order' => 1900,
'permissions' => [
'shopaholic-menu-tax',
],
],
'shopaholic-menu-price-types' => [
'label' => 'lovata.shopaholic::lang.menu.price_type',
'description' => 'lovata.shopaholic::lang.menu.price_type_description',
'category' => 'lovata.shopaholic::lang.tab.settings',
'icon' => 'oc-icon-money',
'url' => Backend::url('lovata/shopaholic/pricetypes'),
'order' => 2000,
'permissions' => [
'shopaholic-menu-price-type',
],
],
'shopaholic-menu-import-xml-file' => [
'label' => 'lovata.shopaholic::lang.menu.import_xml_file',
'description' => 'lovata.shopaholic::lang.menu.import_xml_file_description',
'category' => 'lovata.shopaholic::lang.tab.settings',
'icon' => 'oc-icon-download',
'class' => 'Lovata\Shopaholic\Models\XmlImportSettings',
'order' => 8000,
'permissions' => [
'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,
],
];
}
/**
* Plugin boot method
*/
public function boot()
{
$this->addEventListener();
}
/**
* Add event listeners
*/
protected function addEventListener()
{
Event::subscribe(ExtendMenuHandler::class);
//Brand events
Event::subscribe(BrandModelHandler::class);
//Category events
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
Event::subscribe(ProductModelHandler::class);
Event::subscribe(ProductRelationHandler::class);
//Promo block events
Event::subscribe(PromoBlockModelHandler::class);
Event::subscribe(PromoBlockRelationHandler::class);
//Tax events
Event::subscribe(TaxModelHandler::class);
Event::subscribe(TaxRelationHandler::class);
Event::subscribe(ExtendTaxFieldsHandler::class);
}
/**
* @return array
*/
public function registerReportWidgets()
{
return [
'Lovata\Shopaholic\Widgets\ImportFromXML' => [
'label' => 'lovata.shopaholic::lang.widget.import_from_xml_files',
],
'Lovata\Shopaholic\Widgets\ImportFromCSV' => [
'label' => 'lovata.shopaholic::lang.widget.import_from_csv_files',
]
];
}
}

View File

@ -0,0 +1,128 @@
# Shopaholic
[![Build Status](https://travis-ci.org/oc-shopaholic/oc-shopaholic-plugin.svg?branch=master)](https://travis-ci.org/oc-shopaholic/oc-shopaholic-plugin)
[![Coverage Status](https://coveralls.io/repos/github/oc-shopaholic/oc-shopaholic-plugin/badge.svg?branch=master)](https://coveralls.io/github/oc-shopaholic/oc-shopaholic-plugin?branch=master)
[![Maintainability](https://api.codeclimate.com/v1/badges/3d1cb11b6df3e444422f/maintainability)](https://codeclimate.com/github/oc-shopaholic/oc-shopaholic-plugin/maintainability)
[![Crowdin](https://d322cqt584bo4o.cloudfront.net/shopaholic-plugin-for-october/localized.svg)](https://crowdin.com/project/shopaholic-plugin-for-october)
[![Financial contributors](https://opencollective.com/oc-shopaholic/tiers/badge.svg)](https://opencollective.com/oc-shopaholic)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
E-Commerce plugin by [LOVATA](https://lovata.com) for October CMS.
![Shopaholic Banner](assets/images/shopaholic-banner.png)
## Overview
Shopaholic is a scalable and highly flexible e-commerce ecosystem for [October CMS](https://octobercms.com). The core plugin is provided free of charge and includes the following set of features:
* Products and trade offers management.
* Product image gallery management.
* Products grouping by categories and brands.
* Multi-currency, taxes and price types management.
* Data import (product, offers, categories, brands) from a CSV file.
* Basic products filtering (by category, brand etc.) and sorting (by price, new additions etc.)
With the help of Shopaholics standard functions, combining them together its also possible to solve many other non-trivial tasks, such as displaying blocks of random products, displaying the cheapest and most expensive products, etc.
In order to cater to the growing scalability demands of a project, the ecosystem provides [extra plugins](https://octobercms.com/plugin/lovata-shopaholic#extensions) to extend the basic functionality. With these plugins sellers can:
* Manage multi-language content (via [RainLab.Translate](https://octobercms.com/plugin/rainlab-translate)).
* Sell online (via [Lovata.PayPalShopaholic](https://octobercms.com/plugin/lovata-paypalshopaholic)).
* Extend online payment options by adding additional payment providers (via [Lovata.OmnipayShopaholic](https://octobercms.com/plugin/lovata-omnipayshopaholic)).
* Create custom products filters by any essence (e.g. by _New additions_, _Discounts_, _In stock_ etc.) (via [Lovata.FilterShopaholic](https://octobercms.com/plugin/lovata-filtershopaholic)).
* Add custom properties to a product (via [Lovata.PropertiesShopaholic](https://octobercms.com/plugin/lovata-propertiesshopaholic)).
* Bind similar products to a certain one (via [Lovata.RelatedProductsShopaholic](https://octobercms.com/plugin/lovata-relatedproductsshopaholic)).
* Manage promo activities (via [Lovata.CouponsShopaholic](https://octobercms.com/plugin/lovata-couponsshopaholic), [Lovata.DiscountsShopaholic](https://octobercms.com/plugin/lovata-discountsshopaholic) and [Lovata.CampaignsShopaholic](https://octobercms.com/plugin/lovata-campaignsshopaholic)).
* Group products for SEO reasons (via [Lovata.TagsShopaholic](https://octobercms.com/plugin/lovata-tagsshopaholic)).
* Manage complex SEO issues (via [Lovata.MightySeo](https://octobercms.com/plugin/lovata-mightyseo)).
* Increase the revenue by assigning accessories to the products (via [Lovata.AccessoriesShopaholic](https://octobercms.com/plugin/lovata-accessoriesshopaholic)).
* Manage customers (via [Lovata.Buddies](https://octobercms.com/plugin/lovata-buddies) or [RainLab.User](https://octobercms.com/plugin/rainlab-user)).
Besides you can provide a better UX for the customer with the ability to:
* See the popular products ( via [Lovata.PopularityShopaholic](https://octobercms.com/plugin/lovata-popularityshopaholic)).
* Search for the products (via [Lovata.SearchShopaholic](https://octobercms.com/plugin/lovata-searchshopaholic) or [Lovata.SphinxShopaholic](https://octobercms.com/plugin/lovata-sphinxshopaholic)).
* Compare the products (via [Lovata.CompareShopaholic](https://octobercms.com/plugin/lovata-compareshopaholic)).
* Find the products they viewed before (via [Lovata.ViewedProductsShopaholic](https://octobercms.com/plugin/lovata-viewedproductsshopaholic)).
* Leave and read the reviews for the products (via [Lovata.ReviewsShopaholic](https://octobercms.com/plugin/lovata-reviewsshopaholic)).
* Postpone the products for the future purchases (via [Lovata.WishListShopaholic](https://octobercms.com/plugin/lovata-wishlistshopaholic)).
> Please note, the architecture of the plugins allows [extending](https://octobercms.com/docs/plugin/extending) the existing methods, fields and other data without interfering with original source code!
The development of Shopaholics ecosystem is guided by the similar philosophies of October CMS and Unix like operating systems, where the main focus is to create simple microarchitecture solutions that communicate with each other through smart APIs.
One one hand, this approach allows keeping performance, security, and functionality of the code to a high standard. On the other hand, it provides a clean and smooth back-end UI/UX that isn't over-bloated with the features.
## Live demo
Visit our [demo](http://demo.shopaholic.one/) website. Sign in to [backend](http://demo.shopaholic.one/backend) using the following credentials:
* user: manager
* password: manager
You can run the demo site locally. To do so, you need to clone the [oc-shopaholic-demo-theme](https://github.com/lovata/oc-shopaholic-demo-theme) repository and follow the steps from the _Installation guide_ in the Readme file. As a result, you will receive a copy of the demo site with a full database. Having a ready-made demo site example, you can easily learn how to operate the plugins.
## Installation
Regardless of the installation type you choose, you must install [Toolbox plugin](https://octobercms.com/plugin/lovata-toolbox), which is a required dependency for Shopaholic.
### Artisan
Using the Laravels CLI is the fastest way to get started. Just run the following commands in a projects root directory:
```bash
php artisan plugin:install lovata.toolbox
php artisan plugin:install lovata.shopaholic
```
### Composer
If you prefer Composer run following commands in a projects root directory:
```
composer require lovata/oc-toolbox-plugin
composer require lovata/oc-shopaholic-plugin
php artisan october:up
```
> It's not recommended way because of possible collisions with the updating of the plugins.
Once the plugins are installed take a look at the official documentation for the possible next steps.
## Documentation
The complete official documentation of the ecosystem can be found [here](https://github.com/lovata/oc-shopaholic-plugin/wiki).
## Performance
As an environment for a testing measurements was used simple Digital Ocean droplet with this configuration:
* Dual Core CPU
* 4 Gb RAM
* Ubuntu 18.04
* PHP 7.2.0
* Apache 2.4
* MySQL 5.7
| Products number | Catalog page load time | Product list filtering time |
| ------------------: | ---------------------: | --------------------------: |
| 210 | 100-150 ms | 80-100 ms |
| 21 000 | 900-1100 ms | 500-600 ms |
If you would like to know how our plugins perform with large catalogs of products, you can visit our [Large Catalog Demo](http://big-demo.shopaholic.one) website that has 21 000 products, 68 000 offers and 210 000 variations of property values.
## Quality standards
We ensure the high quality of our plugins and provide you with full support. All of our plugins have extensive documentation. The quality of our plugins goes through rigorous testing, we have launched automated testing for all of our plugins. Our code conforms with the best writing and structuring practices. All this guarantees the stable work of our plugins after they are updated with new functionality and ensures their smooth integration.
## Get involved
If you're interested in the improvement of this project you can help in the following ways:
* bug reporting and new feature requesting by creating issues on plugin [GitHub page](https://github.com/lovata/oc-shopaholic-plugin/issues);
* contribution to a project following these [instructions](https://github.com/lovata/oc-shopaholic-plugin/blob/master/CONTRIBUTING.md);
* localization to your language using [Crowdin](https://crowdin.com/project/shopaholic-plugin-for-october) service.
Let us know if you have any other questions, ideas or suggestions! Just drop a line at shopaholic@lovata.com.
## License
© 2019, [LOVATA Group, LLC](https://github.com/lovata) under [GNU GPL v3](https://opensource.org/licenses/GPL-3.0).
Developed by [Andrey Kharanenka](https://github.com/kharanenka).

View File

@ -0,0 +1,11 @@
<svg width="256" height="256" viewBox="0 0 256 256" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M205.546 84.2591C205.529 87.651 204.677 90.9865 203.067 93.9719C207.384 95.526 211.092 98.418 213.65 102.226C216.209 106.035 217.484 110.561 217.291 115.145C217.448 119.241 216.478 123.303 214.486 126.886C212.494 130.469 209.556 133.436 205.993 135.464V148.957C205.982 155.118 203.53 161.025 199.173 165.382C194.816 169.739 188.909 172.191 182.748 172.202H180.147V217.881C180.147 241.045 163.403 256 136.5 256C109.597 256 92.8945 241.411 92.8945 217.881L147.695 9.07385C156.034 9.95324 163.751 13.8927 169.355 20.1307C174.958 26.3688 178.05 34.4626 178.033 42.8479C178.013 43.9623 177.931 45.0747 177.79 46.1803C189.778 58.1688 205.546 75.5624 205.546 84.2591Z" fill="#2676F7"/>
<path d="M196.224 106.421C196.224 97.6833 190.575 90.5714 183.585 90.5714C181.981 90.6129 180.404 90.9969 178.96 91.6978C177.516 92.3987 176.239 93.4003 175.214 94.6353C173.44 93.8409 171.543 93.3597 169.605 93.213C179.44 91.9125 184.561 80.1272 184.276 75.5756C184.276 68.3012 163.306 46.7625 156.194 39.6913C156.571 37.873 156.761 36.0212 156.763 34.1643C156.827 30.514 156.172 26.8867 154.834 23.4897C153.496 20.0927 151.503 16.9924 148.967 14.366C146.431 11.7395 143.402 9.63819 140.054 8.18208C136.706 6.72598 133.104 5.94357 129.454 5.87953C122.082 5.75019 114.96 8.55477 109.656 13.6763C104.351 18.7978 101.298 25.8167 101.169 33.189H78.3706V33.5141C73.9139 33.4918 69.627 35.2217 66.4341 38.331C63.2412 41.4403 61.3981 45.6798 61.3022 50.1355V75.3724C61.3451 79.8636 63.1649 84.1549 66.3635 87.3079C69.5622 90.4608 73.8793 92.2187 78.3706 92.197H106.818C110.932 92.2257 114.915 90.7572 118.026 88.0653C121.136 85.3734 123.162 81.642 123.724 77.5669C123.752 81.2804 125.107 84.8616 127.544 87.6637C129.981 90.4659 133.339 92.3043 137.013 92.8472H73.9409C71.0119 92.8585 68.1379 93.6436 65.6099 95.123C64.5751 93.7519 63.2453 92.631 61.7188 91.8432C60.1923 91.0553 58.5083 90.6207 56.7912 90.5714C49.8013 90.5714 44.1525 97.6833 44.1525 106.421C44.1525 115.158 49.8013 122.27 56.7912 122.27V139.745C56.8232 144.283 58.6402 148.627 61.8495 151.836C65.0588 155.045 69.4024 156.863 73.9409 156.894V157.22H83.9788V208.994C83.9788 231.345 100.478 241.058 121.489 241.058C142.499 241.058 159.039 231.02 159.039 208.994V157.22H167.777C172.315 157.188 176.659 155.371 179.868 152.161C183.077 148.952 184.894 144.608 184.926 140.07V122.107C191.266 121.295 196.224 114.63 196.224 106.421ZM123.764 74.6815V61.2706C125.465 61.5977 127.194 61.761 128.926 61.7583C129.86 61.7583 130.754 61.7583 131.689 61.7583C128.349 65.5964 125.67 69.9639 123.764 74.6815Z" fill="white"/>
<path d="M74.3066 59.8892C73.7677 59.8892 73.2509 59.6751 72.8698 59.294C72.4887 58.913 72.2747 58.3961 72.2747 57.8572V53.3056C72.2851 52.77 72.5025 52.2592 72.8813 51.8803C73.2601 51.5015 73.771 51.2841 74.3066 51.2737C74.8455 51.2737 75.3624 51.4878 75.7434 51.8688C76.1245 52.2499 76.3386 52.7667 76.3386 53.3056V57.8572C76.3386 58.3961 76.1245 58.913 75.7434 59.294C75.3624 59.6751 74.8455 59.8892 74.3066 59.8892Z" fill="#3B3B3B"/>
<path d="M74.3065 66.6349V70.1705C74.3065 77.323 75.607 79.2737 83.4097 79.2737H88.5708" fill="white"/>
<path d="M88.4085 81.3057H83.2473C74.6318 81.3057 72.1122 78.8267 72.1122 70.1705V66.6349C72.1327 66.3678 72.2058 66.1073 72.3274 65.8686C72.449 65.6298 72.6166 65.4174 72.8205 65.2437C73.0245 65.0699 73.2608 64.9382 73.5159 64.8562C73.7709 64.7741 74.0397 64.7433 74.3067 64.7655C74.8456 64.7655 75.3624 64.9796 75.7435 65.3607C76.1246 65.7418 76.3387 66.2586 76.3387 66.7975V70.3331C76.3387 76.429 76.8263 77.4043 83.4099 77.4043H88.571C89.1099 77.4043 89.6268 77.6184 90.0078 77.9995C90.3889 78.3805 90.603 78.8974 90.603 79.4363C90.603 79.9752 90.3889 80.492 90.0078 80.8731C89.6268 81.2541 89.1099 81.4682 88.571 81.4682L88.4085 81.3057Z" fill="#3B3B3B"/>
<path d="M139.614 76.9573C139.157 76.9456 138.716 76.7891 138.354 76.5102C137.935 76.175 137.666 75.6878 137.605 75.1549C137.544 74.6219 137.696 74.0866 138.029 73.6655L150.952 57.166C151.117 56.9552 151.323 56.7791 151.556 56.6476C151.79 56.5162 152.047 56.432 152.313 56.3999C152.579 56.3678 152.849 56.3885 153.107 56.4607C153.365 56.5328 153.606 56.6551 153.817 56.8206C154.028 56.986 154.204 57.1914 154.335 57.4249C154.467 57.6584 154.551 57.9155 154.583 58.1816C154.615 58.4476 154.595 58.7174 154.522 58.9754C154.45 59.2335 154.328 59.4748 154.162 59.6856L141.199 76.1851C141.011 76.4268 140.771 76.6222 140.496 76.7561C140.221 76.89 139.919 76.9589 139.614 76.9573Z" fill="#3B3B3B"/>
<path d="M188.096 85.085C189.706 82.0996 190.558 78.7641 190.575 75.3723C190.575 66.6755 174.807 49.282 162.819 37.2934C162.96 36.1879 163.042 35.0754 163.063 33.961C163.079 25.5757 159.987 17.4819 154.384 11.2439C148.78 5.00579 141.063 1.06637 132.724 0.186978C124.385 -0.692412 116.016 1.55066 109.235 6.48268C102.453 11.4147 97.7406 18.6855 96.008 26.8898H78.3706C77.6037 26.893 76.8446 27.0448 76.1355 27.3368C70.4321 27.8518 65.1249 30.472 61.2481 34.6868C57.3714 38.9016 55.2031 44.4089 55.1657 50.1354V75.3723C55.1668 78.5191 55.817 81.6319 57.0757 84.5161H56.71C46.3876 84.5161 38.016 94.3914 38.016 106.461C37.8517 110.771 38.9584 115.033 41.1985 118.719C43.4385 122.404 46.7129 125.349 50.6141 127.187V139.785C50.6166 145.555 52.7645 151.117 56.6402 155.391C60.5158 159.664 65.8422 162.344 71.5839 162.909C72.306 163.205 73.0791 163.357 73.8597 163.356H77.9236V208.994C77.9236 232.524 94.6262 247.113 121.529 247.113C148.432 247.113 165.176 232.158 165.176 208.994V163.315H167.777C173.938 163.305 179.845 160.852 184.202 156.495C188.559 152.138 191.011 146.232 191.022 140.07V126.578C194.585 124.549 197.523 121.582 199.515 117.999C201.507 114.416 202.477 110.355 202.32 106.258C202.513 101.674 201.238 97.1481 198.679 93.3396C196.121 89.5311 192.413 86.6391 188.096 85.085ZM154.081 45.7463C165.948 57.7349 177.693 71.5116 178.465 75.738C177.986 78.8867 176.57 81.8182 174.401 84.1503C173.187 85.4483 171.641 86.3898 169.931 86.8731H168.183H137.257C135.23 86.4788 133.389 85.4302 132.017 83.8885C130.644 82.3469 129.815 80.3972 129.657 78.3389C129.637 78.1362 129.637 77.932 129.657 77.7293C129.537 77.1693 129.536 76.5902 129.655 76.0299C129.774 75.4696 130.01 74.9408 130.348 74.4782C137.016 63.9955 144.915 54.3495 153.878 45.7463H154.081ZM112.751 19.5748C116.654 20.7418 120.675 21.4643 124.74 21.7286C129.653 21.3805 134.531 20.6467 139.329 19.5341L135.794 25.1017C135.607 25.4077 135.505 25.7575 135.498 26.1157C135.49 26.4739 135.577 26.8277 135.751 27.1413C135.924 27.4549 136.177 27.7171 136.484 27.9013C136.792 28.0855 137.142 28.1852 137.501 28.1903C140.677 28.0032 143.818 27.416 146.847 26.4428C147.561 26.13 148.22 25.7046 148.798 25.183C149.8 27.4183 150.405 29.8111 150.586 32.2542C150.246 32.4471 149.92 32.6645 149.611 32.9044C142.653 39.6598 136.06 46.7818 129.86 54.2399V49.8103C129.815 44.015 127.591 38.4488 123.631 34.2175C119.671 29.9862 114.264 27.3994 108.484 26.9711C109.404 24.2478 110.854 21.7339 112.751 19.5748ZM67.398 50.1354C67.4408 47.2573 68.617 44.5122 70.6713 42.4959C72.7256 40.4797 75.4922 39.355 78.3706 39.366C79.0093 39.3843 79.645 39.2738 80.24 39.0409H106.818C109.71 39.0083 112.498 40.1234 114.57 42.142C116.642 44.1605 117.829 46.918 117.872 49.8103V74.1937C117.701 75.3916 117.619 76.6006 117.628 77.8106C117.017 80.2048 115.619 82.3241 113.659 83.8277C111.698 85.3314 109.289 86.132 106.818 86.101H78.3706C76.9403 86.1225 75.5198 85.862 74.1901 85.3345C72.8605 84.8069 71.6478 84.0226 70.6213 83.0263C69.5949 82.03 68.7747 80.8413 68.2077 79.528C67.6407 78.2147 67.338 76.8026 67.3168 75.3723L67.398 50.1354ZM56.7912 116.215C53.2963 116.215 50.2483 111.622 50.2483 106.421C50.2483 101.219 53.2963 96.6672 56.7912 96.6672C60.2862 96.6672 63.3341 101.341 63.3341 106.421C63.3341 111.5 60.2456 116.215 56.7912 116.215ZM117.465 234.799C105.721 233.987 90.034 229.151 90.034 208.994V163.315H117.465V234.799ZM152.943 208.994C152.943 229.313 136.119 233.987 125.553 234.799V163.315H152.943V208.994ZM178.83 139.907C178.842 142.861 177.687 145.7 175.617 147.808C173.548 149.915 170.73 151.121 167.777 151.164H75.8916C75.2632 150.951 74.6045 150.841 73.9409 150.839C71.0116 150.797 68.214 149.615 66.1424 147.543C64.0708 145.472 62.8885 142.674 62.8465 139.745V127.146C66.7586 125.318 70.0444 122.377 72.2926 118.69C74.5408 115.004 75.6514 110.735 75.4852 106.421C75.4734 103.869 75.0761 101.335 74.3067 98.9023H136.159C137.504 99.1158 138.862 99.2245 140.223 99.2274H165.948C165.242 101.56 164.886 103.984 164.891 106.421C164.681 110.964 165.912 115.458 168.408 119.26C170.904 123.063 174.537 125.979 178.79 127.594L178.83 139.907ZM183.626 116.052C180.131 116.052 177.083 111.46 177.083 106.258C177.083 101.056 180.131 96.5046 183.626 96.5046C187.121 96.5046 190.169 101.056 190.169 106.258C190.169 111.46 187.121 116.215 183.626 116.215V116.052Z" fill="#3B3B3B"/>
<path d="M132.502 140.314H79.1019C78.5663 140.324 78.0554 140.542 77.6766 140.921C77.2978 141.299 77.0804 141.81 77.0699 142.346C77.0699 142.885 77.284 143.402 77.6651 143.783C78.0462 144.164 78.563 144.378 79.1019 144.378H132.502C133.041 144.378 133.557 144.164 133.938 143.783C134.32 143.402 134.534 142.885 134.534 142.346C134.534 141.807 134.32 141.29 133.938 140.909C133.557 140.528 133.041 140.314 132.502 140.314Z" fill="#3B3B3B"/>
<path d="M160.665 140.314H139.939C139.403 140.324 138.892 140.542 138.513 140.921C138.134 141.299 137.917 141.81 137.907 142.346C137.907 142.885 138.121 143.402 138.502 143.783C138.883 144.164 139.4 144.378 139.939 144.378H160.665C161.203 144.378 161.72 144.164 162.101 143.783C162.482 143.402 162.696 142.885 162.696 142.346C162.686 141.81 162.469 141.299 162.09 140.921C161.711 140.542 161.2 140.324 160.665 140.314Z" fill="#3B3B3B"/>
</svg>

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 KiB

View File

@ -0,0 +1,88 @@
<?php namespace Lovata\Shopaholic\Classes\Collection;
use Lovata\Toolbox\Classes\Collection\ElementCollection;
use Lovata\Shopaholic\Classes\Item\BrandItem;
use Lovata\Shopaholic\Classes\Store\BrandListStore;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
/**
* Class BrandCollection
* @package Lovata\Shopaholic\Classes\Collection
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* Search for Shopaholic, Sphinx for Shopaholic
* @method $this search(string $sSearch)
*/
class BrandCollection extends ElementCollection
{
const ITEM_CLASS = BrandItem::class;
/**
* Apply sorting
* @return $this
*/
public function sort()
{
//Get sorting list
$arResultIDList = BrandListStore::instance()->sorting->get();
return $this->applySorting($arResultIDList);
}
/**
* Apply filter by active brand list
* @return $this
*/
public function active()
{
$arResultIDList = BrandListStore::instance()->active->get();
return $this->intersect($arResultIDList);
}
/**
* Filter brand list by category ID
* @param int|array $arCategoryIDList
* @param bool $bWithChildren
* @return $this
*/
public function category($arCategoryIDList, $bWithChildren = false)
{
if (!is_array($arCategoryIDList)) {
$arCategoryIDList = [$arCategoryIDList];
}
$arResultIDList = [];
foreach ($arCategoryIDList as $iCategoryID) {
$arResultIDList = array_merge($arResultIDList, (array) BrandListStore::instance()->category->get($iCategoryID));
if ($bWithChildren) {
$arResultIDList = array_merge($arResultIDList, (array) $this->getIDListChildrenCategory($iCategoryID));
}
}
return $this->intersect($arResultIDList);
}
/**
* Get brand ID list for children categories
* @param int $iCategoryID
* @return array
*/
protected function getIDListChildrenCategory($iCategoryID) : array
{
//Get category item
$obCategoryItem = CategoryItem::make($iCategoryID);
if ($obCategoryItem->isEmpty() || $obCategoryItem->children->isEmpty()) {
return [];
}
$arResultIDList = [];
foreach ($obCategoryItem->children as $obChildCategoryItem) {
$arResultIDList = array_merge($arResultIDList, (array) BrandListStore::instance()->category->get($obChildCategoryItem->id));
$arResultIDList = array_merge($arResultIDList, $this->getIDListChildrenCategory($obChildCategoryItem->id));
}
return $arResultIDList;
}
}

View File

@ -0,0 +1,41 @@
<?php namespace Lovata\Shopaholic\Classes\Collection;
use Lovata\Toolbox\Classes\Collection\ElementCollection;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
use Lovata\Shopaholic\Classes\Store\CategoryListStore;
/**
* Class CategoryCollection
* @package Lovata\Shopaholic\Classes\Collection
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* Search for Shopaholic, Sphinx for Shopaholic
* @method $this search(string $sSearch)
*/
class CategoryCollection extends ElementCollection
{
const ITEM_CLASS = CategoryItem::class;
/**
* Set to element ID list top level category ID list
* @return CategoryCollection
*/
public function tree()
{
$arResultIDList = CategoryListStore::instance()->top_level->get();
return $this->applySorting($arResultIDList);
}
/**
* Apply filter by active field
* @return $this
*/
public function active()
{
$arResultIDList = CategoryListStore::instance()->active->get();
return $this->intersect($arResultIDList);
}
}

View File

@ -0,0 +1,39 @@
<?php namespace Lovata\Shopaholic\Classes\Collection;
use Lovata\Toolbox\Classes\Collection\ElementCollection;
use Lovata\Shopaholic\Classes\Item\CurrencyItem;
use Lovata\Shopaholic\Classes\Store\CurrencyListStore;
/**
* Class CurrencyCollection
* @package Lovata\Shopaholic\Classes\Collection
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class CurrencyCollection extends ElementCollection
{
const ITEM_CLASS = CurrencyItem::class;
/**
* Apply sorting
* @return $this
*/
public function sort()
{
//Get sorting list
$arResultIDList = CurrencyListStore::instance()->sorting->get();
return $this->applySorting($arResultIDList);
}
/**
* Apply filter by active currency list
* @return $this
*/
public function active()
{
$arResultIDList = CurrencyListStore::instance()->active->get();
return $this->intersect($arResultIDList);
}
}

View File

@ -0,0 +1,67 @@
<?php namespace Lovata\Shopaholic\Classes\Collection;
use Lovata\Toolbox\Classes\Collection\ElementCollection;
use Lovata\Shopaholic\Classes\Item\OfferItem;
use Lovata\Shopaholic\Classes\Store\OfferListStore;
/**
* Class OfferCollection
* @package Lovata\Shopaholic\Classes\Collection
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* Filter for Shopaholic plugin
* @method $this filterByPrice(float $fStartPrice, float $fStopPrice)
* @method $this filterByDiscount()
* @method $this filterByQuantity()
* @method $this filterByProperty(array $arFilterList, \Lovata\FilterShopaholic\Classes\Collection\FilterPropertyCollection $obPropertyList)
*
* Subscriptions for Shopaholic
* @method $this sortByPeriod()
*/
class OfferCollection extends ElementCollection
{
const ITEM_CLASS = OfferItem::class;
/**
* Apply sorting
* @param string $sSorting
* @return $this
*/
public function sort($sSorting)
{
$arResultIDList = OfferListStore::instance()->sorting->get($sSorting);
return $this->applySorting($arResultIDList);
}
/**
* Apply filter by active field
* @see \Lovata\Shopaholic\Tests\Unit\Collection\OfferCollectionTest::testActiveList()
* @return $this
*/
public function active()
{
$arResultIDList = OfferListStore::instance()->active->get();
return $this->intersect($arResultIDList);
}
/**
* Get the total count of all order positions
* @return int
*/
public function getTotalQuantity()
{
$iQuantityCount = 0;
$arOfferList = $this->all();
/** @var \Lovata\Shopaholic\Classes\Item\OfferItem $arOfferItem */
foreach ($arOfferList as $arOfferItem) {
$iQuantityCount += $arOfferItem->quantity;
}
return $iQuantityCount;
}
}

View File

@ -0,0 +1,258 @@
<?php namespace Lovata\Shopaholic\Classes\Collection;
use Event;
use Lovata\Toolbox\Classes\Collection\ElementCollection;
use Lovata\Shopaholic\Models\PromoBlock;
use Lovata\Shopaholic\Classes\Item\OfferItem;
use Lovata\Shopaholic\Classes\Item\ProductItem;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
use Lovata\Shopaholic\Classes\Store\OfferListStore;
use Lovata\Shopaholic\Classes\Store\ProductListStore;
/**
* Class ProductCollection
* @package Lovata\Shopaholic\Classes\Collection
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* Filter for Shopaholic plugin
* @method $this filterByPrice(float $fStartPrice, float $fStopPrice)
* @method $this filterByBrandList(array $arBrandIDList)
* @method $this filterByDiscount()
* @method $this filterByQuantity()
* @method $this filterByProperty(array $arFilterList, \Lovata\FilterShopaholic\Classes\Collection\FilterPropertyCollection $obPropertyList, OfferCollection $obOfferList = null)
*
* Tags for Shopaholic plugin
* @method $this tag(int $iTagID)
*
* Discounts for Shopaholic plugin
* @method $this discount(int $iDiscountID)
*
* Coupons for Shopaholic plugin
* @method $this couponGroup(int $iCouponGroupID)
*
* Campaigns for Shopaholic plugin
* @method $this campaign(int $iCampaignID)
*
* Search for Shopaholic, Sphinx for Shopaholic
* @method $this search(string $sSearch)
*
* Compare for Shopaholic
* @method $this compare()
*
* Wish list for Shopaholic
* @method $this wishList()
*
* Viewed products for Shopaholic
* @method $this viewed()
*
* Labels for Shopaholic
* @method $this label($iLabelID)
*/
class ProductCollection extends ElementCollection
{
const ITEM_CLASS = ProductItem::class;
/**
* Apply sorting
* @param string $sSorting
* @return $this
*/
public function sort($sSorting)
{
$arResultIDList = ProductListStore::instance()->sorting->get($sSorting);
return $this->applySorting($arResultIDList);
}
/**
* Apply filter by active field
* @return $this
*/
public function active()
{
$arResultIDList = ProductListStore::instance()->active->get();
return $this->intersect($arResultIDList);
}
/**
* Filter product list by category ID
* @param int|array $arCategoryIDList
* @param bool $bWithChildren
* @return $this
*/
public function category($arCategoryIDList, $bWithChildren = false)
{
if (!is_array($arCategoryIDList)) {
$arCategoryIDList = [$arCategoryIDList];
}
$arResultIDList = [];
foreach ($arCategoryIDList as $iCategoryID) {
$arResultIDList = array_merge($arResultIDList, (array) ProductListStore::instance()->category->get($iCategoryID));
if ($bWithChildren) {
$arResultIDList = array_merge($arResultIDList, (array) $this->getIDListChildrenCategory($iCategoryID));
}
}
return $this->intersect($arResultIDList);
}
/**
* Filter product list by brand ID
* @param int $iBrandID
* @return $this
*/
public function brand($iBrandID)
{
$arResultIDList = ProductListStore::instance()->brand->get($iBrandID);
return $this->intersect($arResultIDList);
}
/**
* Filter product list by promo block ID + different extensions
* @param int $iPromoBlockID
* @return $this
*/
public function promo($iPromoBlockID)
{
$arResultIDList = ProductListStore::instance()->promo_block->get($iPromoBlockID);
//Fire event, get additional product ID list
$arEventDataList = Event::fire(PromoBlock::EVENT_GET_PRODUCT_LIST, $iPromoBlockID);
if (empty($arEventDataList)) {
return $this->intersect($arResultIDList);
}
//Process event data
foreach ($arEventDataList as $arProductIDList) {
if (empty($arProductIDList) || !is_array($arProductIDList)) {
continue;
}
$arResultIDList = array_merge($arResultIDList, $arProductIDList);
}
$arResultIDList = array_unique($arResultIDList);
return $this->intersect($arResultIDList);
}
/**
* Filter product list by promo block ID
* @param int $iPromoBlockID
* @return $this
*/
public function promoBlock($iPromoBlockID)
{
$arResultIDList = ProductListStore::instance()->promo_block->get($iPromoBlockID);
return $this->intersect($arResultIDList);
}
/**
* Get offer with min price
* @param string $sPriceTypeCode
* @return OfferItem
*/
public function getOfferMinPrice($sPriceTypeCode = null)
{
$obProductList = clone $this;
$sSorting = ProductListStore::SORT_PRICE_ASC;
if (!empty($sPriceTypeCode)) {
$sSorting .= '|'.$sPriceTypeCode;
}
$obProductList->sort($sSorting);
//Get product with min price
/** @var \Lovata\Shopaholic\Classes\Item\ProductItem $obProductItem */
$obProductItem = $obProductList->first();
if ($obProductItem->isEmpty()) {
return OfferItem::make(null);
}
//Get offer with min price
$obOfferCollection = $obProductItem->offer;
if ($obOfferCollection->isEmpty()) {
return OfferItem::make(null);
}
$sSorting = OfferListStore::SORT_PRICE_ASC;
if (!empty($sPriceTypeCode)) {
$sSorting .= '|'.$sPriceTypeCode;
}
/** @var OfferItem $obOfferItem */
$obOfferItem = $obOfferCollection->sort($sSorting)->first();
return $obOfferItem;
}
/**
* Get offer with max price
* @param string $sPriceTypeCode
* @return OfferItem
*/
public function getOfferMaxPrice($sPriceTypeCode = null)
{
$obProductList = clone $this;
$sSorting = ProductListStore::SORT_PRICE_ASC;
if (!empty($sPriceTypeCode)) {
$sSorting .= '|'.$sPriceTypeCode;
}
$obProductList->sort($sSorting);
//Get product with min price
/** @var \Lovata\Shopaholic\Classes\Item\ProductItem $obProductItem */
$obProductItem = $obProductList->last();
if ($obProductItem->isEmpty()) {
return OfferItem::make(null);
}
//Get offer with min price
$obOfferCollection = $obProductItem->offer;
if ($obOfferCollection->isEmpty()) {
return OfferItem::make(null);
}
$sSorting = OfferListStore::SORT_PRICE_ASC;
if (!empty($sPriceTypeCode)) {
$sSorting .= '|'.$sPriceTypeCode;
}
/** @var OfferItem $obOfferItem */
$obOfferItem = $obOfferCollection->sort($sSorting)->last();
return $obOfferItem;
}
/**
* Get product ID list for children categories
* @param int $iCategoryID
* @return array
*/
protected function getIDListChildrenCategory($iCategoryID) : array
{
//Get category item
$obCategoryItem = CategoryItem::make($iCategoryID);
if ($obCategoryItem->isEmpty() || $obCategoryItem->children->isEmpty()) {
return [];
}
$arResultIDList = [];
foreach ($obCategoryItem->children as $obChildCategoryItem) {
$arResultIDList = array_merge($arResultIDList, (array) ProductListStore::instance()->category->get($obChildCategoryItem->id));
$arResultIDList = array_merge($arResultIDList, $this->getIDListChildrenCategory($obChildCategoryItem->id));
}
return $arResultIDList;
}
}

View File

@ -0,0 +1,62 @@
<?php namespace Lovata\Shopaholic\Classes\Collection;
use Lovata\Toolbox\Classes\Collection\ElementCollection;
use Lovata\Shopaholic\Classes\Item\PromoBlockItem;
use Lovata\Shopaholic\Classes\Store\PromoBlockListStore;
/**
* Class PromoBlockCollection
* @package Lovata\Shopaholic\Classes\Collection
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class PromoBlockCollection extends ElementCollection
{
const ITEM_CLASS = PromoBlockItem::class;
/**
* Apply sorting
* @param string $sSorting
* @return $this
*/
public function sort($sSorting)
{
//Get sorting list
$arResultIDList = PromoBlockListStore::instance()->sorting->get($sSorting);
return $this->applySorting($arResultIDList);
}
/**
* Apply filter by active field
* @return $this
*/
public function active()
{
$arResultIDList = PromoBlockListStore::instance()->active->get();
return $this->intersect($arResultIDList);
}
/**
* Apply filter by hidden field
* @return $this
*/
public function hidden()
{
$arResultIDList = PromoBlockListStore::instance()->hidden->get();
return $this->intersect($arResultIDList);
}
/**
* Apply filter by hidden field
* @return $this
*/
public function notHidden()
{
$arResultIDList = PromoBlockListStore::instance()->not_hidden->get();
return $this->intersect($arResultIDList);
}
}

View File

@ -0,0 +1,39 @@
<?php namespace Lovata\Shopaholic\Classes\Collection;
use Lovata\Toolbox\Classes\Collection\ElementCollection;
use Lovata\Shopaholic\Classes\Item\TaxItem;
use Lovata\Shopaholic\Classes\Store\TaxListStore;
/**
* Class TaxCollection
* @package Lovata\Shopaholic\Classes\Collection
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class TaxCollection extends ElementCollection
{
const ITEM_CLASS = TaxItem::class;
/**
* Apply sorting
* @return $this
*/
public function sort()
{
//Get sorting list
$arResultIDList = TaxListStore::instance()->sorting->get();
return $this->applySorting($arResultIDList);
}
/**
* Apply filter by active tax list
* @return $this
*/
public function active()
{
$arResultIDList = TaxListStore::instance()->active->get();
return $this->intersect($arResultIDList);
}
}

View File

@ -0,0 +1,56 @@
<?php namespace Lovata\Shopaholic\Classes\Console;
use Illuminate\Console\Command;
/**
* Class CheckTableIntegrity
* @package Lovata\Shopaholic\Classes\Console
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class CheckTableIntegrity extends Command
{
/**
* @var string command name.
*/
protected $name = 'shopaholic:check.table.integrity';
/**
* @var string The console command description.
*/
protected $description = 'Check table integrity of plugins';
protected $arMigrationList = [
['path' => 'plugins/lovata/shopaholic/updates/update_table_users_add_currency_field.php', 'class' => '\Lovata\Shopaholic\Updates\UpdateTableUsersAddCurrencyField'],
['path' => 'plugins/lovata/compareshopaholic/updates/update_table_users.php', 'class' => '\Lovata\CompareShopaholic\Updates\UpdateTableUsers'],
['path' => 'plugins/lovata/ordersshopaholic/updates/table_update_taxes_add_applied_to_shipping_price.php', 'class' => '\Lovata\OrdersShopaholic\Updates\TableUpdateTaxesAddAppliedToShippingPrice'],
['path' => 'plugins/lovata/searchshopaholic/updates/update_table_tag.php', 'class' => '\Lovata\SearchShopaholic\Updates\UpdateTableTag'],
['path' => 'plugins/lovata/sphinxshopaholic/updates/update_table_tag.php', 'class' => '\Lovata\SphinxShopaholic\Updates\UpdateTableTag'],
['path' => 'plugins/lovata/viewedproductsshopaholic/updates/update_table_users.php', 'class' => '\Lovata\ViewedProductsShopaholic\Updates\UpdateTableUsers'],
['path' => 'plugins/lovata/wishlistshopaholic/updates/update_table_users.php', 'class' => '\Lovata\WishListShopaholic\Updates\UpdateTableUsers'],
];
/**
* Execute the console command.
* @throws \Throwable
*/
public function handle()
{
foreach ($this->arMigrationList as $arMigrationData) {
$sClassName = $arMigrationData['class'];
$sFilePath = base_path($arMigrationData['path']);
if (!file_exists($sFilePath)) {
continue;
}
include_once $sFilePath;
if (!class_exists($sClassName)) {
continue;
}
/** @var \October\Rain\Database\Updates\Migration $obMigration */
$obMigration = new $sClassName();
$obMigration->up();
}
}
}

View File

@ -0,0 +1,83 @@
<?php namespace Lovata\Shopaholic\Classes\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Lovata\Shopaholic\Classes\Import\ImportBrandModelFromXML;
use Lovata\Shopaholic\Classes\Import\ImportCategoryModelFromXML;
use Lovata\Shopaholic\Classes\Import\ImportOfferModelFromXML;
use Lovata\Shopaholic\Classes\Import\ImportOfferPriceFromXML;
use Lovata\Shopaholic\Classes\Import\ImportProductModelFromXML;
/**
* Class ImportFromXML
* @package Lovata\Shopaholic\Classes\Console
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ImportFromXML extends Command
{
/**
* @var string command name.
*/
protected $name = 'shopaholic:import_from_xml';
/**
* @var string The console command description.
*/
protected $description = 'Run import catalog from XML';
protected $arClassList = [
'brand' => ImportBrandModelFromXML::class,
'category' => ImportCategoryModelFromXML::class,
'property' => 'Lovata\PropertiesShopaholic\Classes\Import\ImportPropertyModelFromXML',
'product' => ImportProductModelFromXML::class,
'offer' => ImportOfferModelFromXML::class,
'price' => ImportOfferPriceFromXML::class,
];
/**
* Get the console command options.
* @return array
*/
protected function getOptions()
{
return [
['import', null, InputOption::VALUE_OPTIONAL, 'Available values: brand,category,property,product,offer.', null],
];
}
/**
* Execute the console command.
* @throws \Throwable
*/
public function handle()
{
$arImportList = explode(',', $this->option('import'));
$arImportList = array_filter($arImportList);
foreach ($this->arClassList as $sKey => $sImportClass) {
if (!class_exists($sImportClass) || (!empty($arImportList) && !in_array($sKey, $arImportList))) {
continue;
}
/** @var \Lovata\Toolbox\Classes\Helper\AbstractImportModelFromXML $obImport */
$obImport = new $sImportClass();
$obImport->openMainFile();
if (empty($obImport->getTotalCount())) {
continue;
}
$this->info("Start import for \"$sKey\"");
$obProgressBar = $this->output->createProgressBar($obImport->getTotalCount());
$obImport->import($obProgressBar);
$obProgressBar->finish();
$this->info("\nFinish import for \"$sKey\"\n");
$this->info("Created - {$obImport->getCreatedCount()}");
$this->info("Updated - {$obImport->getUpdatedCount()}");
$this->warn("Skipped - {$obImport->getSkippedCount()}");
$this->info("Processed - {$obImport->getProcessedCount()}\n");
}
}
}

View File

@ -0,0 +1,58 @@
<?php namespace Lovata\Shopaholic\Classes\Console;
use DB;
use Illuminate\Console\Command;
/**
* Class PreconfigureImportSettingsFromXML
* @package Lovata\Shopaholic\Classes\Console
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class PreconfigureImportSettingsFromXML extends Command
{
/**
* @var string command name.
*/
protected $name = 'shopaholic:preconfigure_import_from_xml';
/**
* @var string The console command description.
*/
protected $description = 'Preconfigure import settings form xml file';
protected $arPresetList = [
[
'label' => '1C:Enterprise',
'config' => '{"file_list":[{"path":"temp\/import\/import.xml"},{"path":"temp\/import\/offers.xml"}],"image_folder":"temp\/import","product":[{"field":"external_id","path_to_field":"\u0418\u0434"},{"field":"name","path_to_field":"\u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435"},{"field":"code","path_to_field":"\u0428\u0442\u0440\u0438\u0445\u043a\u043e\u0434"},{"field":"category_id","path_to_field":"\u0413\u0440\u0443\u043f\u043f\u044b"},{"field":"additional_category","path_to_field":"\u0413\u0440\u0443\u043f\u043f\u044b"},{"field":"preview_image","path_to_field":"\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430"},{"field":"images","path_to_field":"\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430"}],"product_file_path":"0","product_path_to_list":"\u041a\u0430\u0442\u0430\u043b\u043e\u0433\/\u0422\u043e\u0432\u0430\u0440\u044b\/\u0422\u043e\u0432\u0430\u0440","brand_file_path":"","brand_path_to_list":"","brand":[],"brand_deactivate":"0","category_file_path":"0","category_path_to_list":"\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\/\u0413\u0440\u0443\u043f\u043f\u044b\/\u0413\u0440\u0443\u043f\u043f\u0430","category_deactivate":"0","category":[{"field":"external_id","path_to_field":"\u0418\u0434"},{"field":"name","path_to_field":"\u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435"},{"field":"active","path_to_field":"\u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0410\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c"},{"field":"children","path_to_field":"\u0413\u0440\u0443\u043f\u043f\u044b\/\u0413\u0440\u0443\u043f\u043f\u0430"}],"property_file_path":"0","property_path_to_list":"\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\/\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430\/\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u043e","property_deactivate":"0","property":[{"field":"external_id","path_to_field":"\u0418\u0434"},{"field":"name","path_to_field":"\u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435"}],"property_import_enable":"1","brand_import_enable":"0","category_import_enable":"1","product_import_enable":"1","offer_import_enable":"1","offer_file_path":"1","offer_path_to_list":"\u041f\u0430\u043a\u0435\u0442\u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439\/\u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f\/\u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435","offer":[{"field":"external_id","path_to_field":"\u0418\u0434"},{"field":"product_id","path_to_field":"\u0418\u0434"},{"field":"code","path_to_field":"\u0428\u0442\u0440\u0438\u0445\u043a\u043e\u0434"},{"field":"name","path_to_field":"\u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435"},{"field":"preview_image","path_to_field":"\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430"},{"field":"images","path_to_field":"\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430"},{"field":"quantity","path_to_field":"\u041e\u0441\u0442\u0430\u0442\u043a\u0438\/\u041e\u0441\u0442\u0430\u0442\u043e\u043a\/\u0421\u043a\u043b\u0430\u0434\/\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e"},{"field":"price","path_to_field":"\u0426\u0435\u043d\u044b\/\u0426\u0435\u043d\u0430\/\u0426\u0435\u043d\u0430\u0417\u0430\u0415\u0434\u0438\u043d\u0438\u0446\u0443"}],"price_import_enable":"1","price_file_path":"1","price_path_to_list":"\u041f\u0430\u043a\u0435\u0442\u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0439\/\u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f\/\u041f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435","price":[{"field":"external_id","path_to_field":"\u0418\u0434"},{"field":"quantity","path_to_field":"\u041e\u0441\u0442\u0430\u0442\u043a\u0438\/\u041e\u0441\u0442\u0430\u0442\u043e\u043a\/\u0421\u043a\u043b\u0430\u0434\/\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e"},{"field":"price","path_to_field":"\u0426\u0435\u043d\u044b\/\u0426\u0435\u043d\u0430\/\u0426\u0435\u043d\u0430\u0417\u0430\u0415\u0434\u0438\u043d\u0438\u0446\u0443"}],"product_property_list_path":"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0421\u0432\u043e\u0439\u0441\u0442\u0432\/\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430","product_property_id_path":"\u0418\u0434","product_property_value_path":"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435","offer_property_list_path":"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0421\u0432\u043e\u0439\u0441\u0442\u0432\/\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430","offer_property_id_path":"\u0418\u0434","offer_property_value_path":"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435"}',
],
];
/**
* Execute the console command.
* @throws \Throwable
*/
public function handle()
{
$arSettings = [];
$sPresetName = $this->choice('Select preset with import settings', array_pluck($this->arPresetList, 'label'), 0);
foreach ($this->arPresetList as $arPresetData) {
if ($arPresetData['label'] != $sPresetName) {
continue;
}
$arSettings = $arPresetData['config'];
}
if (empty($arSettings)) {
return;
}
DB::table('system_settings')->where('item', 'lovata_shopaholic_xml_import_settings')->delete();
DB::table('system_settings')->insert([
'value' => $arSettings,
'item' => 'lovata_shopaholic_xml_import_settings',
]);
$this->call('cache:clear');
}
}

View File

@ -0,0 +1,71 @@
<?php namespace Lovata\Shopaholic\Classes\Event;
use Lovata\Shopaholic\Classes\Helper\AllCategoriesMenuType;
use Lovata\Shopaholic\Classes\Helper\CatalogMenuType;
use Lovata\Shopaholic\Classes\Helper\CategoryMenuType;
/**
* Class ExtendMenuHandler
* @package Lovata\Shopaholic\Classes\Event
*
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
* @author Alvaro Cánepa, https://github.com/alvaro-canepa
*/
class ExtendMenuHandler
{
/**
* Add listeners
* @param \Illuminate\Events\Dispatcher $obEvent
*/
public function subscribe($obEvent)
{
/*
* Register menu items for the RainLab.Pages plugin
*/
$obEvent->listen('pages.menuitem.listTypes', function () {
$arResult = [
CatalogMenuType::MENU_TYPE => 'lovata.shopaholic::lang.menu.shop_catalog',
CategoryMenuType::MENU_TYPE => 'lovata.shopaholic::lang.menu.shop_category',
AllCategoriesMenuType::MENU_TYPE => 'lovata.shopaholic::lang.menu.all_shop_categories',
];
return $arResult;
});
$obEvent->listen('pages.menuitem.getTypeInfo', function ($sType) {
$obMenuType = $this->getMenuTypeObject($sType);
if (!empty($obMenuType)) {
return $obMenuType->getMenuTypeInfo();
}
});
$obEvent->listen('pages.menuitem.resolveItem', function ($sType, $obItem, $sURL) {
$obMenuType = $this->getMenuTypeObject($sType);
if (!empty($obMenuType)) {
return $obMenuType->resolveMenuItem($obItem, $sURL);
}
});
}
/**
* Get new menu object by type value
* @param string $sType
* @return \Lovata\Shopaholic\Classes\Helper\CommonMenuType
*/
protected function getMenuTypeObject($sType)
{
switch ($sType) {
case CategoryMenuType::MENU_TYPE:
return new CategoryMenuType();
case CatalogMenuType::MENU_TYPE:
return new CatalogMenuType();
case AllCategoriesMenuType::MENU_TYPE:
return new AllCategoriesMenuType();
default:
return null;
}
}
}

View File

@ -0,0 +1,98 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Brand;
use Lovata\Toolbox\Models\Settings;
use Lovata\Toolbox\Classes\Event\ModelHandler;
use Lovata\Shopaholic\Models\Brand;
use Lovata\Shopaholic\Classes\Item\BrandItem;
use Lovata\Shopaholic\Classes\Store\BrandListStore;
/**
* Class BrandModelHandler
* @package Lovata\Shopaholic\Classes\Event\Brand
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class BrandModelHandler extends ModelHandler
{
/** @var Brand */
protected $obElement;
/**
* Add listeners
* @param \Illuminate\Events\Dispatcher $obEvent
*/
public function subscribe($obEvent)
{
parent::subscribe($obEvent);
Brand::extend(function ($obModel) {
/** @var Brand $obModel */
$bSlugIsTranslatable = Settings::getValue('slug_is_translatable');
if ($bSlugIsTranslatable) {
$obModel->translatable[] = ['slug', 'index' => true];
}
});
$obEvent->listen('shopaholic.brand.update.sorting', function () {
$this->clearSortingList();
});
}
/**
* After create event handler
*/
protected function afterCreate()
{
parent::afterCreate();
$this->clearSortingList();
}
/**
* After save event handler
*/
protected function afterSave()
{
parent::afterSave();
$this->checkFieldChanges('active', BrandListStore::instance()->active);
}
/**
* After delete event handler
*/
protected function afterDelete()
{
parent::afterDelete();
$this->clearSortingList();
if ($this->obElement->active) {
BrandListStore::instance()->active->clear();
}
}
/**
* Clear sorting list
*/
protected function clearSortingList()
{
BrandListStore::instance()->sorting->clear();
}
/**
* Get model class name
* @return string
*/
protected function getModelClass()
{
return Brand::class;
}
/**
* Get item class name
* @return string
*/
protected function getItemClass()
{
return BrandItem::class;
}
}

View File

@ -0,0 +1,98 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Category;
use Lovata\Toolbox\Models\Settings;
use Lovata\Toolbox\Classes\Event\ModelHandler;
use Lovata\Shopaholic\Models\Category;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
use Lovata\Shopaholic\Classes\Store\CategoryListStore;
/**
* Class CategoryModelHandler
* @package Lovata\Shopaholic\Classes\Event\Category
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class CategoryModelHandler extends ModelHandler
{
/** @var Category */
protected $obElement;
/**
* Add listeners
* @param \Illuminate\Events\Dispatcher $obEvent
*/
public function subscribe($obEvent)
{
parent::subscribe($obEvent);
Category::extend(function ($obModel) {
/** @var Category $obModel */
$bSlugIsTranslatable = Settings::getValue('slug_is_translatable');
if ($bSlugIsTranslatable) {
$obModel->translatable[] = ['slug', 'index' => true];
}
});
$obEvent->listen('shopaholic.category.update.sorting', function () {
CategoryListStore::instance()->top_level->clear();
//Get category ID list
$arCategoryIDList = Category::lists('id');
if (empty($arCategoryIDList)) {
return;
}
//Clear cache for all categories
foreach ($arCategoryIDList as $iCategoryID) {
CategoryItem::clearCache($iCategoryID);
}
});
}
/**
* After save event handler
*/
protected function afterSave()
{
parent::afterSave();
CategoryListStore::instance()->top_level->clear();
$this->checkFieldChanges('active', CategoryListStore::instance()->active);
}
/**
* After delete event handler
*/
protected function afterDelete()
{
parent::afterDelete();
CategoryListStore::instance()->top_level->clear();
//Clear parent item cache
if (!empty($this->obElement->parent_id)) {
CategoryItem::clearCache($this->obElement->parent_id);
}
if ($this->obElement->active) {
CategoryListStore::instance()->active->clear();
}
}
/**
* Get model class name
* @return string
*/
protected function getModelClass()
{
return Category::class;
}
/**
* Get item class name
* @return string
*/
protected function getItemClass()
{
return CategoryItem::class;
}
}

View File

@ -0,0 +1,89 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Currency;
use Lovata\Toolbox\Classes\Event\ModelHandler;
use Lovata\Shopaholic\Models\Currency;
use Lovata\Shopaholic\Classes\Item\CurrencyItem;
use Lovata\Shopaholic\Classes\Store\CurrencyListStore;
/**
* Class CurrencyModelHandler
* @package Lovata\Shopaholic\Classes\Event\Currency
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class CurrencyModelHandler extends ModelHandler
{
/** @var Currency */
protected $obElement;
/**
* Add listeners
* @param \Illuminate\Events\Dispatcher $obEvent
*/
public function subscribe($obEvent)
{
parent::subscribe($obEvent);
$obEvent->listen('shopaholic.currency.update.sorting', function () {
$this->clearSortingList();
});
}
/**
* After create event handler
*/
protected function afterCreate()
{
parent::afterCreate();
$this->clearSortingList();
}
/**
* After save event handler
*/
protected function afterSave()
{
parent::afterSave();
$this->checkFieldChanges('active', CurrencyListStore::instance()->active);
}
/**
* After delete event handler
*/
protected function afterDelete()
{
parent::afterDelete();
$this->clearSortingList();
if ($this->obElement->active) {
CurrencyListStore::instance()->active->clear();
}
}
/**
* Clear sorting list
*/
protected function clearSortingList()
{
CurrencyListStore::instance()->sorting->clear();
}
/**
* Get model class name
* @return string
*/
protected function getModelClass()
{
return Currency::class;
}
/**
* Get item class name
* @return string
*/
protected function getItemClass()
{
return CurrencyItem::class;
}
}

View File

@ -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, a.khoronenko@lovata.com, 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;
}
}

View File

@ -0,0 +1,138 @@
<?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, a.khoronenko@lovata.com, LOVATA Group
*/
class ExtendOfferFieldsHandler extends AbstractBackendFieldHandler
{
protected $iPriority = 15000;
/**
* Extend form fields
* @param \Backend\Widgets\Form $obWidget
*/
protected function extendFields($obWidget)
{
$arAdditionFields = [
'measure' => [
'label' => 'lovata.shopaholic::lang.field.measure',
'type' => 'relation',
'span' => 'left',
'emptyOption' => 'lovata.toolbox::lang.field.empty',
'tab' => 'lovata.shopaholic::lang.tab.dimensions',
],
'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;
}
}

View File

@ -0,0 +1,226 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Offer;
use Lovata\Shopaholic\Models\PriceType;
use Lovata\Toolbox\Classes\Event\ModelHandler;
use Lovata\Shopaholic\Models\Offer;
use Lovata\Shopaholic\Models\Settings;
use Lovata\Shopaholic\Classes\Item\OfferItem;
use Lovata\Shopaholic\Classes\Item\ProductItem;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
use Lovata\Shopaholic\Classes\Store\OfferListStore;
use Lovata\Shopaholic\Classes\Store\ProductListStore;
/**
* Class OfferModelHandler
* @package Lovata\Shopaholic\Classes\Event\Offer
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class OfferModelHandler extends ModelHandler
{
/** @var Offer */
protected $obElement;
protected $bWithRestore = true;
/**
* After save event handler
*/
protected function afterCreate()
{
parent::afterCreate();
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_NO);
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_NEW);
}
/**
* After save event handler
*/
protected function afterSave()
{
parent::afterSave();
$this->checkProductIDField();
$this->checkActiveField();
}
/**
* After delete event handler
*/
protected function afterDelete()
{
parent::afterDelete();
if ($this->obElement->active) {
$this->clearProductActiveList();
$this->clearProductItemCache($this->obElement->product_id);
OfferListStore::instance()->active->clear();
$this->clearOfferSortingByPrice();
//Clear sorting product list by offer price
$this->clearProductSortingByPrice();
}
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_NO);
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_NEW);
}
/**
* After restore event handler
*/
protected function afterRestore()
{
parent::afterRestore();
if ($this->obElement->active) {
$this->clearProductActiveList();
$this->clearProductItemCache($this->obElement->product_id);
OfferListStore::instance()->active->clear();
$this->clearOfferSortingByPrice();
//Clear sorting product list by offer price
$this->clearProductSortingByPrice();
}
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_NO);
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_NEW);
}
/**
* Clear product item cache
* @param int $iProductID
*/
protected function clearProductItemCache($iProductID)
{
ProductItem::clearCache($iProductID);
}
/**
* Clear cache, if product ID field changed
*/
protected function checkProductIDField()
{
//Clear product cache
/** @var int $iOriginalProductID */
$iOriginalProductID = $this->obElement->getOriginal('product_id');
/** @var int $iProductID */
$iProductID = $this->obElement->getAttribute('product_id');
if ($iOriginalProductID == $iProductID) {
return;
}
if (!empty($iOriginalProductID)) {
$this->clearProductItemCache($iOriginalProductID);
}
if (!empty($iProductID)) {
$this->clearProductItemCache($iProductID);
}
}
/**
* Check offer "active" field, if it was changed, then clear cache
*/
protected function checkActiveField()
{
//check offer "active" field
if ($this->obElement->getOriginal('active') == $this->obElement->active) {
return;
}
$this->clearProductActiveList();
OfferListStore::instance()->active->clear();
$this->clearProductSortingByPrice();
$obProduct = $this->obElement->product;
if (empty($obProduct)) {
return;
}
$this->clearProductItemCache($this->obElement->product_id);
$obCategoryItem = CategoryItem::make($obProduct->category_id);
if ($obCategoryItem->isEmpty()) {
return;
}
$obCategoryItem->clearProductCount();
}
/**
* Clear cached active product ID list
*/
protected function clearProductActiveList()
{
if (!Settings::getValue('check_offer_active')) {
return;
}
ProductListStore::instance()->active->clear();
}
/**
* Clear offer sorting cache by price
*/
protected function clearOfferSortingByPrice()
{
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_PRICE_ASC);
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_PRICE_DESC);
//Get price types
$obPriceTypeList = PriceType::active()->get();
if ($obPriceTypeList->isEmpty()) {
return;
}
foreach ($obPriceTypeList as $obPriceType) {
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_PRICE_ASC.'|'.$obPriceType->code);
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_PRICE_DESC.'|'.$obPriceType->code);
}
}
/**
* Clear offer sorting cache by price
*/
protected function clearProductSortingByPrice()
{
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_ASC);
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_DESC);
//Get price types
$obPriceTypeList = PriceType::active()->get();
if ($obPriceTypeList->isEmpty()) {
return;
}
foreach ($obPriceTypeList as $obPriceType) {
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_ASC.'|'.$obPriceType->code);
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_DESC.'|'.$obPriceType->code);
}
}
/**
* Get model class name
* @return string
*/
protected function getModelClass()
{
return Offer::class;
}
/**
* Get item class name
* @return string
*/
protected function getItemClass()
{
return OfferItem::class;
}
}

View File

@ -0,0 +1,97 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Price;
use Lovata\Shopaholic\Models\Offer;
use Lovata\Shopaholic\Models\Price;
use Lovata\Shopaholic\Classes\Store\OfferListStore;
use Lovata\Shopaholic\Classes\Store\ProductListStore;
/**
* Class PriceModelHandler
* @package Lovata\Shopaholic\Classes\Event\Price
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class PriceModelHandler
{
protected $iPriority = 1000;
/** @var Price */
protected $obElement;
protected $obListStore;
protected $bWithRestore = false;
protected $sIdentifierField = 'id';
/**
* Add listeners
*/
public function subscribe()
{
$sModelClass = $this->getModelClass();
$sModelClass::extend(function ($obElement) {
/** @var \Model $obElement */
$obElement->bindEvent('model.afterSave', function () use ($obElement) {
$this->obElement = $obElement;
$this->afterSave();
}, $this->iPriority);
/** @var \Model $obElement */
$obElement->bindEvent('model.afterDelete', function () use ($obElement) {
$this->obElement = $obElement;
$this->afterDelete();
}, $this->iPriority);
});
}
/**
* After save event handler
*/
protected function afterSave()
{
if ($this->obElement->getOriginal('price') != $this->obElement->price_value) {
$this->clearPriceCache();
}
}
/**
* After delete event handler
*/
protected function afterDelete()
{
$this->clearPriceCache();
}
/**
* Clear product/offer price cache
*/
protected function clearPriceCache()
{
$obItem = $this->obElement->item;
if (empty($obItem)) {
return;
}
if ($obItem instanceof Offer) {
$sSorting = !empty($this->obElement->price_type) ? '|'.$this->obElement->price_type->code : '';
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_PRICE_ASC.$sSorting);
OfferListStore::instance()->sorting->clear(OfferListStore::SORT_PRICE_DESC.$sSorting);
if ($obItem->active) {
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_ASC.$sSorting);
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_DESC.$sSorting);
}
}
}
/**
* Get model class name
* @return string
*/
protected function getModelClass()
{
return Price::class;
}
}

View File

@ -0,0 +1,259 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Product;
use Lovata\Toolbox\Models\Settings;
use Lovata\Toolbox\Classes\Event\ModelHandler;
use Lovata\Shopaholic\Models\Product;
use Lovata\Shopaholic\Models\PriceType;
use Lovata\Shopaholic\Classes\Item\ProductItem;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
use Lovata\Shopaholic\Classes\Store\BrandListStore;
use Lovata\Shopaholic\Classes\Store\ProductListStore;
/**
* Class ProductModelHandler
* @package Lovata\Shopaholic\Classes\Event\Product
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ProductModelHandler extends ModelHandler
{
/** @var Product */
protected $obElement;
protected $bWithRestore = true;
/**
* Add listeners
* @param \Illuminate\Events\Dispatcher $obEvent
*/
public function subscribe($obEvent)
{
parent::subscribe($obEvent);
Product::extend(function ($obModel) {
/** @var Product $obModel */
$bSlugIsTranslatable = Settings::getValue('slug_is_translatable');
if ($bSlugIsTranslatable) {
$obModel->translatable[] = ['slug', 'index' => true];
}
});
}
/**
* After create event handler
*/
protected function afterCreate()
{
parent::afterCreate();
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_NEW);
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_NO);
}
/**
* After save event handler
*/
protected function afterSave()
{
parent::afterSave();
//Check "category_id" field
$this->checkCategoryIDField();
//Check "brand_id" field
$this->checkBrandIDField();
$this->checkActiveField();
}
/**
* After delete event handler
*/
protected function afterDelete()
{
$this->processOfferAfterDelete();
parent::afterDelete();
ProductListStore::instance()->category->clear($this->obElement->category_id);
BrandListStore::instance()->category->clear($this->obElement->category_id);
$this->clearCategoryProductCount($this->obElement->category_id);
ProductListStore::instance()->brand->clear($this->obElement->brand_id);
$this->clearProductSortingByPrice();
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_NEW);
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_NO);
if ($this->obElement->active) {
ProductListStore::instance()->active->clear();
}
$arAdditionalCategoryIDList = $this->obElement->additional_category->lists('id');
if (empty($arAdditionalCategoryIDList)) {
return;
}
foreach ($arAdditionalCategoryIDList as $iCategoryID) {
$this->clearCategoryProductCount($iCategoryID);
ProductListStore::instance()->category->clear($iCategoryID);
}
}
/**
* After restore event handler
*/
protected function afterRestore()
{
parent::afterRestore();
ProductListStore::instance()->category->clear($this->obElement->category_id);
BrandListStore::instance()->category->clear($this->obElement->category_id);
$this->clearCategoryProductCount($this->obElement->category_id);
ProductListStore::instance()->brand->clear($this->obElement->brand_id);
$this->clearProductSortingByPrice();
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_NEW);
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_NO);
if ($this->obElement->active) {
ProductListStore::instance()->active->clear();
}
$arAdditionalCategoryIDList = $this->obElement->additional_category->lists('id');
if (empty($arAdditionalCategoryIDList)) {
return;
}
foreach ($arAdditionalCategoryIDList as $iCategoryID) {
$this->clearCategoryProductCount($iCategoryID);
ProductListStore::instance()->category->clear($iCategoryID);
}
}
/**
* Set active = false in offer list, after product was removed
*/
protected function processOfferAfterDelete()
{
$obOfferList = $this->obElement->offer;
if ($obOfferList->isEmpty()) {
return;
}
foreach ($obOfferList as $obOffer) {
$obOffer->active = false;
$obOffer->save();
}
}
/**
* Check offer "active" field, if it was changed, then clear cache
*/
protected function checkActiveField()
{
//check product "active" field
if (!$this->isFieldChanged('active')) {
return;
}
ProductListStore::instance()->active->clear();
$this->clearCategoryProductCount($this->obElement->category_id);
//Get additional category ID list
$arAdditionalCategoryIDList = $this->obElement->additional_category->lists('id');
if (empty($arAdditionalCategoryIDList)) {
return;
}
foreach ($arAdditionalCategoryIDList as $iCategoryID) {
$this->clearCategoryProductCount($iCategoryID);
}
}
/**
* Check product "category_id" field, if it was changed, then clear cache
*/
protected function checkCategoryIDField()
{
//Check "category_id" field
if (!$this->isFieldChanged('category_id')) {
return;
}
//Update product ID cache list for category
ProductListStore::instance()->category->clear($this->obElement->category_id);
ProductListStore::instance()->category->clear((int) $this->obElement->getOriginal('category_id'));
BrandListStore::instance()->category->clear($this->obElement->category_id);
BrandListStore::instance()->category->clear((int) $this->obElement->getOriginal('category_id'));
$this->clearCategoryProductCount($this->obElement->category_id);
$this->clearCategoryProductCount((int) $this->obElement->getOriginal('category_id'));
}
/**
* Check product "brand_id" field, if it was changed, then clear cache
*/
protected function checkBrandIDField()
{
//Check "brand_id" field
if ($this->obElement->getOriginal('brand_id') == $this->obElement->brand_id) {
return;
}
//Update product ID cache list for brand
ProductListStore::instance()->brand->clear($this->obElement->brand_id);
ProductListStore::instance()->brand->clear((int) $this->obElement->getOriginal('brand_id'));
}
/**
* Clear product count cache in category item
* @param int $iCategoryID
*/
protected function clearCategoryProductCount($iCategoryID)
{
$obCategoryItem = CategoryItem::make($iCategoryID);
if ($obCategoryItem->isNotEmpty()) {
$obCategoryItem->clearProductCount();
}
}
/**
* Clear offer sorting cache by price
*/
protected function clearProductSortingByPrice()
{
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_ASC);
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_DESC);
//Get price types
$obPriceTypeList = PriceType::active()->get();
if ($obPriceTypeList->isEmpty()) {
return;
}
foreach ($obPriceTypeList as $obPriceType) {
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_ASC.'|'.$obPriceType->code);
ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_DESC.'|'.$obPriceType->code);
}
}
/**
* Get model class name
* @return string
*/
protected function getModelClass()
{
return Product::class;
}
/**
* Get item class name
* @return string
*/
protected function getItemClass()
{
return ProductItem::class;
}
}

View File

@ -0,0 +1,95 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Product;
use Lovata\Toolbox\Classes\Event\AbstractModelRelationHandler;
use Lovata\Shopaholic\Models\Product;
use Lovata\Shopaholic\Classes\Store\BrandListStore;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
use Lovata\Shopaholic\Classes\Store\ProductListStore;
/**
* Class ProductRelationHandler
* @package Lovata\Shopaholic\Classes\Event\Product
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ProductRelationHandler extends AbstractModelRelationHandler
{
protected $iPriority = 900;
/**
* After attach event handler
* @param \Model $obModel
* @param array $arAttachedIDList
* @param array $arInsertData
*/
protected function afterAttach($obModel, $arAttachedIDList, $arInsertData)
{
$this->clearListByPromoBlock($arAttachedIDList);
$this->clearListByCategory($arAttachedIDList);
}
/**
* After detach event handler
* @param \Model $obModel
* @param array $arAttachedIDList
*/
protected function afterDetach($obModel, $arAttachedIDList)
{
$this->clearListByPromoBlock($arAttachedIDList);
$this->clearListByCategory($arAttachedIDList);
}
/**
* Clear cached product list by promo block ID
* @param array $arAttachedIDList
*/
protected function clearListByPromoBlock($arAttachedIDList)
{
if ($this->sRelationName != 'promo_block') {
return;
}
foreach ($arAttachedIDList as $iPromoBlockID) {
ProductListStore::instance()->promo_block->clear($iPromoBlockID);
}
}
/**
* Clear cached product list by category ID
* @param array $arAttachedIDList
*/
protected function clearListByCategory($arAttachedIDList)
{
if ($this->sRelationName != 'additional_category') {
return;
}
foreach ($arAttachedIDList as $iCategoryID) {
BrandListStore::instance()->category->clear($iCategoryID);
ProductListStore::instance()->category->clear($iCategoryID);
$obCategoryItem = CategoryItem::make($iCategoryID);
if ($obCategoryItem->isNotEmpty()) {
$obCategoryItem->clearProductCount();
}
}
}
/**
* Get model class name
* @return string
*/
protected function getModelClass() : string
{
return Product::class;
}
/**
* Get relation name
* @return array
*/
protected function getRelationName()
{
return ['promo_block', 'additional_category'];
}
}

View File

@ -0,0 +1,119 @@
<?php namespace Lovata\Shopaholic\Classes\Event\PromoBlock;
use Lovata\Toolbox\Models\Settings;
use Lovata\Toolbox\Classes\Event\ModelHandler;
use Lovata\Shopaholic\Models\PromoBlock;
use Lovata\Shopaholic\Classes\Item\PromoBlockItem;
use Lovata\Shopaholic\Classes\Store\PromoBlockListStore;
use Lovata\Shopaholic\Classes\Store\ProductListStore;
/**
* Class PromoBlockModelHandler
* @package Lovata\Shopaholic\Classes\Event\PromoBlock
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class PromoBlockModelHandler extends ModelHandler
{
/** @var PromoBlock */
protected $obElement;
/**
* Add listeners
* @param \Illuminate\Events\Dispatcher $obEvent
*/
public function subscribe($obEvent)
{
parent::subscribe($obEvent);
PromoBlock::extend(function ($obModel) {
/** @var PromoBlock $obModel */
$bSlugIsTranslatable = Settings::getValue('slug_is_translatable');
if ($bSlugIsTranslatable) {
$obModel->translatable[] = ['slug', 'index' => true];
}
});
$obEvent->listen('shopaholic.promo_block.update.sorting', function () {
$this->clearSortingList();
});
}
/**
* After create event handler
*/
protected function afterCreate()
{
parent::afterCreate();
$this->clearSortingList();
}
/**
* After save event handler
*/
protected function afterSave()
{
parent::afterSave();
if ($this->isFieldChanged('date_begin')) {
PromoBlockListStore::instance()->sorting->clear(PromoBlockListStore::SORT_DATE_BEGIN_ASC);
PromoBlockListStore::instance()->sorting->clear(PromoBlockListStore::SORT_DATE_BEGIN_DESC);
}
if ($this->isFieldChanged('date_end')) {
PromoBlockListStore::instance()->sorting->clear(PromoBlockListStore::SORT_DATE_END_ASC);
PromoBlockListStore::instance()->sorting->clear(PromoBlockListStore::SORT_DATE_END_DESC);
}
$this->checkFieldChanges('hidden', PromoBlockListStore::instance()->hidden);
$this->checkFieldChanges('hidden', PromoBlockListStore::instance()->not_hidden);
$this->checkFieldChanges('active', PromoBlockListStore::instance()->active);
}
/**
* After delete event handler
*/
protected function afterDelete()
{
parent::afterDelete();
$this->clearSortingList();
ProductListStore::instance()->promo_block->clear($this->obElement->id);
$this->clearCacheNotEmptyValue('hidden', PromoBlockListStore::instance()->hidden);
$this->clearCacheEmptyValue('hidden', PromoBlockListStore::instance()->not_hidden);
$this->clearCacheNotEmptyValue('active', PromoBlockListStore::instance()->active);
}
/**
* Clear sorting list
*/
protected function clearSortingList()
{
PromoBlockListStore::instance()->sorting->clear(PromoBlockListStore::SORT_DEFAULT);
PromoBlockListStore::instance()->sorting->clear(PromoBlockListStore::SORT_DATE_BEGIN_ASC);
PromoBlockListStore::instance()->sorting->clear(PromoBlockListStore::SORT_DATE_BEGIN_DESC);
PromoBlockListStore::instance()->sorting->clear(PromoBlockListStore::SORT_DATE_END_ASC);
PromoBlockListStore::instance()->sorting->clear(PromoBlockListStore::SORT_DATE_END_DESC);
}
/**
* Get model class name
* @return string
*/
protected function getModelClass()
{
return PromoBlock::class;
}
/**
* Get item class name
* @return string
*/
protected function getItemClass()
{
return PromoBlockItem::class;
}
}

View File

@ -0,0 +1,64 @@
<?php namespace Lovata\Shopaholic\Classes\Event\PromoBlock;
use Lovata\Toolbox\Classes\Event\AbstractModelRelationHandler;
use Lovata\Shopaholic\Models\PromoBlock;
use Lovata\Shopaholic\Classes\Store\ProductListStore;
/**
* Class PromoBlockRelationHandler
* @package Lovata\Shopaholic\Classes\Event\PromoBlock
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class PromoBlockRelationHandler extends AbstractModelRelationHandler
{
protected $iPriority = 900;
/**
* After attach event handler
* @param PromoBlock $obModel
* @param array $arAttachedIDList
* @param array $arInsertData
*/
protected function afterAttach($obModel, $arAttachedIDList, $arInsertData)
{
$this->clearCachedList($obModel);
}
/**
* After detach event handler
* @param PromoBlock $obModel
* @param array $arAttachedIDList
*/
protected function afterDetach($obModel, $arAttachedIDList)
{
$this->clearCachedList($obModel);
}
/**
* Clear cached list
* @param PromoBlock $obModel
*/
protected function clearCachedList($obModel)
{
ProductListStore::instance()->promo_block->clear($obModel->id);
}
/**
* Get model class name
* @return string
*/
protected function getModelClass() : string
{
return PromoBlock::class;
}
/**
* Get relation name
* @return array
*/
protected function getRelationName()
{
return ['product'];
}
}

View File

@ -0,0 +1,47 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Tax;
use System\Classes\PluginManager;
use Lovata\Toolbox\Classes\Event\AbstractBackendFieldHandler;
use Lovata\Shopaholic\Models\Tax;
use Lovata\Shopaholic\Controllers\Taxes;
/**
* Class ExtendTaxFieldsHandler
* @package Lovata\Shopaholic\Classes\Event\Tax
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ExtendTaxFieldsHandler extends AbstractBackendFieldHandler
{
/**
* Extend backend fields
* @param \Backend\Widgets\Form $obWidget
*/
protected function extendFields($obWidget)
{
if (PluginManager::instance()->hasPlugin('RainLab.Location')) {
return;
}
$obWidget->removeField('country');
$obWidget->removeField('state');
}
/**
* Get model class name
* @return string
*/
protected function getModelClass() : string
{
return Tax::class;
}
/**
* Get controller class name
* @return string
*/
protected function getControllerClass() : string
{
return Taxes::class;
}
}

View File

@ -0,0 +1,100 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Tax;
use System\Classes\PluginManager;
use Lovata\Toolbox\Classes\Event\ModelHandler;
use Lovata\Shopaholic\Models\Tax;
use Lovata\Shopaholic\Classes\Item\TaxItem;
use Lovata\Shopaholic\Classes\Store\TaxListStore;
/**
* Class TaxModelHandler
* @package Lovata\Shopaholic\Classes\Event\Tax
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class TaxModelHandler extends ModelHandler
{
/** @var Tax */
protected $obElement;
/**
* Add listeners
* @param \Illuminate\Events\Dispatcher $obEvent
*/
public function subscribe($obEvent)
{
parent::subscribe($obEvent);
$obEvent->listen('shopaholic.tax.update.sorting', function () {
$this->clearSortingList();
});
if (PluginManager::instance()->hasPlugin('RainLab.Location')) {
return;
}
Tax::extend(function ($obTax) {
/** @var Tax $obTax */
unset($obTax->belongsToMany['country']);
unset($obTax->belongsToMany['state']);
});
}
/**
* After create event handler
*/
protected function afterCreate()
{
parent::afterCreate();
$this->clearSortingList();
}
/**
* After save event handler
*/
protected function afterSave()
{
parent::afterSave();
$this->checkFieldChanges('active', TaxListStore::instance()->active);
}
/**
* After delete event handler
*/
protected function afterDelete()
{
parent::afterDelete();
$this->clearSortingList();
if ($this->obElement->active) {
TaxListStore::instance()->active->clear();
}
}
/**
* Clear sorting list
*/
protected function clearSortingList()
{
TaxListStore::instance()->sorting->clear();
}
/**
* Get model class name
* @return string
*/
protected function getModelClass()
{
return Tax::class;
}
/**
* Get item class name
* @return string
*/
protected function getItemClass()
{
return TaxItem::class;
}
}

View File

@ -0,0 +1,55 @@
<?php namespace Lovata\Shopaholic\Classes\Event\Tax;
use Lovata\Shopaholic\Classes\Item\TaxItem;
use Lovata\Toolbox\Classes\Event\AbstractModelRelationHandler;
use Lovata\Shopaholic\Models\Tax;
/**
* Class TaxRelationHandler
* @package Lovata\Shopaholic\Classes\Event\Tax
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class TaxRelationHandler extends AbstractModelRelationHandler
{
protected $iPriority = 900;
/**
* After attach event handler
* @param Tax $obModel
* @param array $arAttachedIDList
* @param array $arInsertData
*/
protected function afterAttach($obModel, $arAttachedIDList, $arInsertData)
{
TaxItem::clearCache($obModel->id);
}
/**
* After detach event handler
* @param Tax $obModel
* @param array $arAttachedIDList
*/
protected function afterDetach($obModel, $arAttachedIDList)
{
TaxItem::clearCache($obModel->id);
}
/**
* Get model class name
* @return string
*/
protected function getModelClass() : string
{
return Tax::class;
}
/**
* Get relation name
* @return array
*/
protected function getRelationName()
{
return ['category', 'product', 'country', 'state'];
}
}

View File

@ -0,0 +1,57 @@
<?php namespace Lovata\Shopaholic\Classes\Helper;
use Lovata\Shopaholic\Models\Category;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
/**
* Class AllCategoriesMenuType
* @package Lovata\Shopaholic\Classes\Helper
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class AllCategoriesMenuType extends CommonMenuType
{
const MENU_TYPE = 'all-shop-categories';
/**
* Handler for the pages.menuitem.resolveItem event.
* @param \RainLab\Pages\Classes\MenuItem $obMenuItem
* @param string $sURL
*
* @return array|mixed
*/
public function resolveMenuItem($obMenuItem, $sURL)
{
$arResult = [
'items' => [],
];
//Get category list with sorted by 'nest_left'
$obCategoryList = Category::active()->orderBy('nest_left', 'asc')->get();
if ($obCategoryList->isEmpty()) {
return $arResult;
}
/** @var Category $obCategory */
foreach ($obCategoryList as $obCategory) {
$obCategoryItem = CategoryItem::make($obCategory->id, $obCategory);
$arMenuItem = $this->getCategoryMenuData($obCategoryItem, $obMenuItem->cmsPage, $sURL);
$arResult['items'][] = $arMenuItem;
}
return $arResult;
}
/**
* Get default array for menu type
* @return array|null
*/
protected function getDefaultMenuTypeInfo()
{
$arResult = [
'dynamicItems' => true,
];
return $arResult;
}
}

View File

@ -0,0 +1,60 @@
<?php namespace Lovata\Shopaholic\Classes\Helper;
use Lovata\Shopaholic\Classes\Collection\CategoryCollection;
/**
* Class CatalogMenuType
* @package Lovata\Shopaholic\Classes\Helper
*
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
* @author Alvaro Cánepa, https://github.com/alvaro-canepa
*/
class CatalogMenuType extends CommonMenuType
{
const MENU_TYPE = 'shop-catalog';
/**
* Handler for the pages.menuitem.resolveItem event.
* @param \RainLab\Pages\Classes\MenuItem $obMenuItem
* @param string $sURL
* @return array|mixed
*/
public function resolveMenuItem($obMenuItem, $sURL)
{
$arResult = [
'items' => [],
];
//Get category list with sorted by 'nest_left'
$obCategoryList = CategoryCollection::make()->tree();
if ($obCategoryList->isEmpty()) {
return $arResult;
}
/** @var \Lovata\Shopaholic\Classes\Item\CategoryItem $obCategoryItem */
foreach ($obCategoryList as $obCategoryItem) {
$arMenuItem = $this->getCategoryMenuData($obCategoryItem, $obMenuItem->cmsPage, $sURL);
if ($obMenuItem->nesting) {
$arMenuItem['items'] = $this->getChildrenCategoryList($obCategoryItem, $obMenuItem->cmsPage, $sURL);
}
$arResult['items'][] = $arMenuItem;
}
return $arResult;
}
/**
* Get default array for menu type
* @return array|null
*/
protected function getDefaultMenuTypeInfo()
{
$arResult = [
'dynamicItems' => true,
'nesting' => true,
];
return $arResult;
}
}

View File

@ -0,0 +1,59 @@
<?php namespace Lovata\Shopaholic\Classes\Helper;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
/**
* Class CategoryMenuType
* @package Lovata\Shopaholic\Classes\Helper
*
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
* @author Alvaro Cánepa, https://github.com/alvaro-canepa
*/
class CategoryMenuType extends CommonMenuType
{
const MENU_TYPE = 'shop-category';
/**
* Handler for the pages.menuitem.resolveItem event.
* @param \RainLab\Pages\Classes\MenuItem $obMenuItem
* @param string $sURL
* @return array|mixed
*/
public function resolveMenuItem($obMenuItem, $sURL)
{
$arResult = [];
if (empty($obMenuItem->reference)) {
return $arResult;
}
$obCategoryItem = CategoryItem::make($obMenuItem->reference);
if ($obCategoryItem->isEmpty()) {
return $arResult;
}
$arResult = $this->getCategoryMenuData($obCategoryItem, $obMenuItem->cmsPage, $sURL);
if (!$obMenuItem->nesting || $obCategoryItem->children->isEmpty()) {
return $arResult;
}
$arResult['items'] = $this->getChildrenCategoryList($obCategoryItem, $obMenuItem->cmsPage, $sURL);
return $arResult;
}
/**
* Get default array for menu type
* @return array|null
*/
protected function getDefaultMenuTypeInfo()
{
$arResult = [
'references' => $this->listSubCategoryOptions(),
'nesting' => true,
'dynamicItems' => true,
];
return $arResult;
}
}

View File

@ -0,0 +1,200 @@
<?php namespace Lovata\Shopaholic\Classes\Helper;
use Cms\Classes\Theme;
use Cms\Classes\Page as CmsPage;
use Lovata\Shopaholic\Classes\Collection\CategoryCollection;
/**
* Class CommonMenuType
* @package Lovata\Shopaholic\Classes\Helper
*
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
* @author Alvaro Cánepa, https://github.com/alvaro-canepa
*/
abstract class CommonMenuType
{
/**
* Handler for the pages.menuitem.resolveItem event.
* Returns information about a menu item. The result is an array
* with the following keys:
* - url - the menu item URL. Not required for menu item types that return all available records.
* The URL should be returned relative to the website root and include the subdirectory, if any.
* Use the URL::to() helper to generate the URLs.
* - isActive - determines whether the menu item is active. Not required for menu item types that
* return all available records.
* - items - an array of arrays with the same keys (url, isActive, items) + the title key.
* The items array should be added only if the $item's $nesting property value is TRUE.
*
* @param \RainLab\Pages\Classes\MenuItem $obItem Specifies the menu item.
* @param string $sURL Specifies the current page URL, normalized, in lower case
*
* The URL is specified relative to the website root, it includes the subdirectory name, if any.
* @return mixed Returns an array. Returns null if the item cannot be resolved.
*/
abstract public function resolveMenuItem($obItem, $sURL);
/**
* Handler for the pages.menuitem.getTypeInfo event.
* Returns a menu item type information. The type information is returned as array
* with the following elements:
* - references - a list of the item type reference options. The options are returned in the
* ["key"] => "title" format for options that don't have sub-options, and in the format
* ["key"] => ["title"=>"Option title", "items"=>[...]] for options that have sub-options. Optional,
* required only if the menu item type requires references.
* - nesting - Boolean value indicating whether the item type supports nested items. Optional,
* false if omitted.
* - dynamicItems - Boolean value indicating whether the item type could generate new menu items.
* Optional, false if omitted.
* - cmsPages - a list of CMS pages (objects of the Cms\Classes\Page class), if the item type requires a CMS page reference to
* resolve the item URL.
* @return array Returns an array
*/
public function getMenuTypeInfo()
{
$arResult = $this->getDefaultMenuTypeInfo();
if (empty($arResult)) {
return $arResult;
}
$obTheme = Theme::getActiveTheme();
$obPageList = CmsPage::listInTheme($obTheme, true);
$arResult['cmsPages'] = $this->filterPageList($obPageList);
return $arResult;
}
/**
* Get default array for menu type
* @return array|null
*/
abstract protected function getDefaultMenuTypeInfo();
/**
* Filter page list, add pages with CategoryPage component to result
* @param \October\Rain\Support\Collection $obPageList
* @return array
*/
protected function filterPageList($obPageList)
{
$arCmsPageList = [];
if (empty($obPageList) || $obPageList->isEmpty()) {
return $arCmsPageList;
}
/** @var CmsPage $obPage */
foreach ($obPageList as $obPage) {
if (!$obPage->hasComponent('CategoryPage')) {
continue;
}
/*
* Component must use a category filter with a routing parameter
* eg: categoryFilter = "{{ :somevalue }}"
*/
$arPropertyList = $obPage->getComponentProperties('CategoryPage');
if (!isset($arPropertyList['slug']) || !preg_match('/{{\s*:/', $arPropertyList['slug'])) {
continue;
}
$arCmsPageList[] = $obPage;
}
return $arCmsPageList;
}
/**
* Get subcategories list
* @return array
*/
protected function listSubCategoryOptions()
{
$arResult = [];
$obCategoryList = CategoryCollection::make()->tree();
if ($obCategoryList->isEmpty()) {
return $arResult;
}
$arResult = $this->getCategoryMenuOptions($obCategoryList);
return $arResult;
}
/**
* Get option array for category
* @param CategoryCollection|\Lovata\Shopaholic\Classes\Item\CategoryItem[] $obCategoryList
* @return null|array|string
*/
protected function getCategoryMenuOptions($obCategoryList)
{
if (empty($obCategoryList) || $obCategoryList->isEmpty()) {
return null;
}
$arResult = [];
foreach ($obCategoryList as $obCategory) {
if ($obCategory->children->isEmpty()) {
$arResult[$obCategory->id] = $obCategory->name;
} else {
$arResult[$obCategory->id] = [
'title' => $obCategory->name,
'items' => $this->getCategoryMenuOptions($obCategory->children),
];
}
}
return $arResult;
}
/**
* Get array for menu item from category item
* @param \Lovata\Shopaholic\Classes\Item\CategoryItem $obCategoryItem
* @param string $sPageCode
* @param string $sURL
*
* @return array
*/
protected function getCategoryMenuData($obCategoryItem, $sPageCode, $sURL)
{
if (empty($obCategoryItem)) {
return [];
}
$arMenuItem = [
'title' => $obCategoryItem->name,
'url' => $obCategoryItem->getPageUrl($sPageCode),
'mtime' => $obCategoryItem->updated_at,
'viewBag' => ['object' => $obCategoryItem],
];
$arMenuItem['isActive'] = $arMenuItem['url'] == $sURL;
return $arMenuItem;
}
/**
* Get list of children categories for menu items
* @param \Lovata\Shopaholic\Classes\Item\CategoryItem $obCategoryItem
* @param string $sPageCode
* @param string $sURL
*
* @return array
*/
protected function getChildrenCategoryList($obCategoryItem, $sPageCode, $sURL)
{
if (empty($obCategoryItem) || $obCategoryItem->children->isEmpty()) {
return [];
}
$arResult = [];
foreach ($obCategoryItem->children as $obChildrenCategory) {
$arMenuItem = $this->getCategoryMenuData($obChildrenCategory, $sPageCode, $sURL);
if ($obChildrenCategory->children->isNotEmpty()) {
$arMenuItem['items'] = $this->getChildrenCategoryList($obChildrenCategory, $sPageCode, $sURL);
}
$arResult[] = $arMenuItem;
}
return $arResult;
}
}

View File

@ -0,0 +1,221 @@
<?php namespace Lovata\Shopaholic\Classes\Helper;
use October\Rain\Support\Traits\Singleton;
use Lovata\Toolbox\Classes\Helper\PriceHelper;
use Lovata\Toolbox\Classes\Storage\CookieUserStorage;
use Lovata\Toolbox\Classes\Storage\UserStorage;
use Lovata\Shopaholic\Models\Currency;
/**
* Class CurrencyHelper
* @package Lovata\Shopaholic\Classes\Helper
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class CurrencyHelper
{
use Singleton;
const FIELD_NAME = 'active_currency_code';
/** @var Currency */
protected $obActiveCurrency;
/** @var Currency */
protected $obDefaultCurrency;
/** @var \October\Rain\Database\Collection|Currency[] */
protected $obCurrencyList;
/** @var string */
protected $sActiveCurrencyCode;
/**
* Get value of active currency
* @return Currency
*/
public function getActive()
{
return $this->obActiveCurrency;
}
/**
* Get default currency object
* @return Currency
*/
public function getDefault()
{
return $this->obDefaultCurrency;
}
/**
* Set default currency as active
* Used in backend
*/
public function disableActiveCurrency()
{
if (empty($this->obDefaultCurrency)) {
return;
}
$this->sActiveCurrencyCode = $this->obDefaultCurrency->code;
$this->obActiveCurrency = $this->obDefaultCurrency;
}
/**
* Get active currency symbol
* @return null|string
*/
public function getActiveCurrencySymbol()
{
$obCurrency = $this->getActive();
if (empty($obCurrency)) {
return null;
}
return $obCurrency->symbol;
}
/**
* Get active currency code
* @return null|string
*/
public function getActiveCurrencyCode()
{
$obCurrency = $this->getActive();
if (empty($obCurrency)) {
return null;
}
return $obCurrency->code;
}
/**
* Get currency symbol
* @param string $sCurrencyCode
* @return null|string
*/
public function getCurrencySymbol($sCurrencyCode)
{
$obCurrency = $this->obCurrencyList->where('code', $sCurrencyCode)->first();
if (empty($obCurrency)) {
return null;
}
return $obCurrency->symbol;
}
/**
* Get currency code
* @param string $sCurrencyCode
* @return null|string
*/
public function getCurrencyCode($sCurrencyCode)
{
$obCurrency = $this->obCurrencyList->where('code', $sCurrencyCode)->first();
if (empty($obCurrency)) {
return null;
}
return $obCurrency->code;
}
/**
* Clear active currency value
* @param string $sCurrencyCode
*/
public function switchActive($sCurrencyCode)
{
$obUserStorage = $this->getUserStorage();
$obUserStorage->put(self::FIELD_NAME, $sCurrencyCode);
$this->sActiveCurrencyCode = $sCurrencyCode;
$this->initActiveCurrency();
}
/**
* Clear active currency value
*/
public function resetActive()
{
$obUserStorage = $this->getUserStorage();
$obUserStorage->clear(self::FIELD_NAME);
$this->obActiveCurrency = $this->obDefaultCurrency;
}
/**
* @param float $fPrice
* @param string $sCurrencyTo
* @return float
*/
public function convert($fPrice, $sCurrencyTo = null)
{
if (empty($sCurrencyTo)) {
$obCurrencyTo = $this->obActiveCurrency;
} else {
$obCurrencyTo = $this->obCurrencyList->where('code', $sCurrencyTo)->first();
}
if (empty($obCurrencyTo) || empty($this->obDefaultCurrency) || $obCurrencyTo->id == $this->obDefaultCurrency->id) {
return $fPrice;
}
$fResultPrice = PriceHelper::round(($this->obDefaultCurrency->rate * $fPrice) / $obCurrencyTo->rate);
return $fResultPrice;
}
/**
* Init currency data
*/
protected function init()
{
$this->obCurrencyList = Currency::active()->get();
$this->obDefaultCurrency = $this->obCurrencyList->where('is_default', true)->first();
$this->sActiveCurrencyCode = $this->getActiveCurrencyFromStorage();
$this->initActiveCurrency();
}
/**
* Get active currency code and find active currency object by code
*/
protected function initActiveCurrency()
{
$this->obActiveCurrency = null;
if (!empty($this->sActiveCurrencyCode)) {
$this->obActiveCurrency = $this->obCurrencyList->where('code', $this->sActiveCurrencyCode)->first();
}
if (empty($this->obActiveCurrency)) {
$this->obActiveCurrency = $this->obDefaultCurrency;
}
}
/**
* Get active currency code from user storage
* @return array
*/
protected function getActiveCurrencyFromStorage()
{
$obUserStorage = $this->getUserStorage();
$sActiveCurrencyCode = $obUserStorage->get(self::FIELD_NAME);
return $sActiveCurrencyCode;
}
/**
* Get user storage object (User model or cookie)
* @return UserStorage
*/
protected function getUserStorage()
{
/** @var UserStorage $obUserStorage */
$obUserStorage = app(UserStorage::class);
$obUserStorage->setDefaultStorage(CookieUserStorage::class);
return $obUserStorage;
}
}

View File

@ -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, a.khoronenko@lovata.com, 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;
}
}

View File

@ -0,0 +1,105 @@
<?php namespace Lovata\Shopaholic\Classes\Helper;
use October\Rain\Support\Traits\Singleton;
use Lovata\Shopaholic\Models\PriceType;
/**
* Class PriceTypeHelper
* @package Lovata\Shopaholic\Classes\Helper
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class PriceTypeHelper
{
use Singleton;
/** @var PriceType */
protected $obActivePriceType;
/** @var \October\Rain\Database\Collection|PriceType[] */
protected $obPriceTypeList;
/** @var string */
protected $sActivePriceTypeCode;
/**
* Get value of active price type
* @param string $sPriceTypeCode
* @return PriceType
*/
public function findByCode($sPriceTypeCode)
{
$obPriceType = $this->obPriceTypeList->where('code', $sPriceTypeCode)->first();
return $obPriceType;
}
/**
* Get value of active price type
* @return PriceType
*/
public function getActive()
{
return $this->obActivePriceType;
}
/**
* Get active price type code
* @return null|string
*/
public function getActivePriceTypeCode()
{
$obPriceType = $this->getActive();
if (empty($obPriceType)) {
return null;
}
return $obPriceType->code;
}
/**
* Get active price type code
* @return null|string
*/
public function getActivePriceTypeID()
{
$obPriceType = $this->getActive();
if (empty($obPriceType)) {
return null;
}
return $obPriceType->id;
}
/**
* Clear active currency value
* @param string $sPriceTypeCode
*/
public function switchActive($sPriceTypeCode)
{
$this->sActivePriceTypeCode = $sPriceTypeCode;
$this->initActivePriceType();
}
/**
* Init price type data
*/
protected function init()
{
$this->obPriceTypeList = PriceType::active()->get();
$this->initActivePriceType();
}
/**
* Get active price type code and find active price type object by code
*/
protected function initActivePriceType()
{
$this->obActivePriceType = null;
if (!empty($this->sActivePriceTypeCode)) {
$this->obActivePriceType = $this->obPriceTypeList->where('code', $this->sActivePriceTypeCode)->first();
}
}
}

View File

@ -0,0 +1,184 @@
<?php namespace Lovata\Shopaholic\Classes\Helper;
use System\Classes\PluginManager;
use October\Rain\Support\Traits\Singleton;
use Lovata\Toolbox\Classes\Helper\PriceHelper;
use Lovata\Shopaholic\Models\Settings;
use Lovata\Shopaholic\Classes\Collection\TaxCollection;
/**
* Class TaxHelper
* @package Lovata\Shopaholic\Classes\Helper
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class TaxHelper
{
use Singleton;
/** @var \Lovata\Shopaholic\Classes\Collection\TaxCollection|\Lovata\Shopaholic\Classes\Item\TaxItem[] */
protected $obTaxList;
/** @var bool */
protected $bPriceIncludeTax;
/** @var \RainLab\Location\Models\Country */
protected $obActiveCountry;
/** @var \RainLab\Location\Models\State */
protected $obActiveState;
/**
* Return flag "price include tax" from settings
* @return bool
*/
public function isPriceIncludeTax()
{
return $this->bPriceIncludeTax;
}
/**
* Switch active country by code
* @param string $sCountryCode
*/
public function switchCountry($sCountryCode)
{
if (empty($sCountryCode) || !PluginManager::instance()->hasPlugin('RainLab.Location')) {
return;
}
$this->obActiveCountry = \RainLab\Location\Models\Country::whereCode($sCountryCode)->first();
}
/**
* Get active country object
* @return \RainLab\Location\Models\Country
*/
public function getActiveCountry()
{
return $this->obActiveCountry;
}
/**
* Switch active state by code
* @param string $sStateCode
*/
public function switchState($sStateCode)
{
if (empty($sStateCode) || !PluginManager::instance()->hasPlugin('RainLab.Location')) {
return;
}
$this->obActiveState = \RainLab\Location\Models\State::whereCode($sStateCode)->first();
}
/**
* Get active state object
* @return \RainLab\Location\Models\State
*/
public function getActiveState()
{
return $this->obActiveState;
}
/**
* Get applied tax list
* @return \Lovata\Shopaholic\Classes\Collection\TaxCollection|\Lovata\Shopaholic\Classes\Item\TaxItem[]
*/
public function getTaxList()
{
return clone $this->obTaxList;
}
/**
* Get price value without tax
* @param float $fPrice
* @param float $fPricePercent
* @return float
*/
public function getPriceWithoutTax($fPrice, $fPricePercent)
{
$fPriceResult = $fPrice;
if ($this->bPriceIncludeTax) {
$fPriceResult = $this->calculatePriceWithoutTax($fPrice, $fPricePercent);
}
return $fPriceResult;
}
/**
* Get price value with tax
* @param float $fPrice
* @param float $fPricePercent
* @return float
*/
public function getPriceWithTax($fPrice, $fPricePercent)
{
$fPriceResult = $fPrice;
if (!$this->bPriceIncludeTax) {
$fPriceResult = $this->calculatePriceWithTax($fPrice, $fPricePercent);
}
return $fPriceResult;
}
/**
* Calculate price + tax
* @param float $fPrice
* @param float $fTax
* @return float
*/
public function calculatePriceWithTax($fPrice, $fTax)
{
$fPrice = ($fPrice * (100 + $fTax)) / 100;
$fPrice = PriceHelper::round($fPrice);
return $fPrice;
}
/**
* Calculate price - tax
* @param float $fPrice
* @param float $fTax
* @return float
*/
public function calculatePriceWithoutTax($fPrice, $fTax)
{
$fPrice = ($fPrice * 100) / (100 + $fTax);
$fPrice = PriceHelper::round($fPrice);
return $fPrice;
}
/**
* Get tax percent
* @param \Lovata\Shopaholic\Classes\Collection\TaxCollection|\Lovata\Shopaholic\Classes\Item\TaxItem[] $obTaxList
* @return float
*/
public function getTaxPercent($obTaxList)
{
if (empty($obTaxList) || $obTaxList->isEmpty()) {
return 0;
}
//Calculate tax percent
$fTaxPercent = 0;
foreach ($obTaxList as $obTaxItem) {
$fTaxPercent += $obTaxItem->percent;
}
$fTaxPercent = PriceHelper::round($fTaxPercent);
return $fTaxPercent;
}
/**
* Init currency data
*/
protected function init()
{
$this->obTaxList = TaxCollection::make()->active()->sort();
$this->bPriceIncludeTax = (bool) Settings::getValue('price_include_tax');
}
}

View File

@ -0,0 +1,49 @@
<?php namespace Lovata\Shopaholic\Classes\Import;
use Lovata\Toolbox\Classes\Helper\AbstractImportModelFromCSV;
use Lovata\Shopaholic\Models\Brand;
/**
* Class ImportBrandModelFromCSV
* @package Lovata\Shopaholic\Classes\Import
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ImportBrandModelFromCSV extends AbstractImportModelFromCSV
{
const MODEL_CLASS = Brand::class;
/** @var Brand */
protected $obModel;
/**
* ImportBrandModelFromCSV constructor.
*/
public function __construct()
{
$this->arExistIDList = (array) Brand::whereNotNull('external_id')->lists('external_id', 'id');
$this->arExistIDList = array_filter($this->arExistIDList);
}
/**
* Prepare array of import data
*/
protected function prepareImportData()
{
$this->setActiveField();
$this->initPreviewImage();
$this->initImageList();
parent::prepareImportData();
}
/**
* Process model object after creation/updating
*/
protected function processModelObject()
{
$this->importPreviewImage();
$this->importImageList();
}
}

View File

@ -0,0 +1,114 @@
<?php namespace Lovata\Shopaholic\Classes\Import;
use Lang;
use Lovata\Toolbox\Classes\Helper\AbstractImportModelFromXML;
use Lovata\Shopaholic\Models\Brand;
use Lovata\Shopaholic\Models\XmlImportSettings;
/**
* Class ImportBrandModelFromXML
* @package Lovata\Shopaholic\Classes\Import
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ImportBrandModelFromXML extends AbstractImportModelFromXML
{
const EXTEND_FIELD_LIST = 'shopaholic.brand.extend_xml_import_fields';
const EXTEND_IMPORT_DATA = 'shopaholic.brand.extend_xml_import_data';
const MODEL_CLASS = Brand::class;
/** @var Brand */
protected $obModel;
/**
* ImportBrandModelFromCSV constructor.
*/
public function __construct()
{
$this->arExistIDList = (array) Brand::whereNotNull('external_id')->lists('external_id', 'id');
$this->arExistIDList = array_filter($this->arExistIDList);
$this->prepareImportSettings();
parent::__construct();
}
/**
* Get import fields
* @return array
*/
public function getFields() : array
{
$this->arFieldList = [
'external_id' => Lang::get('lovata.toolbox::lang.field.external_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'),
'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'),
];
return parent::getFields();
}
/**
* Start import
* @param $obProgressBar
* @throws
*/
public function import($obProgressBar = null)
{
parent::import($obProgressBar);
$this->deactivateElements();
}
/**
* Prepare array of import data
*/
protected function prepareImportData()
{
$this->setActiveField();
$this->initPreviewImage();
$this->initImageList();
parent::prepareImportData();
}
/**
* Process model object after creation/updating
*/
protected function processModelObject()
{
$this->importPreviewImage();
$this->importImageList();
parent::processModelObject();
}
/**
* Prepare import settings
*/
protected function prepareImportSettings()
{
$this->arXMLFileList = XmlImportSettings::getValue('file_list');
$this->sImageFolderPath = XmlImportSettings::getValue('image_folder');
$this->sImageFolderPath = trim($this->sImageFolderPath, '/');
$this->bDeactivate = (bool) XmlImportSettings::getValue('brand_deactivate');
$this->arImportSettings = XmlImportSettings::getValue('brand');
$this->sElementListPath = XmlImportSettings::getValue('brand_path_to_list');
$iFileNumber = XmlImportSettings::getValue('brand_file_path');
if ($iFileNumber !== null) {
$this->sMainFilePath = array_get($this->arXMLFileList, $iFileNumber.'.path');
$this->sPrefix = array_get($this->arXMLFileList, $iFileNumber.'.path_prefix');
$this->sNamespace = array_get($this->arXMLFileList, $iFileNumber.'.file_namespace');
$this->sMainFilePath = trim($this->sMainFilePath, '/');
}
}
}

View File

@ -0,0 +1,81 @@
<?php namespace Lovata\Shopaholic\Classes\Import;
use Lovata\Toolbox\Classes\Helper\AbstractImportModelFromCSV;
use Lovata\Shopaholic\Models\Category;
/**
* Class ImportCategoryModelFromCSV
* @package Lovata\Shopaholic\Classes\Import
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ImportCategoryModelFromCSV extends AbstractImportModelFromCSV
{
const MODEL_CLASS = Category::class;
/** @var Category */
protected $obParentCategory;
/** @var Category */
protected $obModel;
/**
* ImportCategoryModelFromCSV constructor.
*/
public function __construct()
{
$this->arExistIDList = (array) Category::whereNotNull('external_id')->lists('external_id', 'id');
$this->arExistIDList = array_filter($this->arExistIDList);
}
/**
* Prepare array of import data
*/
protected function prepareImportData()
{
$this->initParentCategory();
$this->setActiveField();
$this->initPreviewImage();
$this->initImageList();
parent::prepareImportData();
}
/**
* Process model object after creation/updating
*/
protected function processModelObject()
{
if ($this->obParentCategory === false) {
$this->obModel->parent_id = null;
$this->obModel->save();
} elseif (!empty($this->obParentCategory)) {
$this->obModel->makeChildOf($this->obParentCategory);
}
$this->importPreviewImage();
$this->importImageList();
}
/**
* Find parent category by external ID and set parent_id
*/
protected function initParentCategory()
{
if (!array_key_exists('parent_id', $this->arImportData)) {
return;
}
$iParentID = array_get($this->arImportData, 'parent_id');
array_forget($this->arImportData, 'parent_id');
if (empty($iParentID)) {
$this->obParentCategory = false;
return;
}
//Find parent category
$this->obParentCategory = Category::getByExternalID($iParentID)->first();
}
}

View File

@ -0,0 +1,194 @@
<?php namespace Lovata\Shopaholic\Classes\Import;
use Lang;
use Lovata\Toolbox\Classes\Helper\AbstractImportModelFromXML;
use Lovata\Shopaholic\Models\Category;
use Lovata\Shopaholic\Models\XmlImportSettings;
/**
* Class ImportCategoryModelFromXML
* @package Lovata\Shopaholic\Classes\Import
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ImportCategoryModelFromXML extends AbstractImportModelFromXML
{
const EXTEND_FIELD_LIST = 'shopaholic.category.extend_xml_import_fields';
const EXTEND_IMPORT_DATA = 'shopaholic.category.extend_xml_import_data';
const PARSE_NODE_CLASS = ParseCategoryXMLNode::class;
const MODEL_CLASS = Category::class;
/** @var Category */
protected $obParentCategory;
/** @var array */
protected $arChildrenCategoryList;
/** @var Category */
protected $obModel;
protected $bHasChildrenField = false;
/**
* ImportCategoryModelFromCSV constructor.
*/
public function __construct()
{
$this->arExistIDList = (array) Category::whereNotNull('external_id')->lists('external_id', 'id');
$this->arExistIDList = array_filter($this->arExistIDList);
$this->prepareImportSettings();
parent::__construct();
}
/**
* Get import fields
* @return array
*/
public function getFields() : array
{
$this->arFieldList = [
'external_id' => Lang::get('lovata.toolbox::lang.field.external_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'),
'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'),
'parent_id' => Lang::get('lovata.toolbox::lang.field.category_parent_id'),
'children' => Lang::get('lovata.toolbox::lang.field.children_category'),
];
return parent::getFields();
}
/**
* Start import
* @param $obProgressBar
* @throws
*/
public function import($obProgressBar = null)
{
parent::import($obProgressBar);
$this->deactivateElements();
}
/**
* Prepare array of import data
*/
protected function prepareImportData()
{
$this->initParentCategory();
$this->setActiveField();
$this->initPreviewImage();
$this->initImageList();
$this->initChildrenCategoryList();
parent::prepareImportData();
}
/**
* Process model object after creation/updating
*/
protected function processModelObject()
{
if ($this->obParentCategory === false || ($this->bHasChildrenField && empty($this->obParentCategory))) {
$this->obModel->parent_id = null;
$this->obModel->save();
} elseif (!empty($this->obParentCategory)) {
$this->obModel->makeChildOf($this->obParentCategory);
}
$this->importPreviewImage();
$this->importImageList();
parent::processModelObject();
$this->importChildrenCategoryList();
}
/**
* Find parent category by external ID and set parent_id
*/
protected function initParentCategory()
{
if (!array_key_exists('parent_id', $this->arImportData) && !$this->bHasChildrenField) {
return;
}
$iParentID = array_get($this->arImportData, 'parent_id');
array_forget($this->arImportData, 'parent_id');
if (empty($iParentID)) {
$this->obParentCategory = false;
return;
}
//Find parent category
$this->obParentCategory = Category::getByExternalID($iParentID)->first();
}
/**
* Init children category list
*/
protected function initChildrenCategoryList()
{
if (!array_key_exists('children', $this->arImportData)) {
return;
}
$this->arChildrenCategoryList = array_get($this->arImportData, 'children');
array_forget($this->arImportData, 'children');
}
/**
* Import children category list
*/
protected function importChildrenCategoryList()
{
if (empty($this->arChildrenCategoryList)) {
return;
}
$iExternalID = $this->obModel->external_id;
foreach ($this->arChildrenCategoryList as $arCategoryData) {
$arCategoryData['parent_id'] = $iExternalID;
$this->importRow($arCategoryData);
}
}
/**
* Prepare import settings
*/
protected function prepareImportSettings()
{
$this->arXMLFileList = XmlImportSettings::getValue('file_list');
$this->sImageFolderPath = XmlImportSettings::getValue('image_folder');
$this->sImageFolderPath = trim($this->sImageFolderPath, '/');
$this->bDeactivate = (bool) XmlImportSettings::getValue('category_deactivate');
$this->arImportSettings = (array) XmlImportSettings::getValue('category');
$this->sElementListPath = XmlImportSettings::getValue('category_path_to_list');
$iFileNumber = XmlImportSettings::getValue('category_file_path');
if ($iFileNumber !== null) {
$this->sMainFilePath = array_get($this->arXMLFileList, $iFileNumber.'.path');
$this->sPrefix = array_get($this->arXMLFileList, $iFileNumber.'.path_prefix');
$this->sNamespace = array_get($this->arXMLFileList, $iFileNumber.'.file_namespace');
$this->sMainFilePath = trim($this->sMainFilePath, '/');
}
foreach ($this->arImportSettings as $arFieldData) {
if (array_get($arFieldData, 'field') == 'children') {
$this->bHasChildrenField = true;
break;
}
}
}
}

View File

@ -0,0 +1,152 @@
<?php namespace Lovata\Shopaholic\Classes\Import;
use Lovata\Toolbox\Classes\Helper\AbstractImportModelFromCSV;
use Lovata\Shopaholic\Models\Measure;
use Lovata\Shopaholic\Models\Offer;
use Lovata\Shopaholic\Models\Product;
/**
* Class ImportOfferModelFromCSV
* @package Lovata\Shopaholic\Classes\Import
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ImportOfferModelFromCSV extends AbstractImportModelFromCSV
{
const MODEL_CLASS = Offer::class;
/** @var Offer */
protected $obModel;
protected $bWithTrashed = true;
/**
* ImportOfferModelFromCSV constructor.
*/
public function __construct()
{
$this->arExistIDList = (array) Offer::whereNotNull('external_id')->lists('external_id', 'id');
$this->arExistIDList = array_filter($this->arExistIDList);
}
/**
* Prepare array of import data
*/
protected function prepareImportData()
{
$this->setActiveField();
$this->setProductField();
$this->setQuantityField();
$this->setMeasureField();
$this->setMeasureOfUnitField();
$this->initPreviewImage();
$this->initImageList();
parent::prepareImportData();
}
/**
* Process model object after creation/updating
*/
protected function processModelObject()
{
$this->importPreviewImage();
$this->importImageList();
}
/**
* Set product_id filed value
*/
protected function setProductField()
{
$sProductID = array_get($this->arImportData, 'product_id');
if ($sProductID === null) {
return;
}
if (empty($sProductID)) {
$this->arImportData['product_id'] = null;
return;
}
//Find product by external ID
$obProduct = Product::withTrashed()->getByExternalID($sProductID)->first();
if (empty($obProduct)) {
$this->arImportData['product_id'] = null;
} else {
$this->arImportData['product_id'] = $obProduct->id;
}
}
/**
* Set quantity field value
*/
protected function setQuantityField()
{
$iQuantity = array_get($this->arImportData, 'quantity');
if ($iQuantity === null) {
return;
}
$iQuantity = (int) $iQuantity;
if ($iQuantity < 0) {
$iQuantity = 0;
}
$this->arImportData['quantity'] = $iQuantity;
}
/**
* Set measure filed value
*/
protected function setMeasureOfUnitField()
{
$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;
}
/**
* Set measure filed value
*/
protected function setMeasureField()
{
$sMeasure = array_get($this->arImportData, 'measure_id');
array_forget($this->arImportData, 'measure_id');
if ($sMeasure === null) {
return;
}
if (empty($sMeasure)) {
$this->arImportData['measure_id'] = null;
return;
}
$obMeasure = Measure::getByName($sMeasure)->first();
if (empty($obMeasure)) {
$obMeasure = Measure::create([
'name' => $sMeasure,
]);
}
$this->arImportData['measure_id'] = $obMeasure->id;
}
}

View File

@ -0,0 +1,212 @@
<?php namespace Lovata\Shopaholic\Classes\Import;
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;
use Lovata\Shopaholic\Models\XmlImportSettings;
/**
* Class ImportOfferModelFromXML
* @package Lovata\Shopaholic\Classes\Import
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ImportOfferModelFromXML extends AbstractImportModelFromXML
{
const EXTEND_FIELD_LIST = 'shopaholic.offer.extend_xml_import_fields';
const EXTEND_IMPORT_DATA = 'shopaholic.offer.extend_xml_import_data';
const MODEL_CLASS = Offer::class;
/** @var Offer */
protected $obModel;
protected $bWithTrashed = true;
/**
* ImportOfferModelFromXML constructor.
*/
public function __construct()
{
$this->arExistIDList = (array) Offer::whereNotNull('external_id')->lists('external_id', 'id');
$this->arExistIDList = array_filter($this->arExistIDList);
$this->prepareImportSettings();
parent::__construct();
}
/**
* Get import fields
* @return array
*/
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'),
'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'),
'measure_id' => Lang::get('lovata.shopaholic::lang.field.measure'),
'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
$arPriceTypeList = (array) PriceType::lists('name', 'id');
if (!empty($arPriceTypeList)) {
foreach ($arPriceTypeList as $iPriceTypeID => $sName) {
$sKey = 'price_list.'.$iPriceTypeID;
$this->arFieldList[$sKey.'.price'] = Lang::get('lovata.shopaholic::lang.field.price')." ($sName)";
$this->arFieldList[$sKey.'.old_price'] = Lang::get('lovata.shopaholic::lang.field.old_price')." ($sName)";
}
}
return parent::getFields();
}
/**
* Start import
* @param $obProgressBar
* @throws
*/
public function import($obProgressBar = null)
{
parent::import($obProgressBar);
$this->deactivateElements();
}
/**
* Prepare array of import data
*/
protected function prepareImportData()
{
$this->setActiveField();
$this->setProductField();
$this->setQuantityField();
$this->setMeasureField();
$this->initPreviewImage();
$this->initImageList();
parent::prepareImportData();
}
/**
* Process model object after creation/updating
*/
protected function processModelObject()
{
$this->importPreviewImage();
$this->importImageList();
parent::processModelObject();
}
/**
* Set product_id filed value
*/
protected function setProductField()
{
$sProductID = array_get($this->arImportData, 'product_id');
if ($sProductID === null) {
return;
}
if (empty($sProductID)) {
$this->arImportData['product_id'] = null;
return;
}
//Find product by external ID
$obProduct = Product::withTrashed()->getByExternalID($sProductID)->first();
if (empty($obProduct)) {
$this->arImportData['product_id'] = null;
} else {
$this->arImportData['product_id'] = $obProduct->id;
}
}
/**
* Set quantity field value
*/
protected function setQuantityField()
{
$iQuantity = array_get($this->arImportData, 'quantity');
if ($iQuantity === null) {
return;
}
$iQuantity = (int) $iQuantity;
if ($iQuantity < 0) {
$iQuantity = 0;
}
$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
*/
protected function prepareImportSettings()
{
$this->arXMLFileList = XmlImportSettings::getValue('file_list');
$this->sImageFolderPath = XmlImportSettings::getValue('image_folder');
$this->sImageFolderPath = trim($this->sImageFolderPath, '/');
$this->bDeactivate = (bool) XmlImportSettings::getValue('offer_deactivate');
$this->arImportSettings = XmlImportSettings::getValue('offer');
$this->sElementListPath = XmlImportSettings::getValue('offer_path_to_list');
$iFileNumber = XmlImportSettings::getValue('offer_file_path');
if ($iFileNumber !== null) {
$this->sMainFilePath = array_get($this->arXMLFileList, $iFileNumber.'.path');
$this->sPrefix = array_get($this->arXMLFileList, $iFileNumber.'.path_prefix');
$this->sNamespace = array_get($this->arXMLFileList, $iFileNumber.'.file_namespace');
$this->sMainFilePath = trim($this->sMainFilePath, '/');
}
}
}

View File

@ -0,0 +1,127 @@
<?php namespace Lovata\Shopaholic\Classes\Import;
use Lang;
use Lovata\Toolbox\Classes\Helper\AbstractImportModelFromXML;
use Lovata\Shopaholic\Models\Offer;
use Lovata\Shopaholic\Models\PriceType;
use Lovata\Shopaholic\Models\XmlImportSettings;
/**
* Class ImportOfferPriceFromXML
* @package Lovata\Shopaholic\Classes\Import
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ImportOfferPriceFromXML extends AbstractImportModelFromXML
{
const EXTEND_FIELD_LIST = 'shopaholic.price.extend_xml_import_fields';
const EXTEND_IMPORT_DATA = 'shopaholic.price.extend_xml_import_data';
const MODEL_CLASS = Offer::class;
/** @var Offer */
protected $obModel;
protected $bWithTrashed = true;
/**
* ImportOfferModelFromXML constructor.
*/
public function __construct()
{
$this->arExistIDList = (array) Offer::whereNotNull('external_id')->lists('external_id', 'id');
$this->arExistIDList = array_filter($this->arExistIDList);
$this->prepareImportSettings();
parent::__construct();
}
/**
* Get import fields
* @return array
*/
public function getFields() : array
{
$this->arFieldList = [
'external_id' => Lang::get('lovata.toolbox::lang.field.external_id'),
'active' => Lang::get('lovata.toolbox::lang.field.active'),
'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'),
];
//Get price types
$arPriceTypeList = (array) PriceType::lists('name', 'id');
if (!empty($arPriceTypeList)) {
foreach ($arPriceTypeList as $iPriceTypeID => $sName) {
$sKey = 'price_list.'.$iPriceTypeID;
$this->arFieldList[$sKey.'.price'] = Lang::get('lovata.shopaholic::lang.field.price')." ($sName)";
$this->arFieldList[$sKey.'.old_price'] = Lang::get('lovata.shopaholic::lang.field.old_price')." ($sName)";
}
}
return parent::getFields();
}
/**
* Start import
* @param $obProgressBar
* @throws
*/
public function import($obProgressBar = null)
{
parent::import($obProgressBar);
$this->deactivateElements();
}
/**
* Prepare array of import data
*/
protected function prepareImportData()
{
$this->setActiveField();
$this->setQuantityField();
parent::prepareImportData();
}
/**
* Set quantity field value
*/
protected function setQuantityField()
{
$iQuantity = array_get($this->arImportData, 'quantity');
if ($iQuantity === null) {
return;
}
$iQuantity = (int) $iQuantity;
if ($iQuantity < 0) {
$iQuantity = 0;
}
$this->arImportData['quantity'] = $iQuantity;
}
/**
* Prepare import settings
*/
protected function prepareImportSettings()
{
$this->arXMLFileList = XmlImportSettings::getValue('file_list');
$this->sImageFolderPath = XmlImportSettings::getValue('image_folder');
$this->sImageFolderPath = trim($this->sImageFolderPath, '/');
$this->bDeactivate = (bool) XmlImportSettings::getValue('price_deactivate');
$this->arImportSettings = XmlImportSettings::getValue('price');
$this->sElementListPath = XmlImportSettings::getValue('price_path_to_list');
$iFileNumber = XmlImportSettings::getValue('price_file_path');
if ($iFileNumber !== null) {
$this->sMainFilePath = array_get($this->arXMLFileList, $iFileNumber.'.path');
$this->sMainFilePath = trim($this->sMainFilePath, '/');
}
}
}

View File

@ -0,0 +1,148 @@
<?php namespace Lovata\Shopaholic\Classes\Import;
use Lovata\Toolbox\Classes\Helper\AbstractImportModelFromCSV;
use Lovata\Shopaholic\Models\Brand;
use Lovata\Shopaholic\Models\Category;
use Lovata\Shopaholic\Models\Product;
/**
* Class ImportProductModelFromCSV
* @package Lovata\Shopaholic\Classes\Import
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ImportProductModelFromCSV extends AbstractImportModelFromCSV
{
const MODEL_CLASS = Product::class;
/** @var Product */
protected $obModel;
protected $bWithTrashed = true;
protected $arAdditionalCategoryList = null;
/**
* ImportProductModelFromCSV constructor.
*/
public function __construct()
{
$this->arExistIDList = (array) Product::whereNotNull('external_id')->lists('external_id', 'id');
$this->arExistIDList = array_filter($this->arExistIDList);
}
/**
* Prepare array of import data
*/
protected function prepareImportData()
{
$this->setActiveField();
$this->setBrandField();
$this->setCategoryField();
$this->initPreviewImage();
$this->initImageList();
$this->initAdditionalCategoryField();
parent::prepareImportData();
}
/**
* Process model object after creation/updating
*/
protected function processModelObject()
{
$this->importPreviewImage();
$this->importImageList();
$this->syncAdditionalCategoryList();
}
/**
* Set brand_id filed value
*/
protected function setBrandField()
{
$sBrandID = array_get($this->arImportData, 'brand_id');
if ($sBrandID === null) {
return;
}
if (empty($sBrandID)) {
$this->arImportData['brand_id'] = null;
return;
}
//Find brand by external ID
$obBrand = Brand::getByExternalID($sBrandID)->first();
if (empty($obBrand)) {
$this->arImportData['brand_id'] = null;
} else {
$this->arImportData['brand_id'] = $obBrand->id;
}
}
/**
* Set category_id filed value
*/
protected function setCategoryField()
{
$sCategoryID = array_get($this->arImportData, 'category_id');
if ($sCategoryID === null) {
return;
}
if (empty($sCategoryID)) {
$this->arImportData['category_id'] = null;
return;
}
//Find category by external ID
$obCategory = Category::getByExternalID($sCategoryID)->first();
if (empty($obCategory)) {
$this->arImportData['category_id'] = null;
} else {
$this->arImportData['category_id'] = $obCategory->id;
}
}
/**
* Init additional category ID list
*/
protected function initAdditionalCategoryField()
{
$sCategoryList = array_get($this->arImportData, 'additional_category');
if ($sCategoryList === null) {
return;
}
$arCategoryIDList = explode(',', $sCategoryList);
foreach ($arCategoryIDList as $iKey => &$iCategoryID) {
$iCategoryID = trim($iCategoryID);
if (empty($iCategoryID)) {
unset($arCategoryIDList[$iKey]);
}
}
if (empty($arCategoryIDList)) {
$this->arAdditionalCategoryList = [];
return;
}
$this->arAdditionalCategoryList = (array) Category::whereIn('external_id', $arCategoryIDList)->lists('id');
}
/**
* Sync link product with additional categories
*/
protected function syncAdditionalCategoryList()
{
if ($this->arAdditionalCategoryList === null) {
return;
}
$this->obModel->additional_category()->sync($this->arAdditionalCategoryList);
}
}

View File

@ -0,0 +1,224 @@
<?php namespace Lovata\Shopaholic\Classes\Import;
use Lang;
use Lovata\Toolbox\Classes\Helper\AbstractImportModelFromXML;
use Lovata\Shopaholic\Models\Brand;
use Lovata\Shopaholic\Models\Category;
use Lovata\Shopaholic\Models\Product;
use Lovata\Shopaholic\Models\XmlImportSettings;
/**
* Class ImportProductModelFromXML
* @package Lovata\Shopaholic\Classes\Import
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ImportProductModelFromXML extends AbstractImportModelFromXML
{
const EXTEND_FIELD_LIST = 'shopaholic.product.extend_xml_import_fields';
const EXTEND_IMPORT_DATA = 'shopaholic.product.extend_xml_import_data';
const MODEL_CLASS = Product::class;
/** @var Product */
protected $obModel;
protected $bWithTrashed = true;
protected $arAdditionalCategoryList = null;
/**
* ImportProductModelFromXML constructor.
*/
public function __construct()
{
$this->arExistIDList = (array) Product::whereNotNull('external_id')->lists('external_id', 'id');
$this->arExistIDList = array_filter($this->arExistIDList);
$this->prepareImportSettings();
parent::__construct();
}
/**
* Get import fields
* @return array
*/
public function getFields() : array
{
$this->arFieldList = [
'external_id' => Lang::get('lovata.toolbox::lang.field.external_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'),
'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'),
'brand_id' => Lang::get('lovata.shopaholic::lang.field.brand'),
'category_id' => Lang::get('lovata.toolbox::lang.field.category'),
'additional_category' => Lang::get('lovata.shopaholic::lang.field.additional_category'),
];
return parent::getFields();
}
/**
* Start import
* @param $obProgressBar
* @throws
*/
public function import($obProgressBar = null)
{
parent::import($obProgressBar);
$this->deactivateElements();
}
/**
* Prepare array of import data
*/
protected function prepareImportData()
{
$this->setActiveField();
$this->setBrandField();
$this->setCategoryField();
$this->initPreviewImage();
$this->initImageList();
$this->initAdditionalCategoryField();
parent::prepareImportData();
}
/**
* Process model object after creation/updating
*/
protected function processModelObject()
{
$this->importPreviewImage();
$this->importImageList();
$this->syncAdditionalCategoryList();
parent::processModelObject();
}
/**
* Set brand_id filed value
*/
protected function setBrandField()
{
$sBrandID = array_get($this->arImportData, 'brand_id');
if ($sBrandID === null) {
return;
}
if (empty($sBrandID)) {
$this->arImportData['brand_id'] = null;
return;
}
//Find brand by external ID
$obBrand = Brand::getByExternalID($sBrandID)->first();
if (empty($obBrand)) {
$this->arImportData['brand_id'] = null;
} else {
$this->arImportData['brand_id'] = $obBrand->id;
}
}
/**
* Set category_id filed value
*/
protected function setCategoryField()
{
$sCategoryID = array_get($this->arImportData, 'category_id');
if ($sCategoryID === null) {
return;
}
if (empty($sCategoryID)) {
$this->arImportData['category_id'] = null;
return;
}
if (is_array($sCategoryID)) {
$sCategoryID = array_shift($sCategoryID);
}
//Find category by external ID
$obCategory = Category::getByExternalID($sCategoryID)->first();
if (empty($obCategory)) {
$this->arImportData['category_id'] = null;
} else {
$this->arImportData['category_id'] = $obCategory->id;
}
}
/**
* Init additional category ID list
*/
protected function initAdditionalCategoryField()
{
$arCategoryIDList = (array) array_get($this->arImportData, 'additional_category');
$arCategoryIDList = array_filter($arCategoryIDList);
if (empty($arCategoryIDList)) {
return;
}
$iMainCategoryID = array_get($this->arImportData, 'category_id');
array_forget($this->arImportData, 'additional_category');
foreach ($arCategoryIDList as $iKey => &$iCategoryID) {
$iCategoryID = trim($iCategoryID);
if (empty($iCategoryID)) {
unset($arCategoryIDList[$iKey]);
}
}
if (empty($arCategoryIDList)) {
$this->arAdditionalCategoryList = [];
return;
}
$this->arAdditionalCategoryList = (array) Category::whereIn('external_id', $arCategoryIDList)->where('id', '!=', $iMainCategoryID)->lists('id');
}
/**
* Sync link product with additional categories
*/
protected function syncAdditionalCategoryList()
{
if ($this->arAdditionalCategoryList === null) {
return;
}
$this->obModel->additional_category()->sync($this->arAdditionalCategoryList);
}
/**
* Prepare import settings
*/
protected function prepareImportSettings()
{
$this->arXMLFileList = XmlImportSettings::getValue('file_list');
$this->sImageFolderPath = XmlImportSettings::getValue('image_folder');
$this->sImageFolderPath = trim($this->sImageFolderPath, '/');
$this->bDeactivate = (bool) XmlImportSettings::getValue('product_deactivate');
$this->arImportSettings = XmlImportSettings::getValue('product');
$this->sElementListPath = XmlImportSettings::getValue('product_path_to_list');
$iFileNumber = XmlImportSettings::getValue('product_file_path');
if ($iFileNumber !== null) {
$this->sMainFilePath = array_get($this->arXMLFileList, $iFileNumber.'.path');
$this->sPrefix = array_get($this->arXMLFileList, $iFileNumber.'.path_prefix');
$this->sNamespace = array_get($this->arXMLFileList, $iFileNumber.'.file_namespace');
$this->sMainFilePath = trim($this->sMainFilePath, '/');
}
}
}

View File

@ -0,0 +1,34 @@
<?php namespace Lovata\Shopaholic\Classes\Import;
use Lovata\Toolbox\Classes\Helper\ParseXMLNode;
/**
* Class ParseCategoryXMLNode
* @package Lovata\Shopaholic\Classes\Import
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ParseCategoryXMLNode extends ParseXMLNode
{
/**
* Parse children categories
* @param string $sFieldPath
* @return array
*/
protected function parseChildrenAttribute($sFieldPath)
{
$arResult = [];
//Get children node list
$arNodeList = $this->obElementNode->findListByPath($sFieldPath);
if (empty($arNodeList)) {
return $arResult;
}
foreach ($arNodeList as $obCategoryNode) {
$obParseNode = new ParseCategoryXMLNode($obCategoryNode, $this->arImportSettings);
$arResult[] = $obParseNode->get();
}
return $arResult;
}
}

View File

@ -0,0 +1,84 @@
<?php namespace Lovata\Shopaholic\Classes\Item;
use Cms\Classes\Page as CmsPage;
use Lovata\Toolbox\Classes\Item\ElementItem;
use Lovata\Toolbox\Classes\Helper\PageHelper;
use Lovata\Shopaholic\Models\Settings;
use Lovata\Shopaholic\Models\Brand;
/**
* Class BrandItem
* @package Lovata\Shopaholic\Classes\Item
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* @property int $id
* @property string $name
* @property string $slug
* @property string $code
*
* @property string $preview_text
* @property \System\Models\File $preview_image
* @property \System\Models\File $icon
*
* @property string $description
* @property \October\Rain\Database\Collection|\System\Models\File[] $images
*/
class BrandItem extends ElementItem
{
const MODEL_CLASS = Brand::class;
public static $arQueryWith = ['preview_image', 'icon', 'images'];
/** @var Brand */
protected $obElement = null;
/**
* Returns URL of a brand page.
*
* @param string|null $sPageCode
* @param array $arRemoveParamList
*
* @return string
*/
public function getPageUrl($sPageCode = null, $arRemoveParamList = [])
{
if (empty($sPageCode)) {
$sPageCode = Settings::getValue('default_brand_page_id', 'brand');
}
//Get URL params
$arParamList = $this->getPageParamList($sPageCode, $arRemoveParamList);
//Generate page URL
$sURL = CmsPage::url($sPageCode, $arParamList);
return $sURL;
}
/**
* Get URL param list by page code
* @param string $sPageCode
* @param array $arRemoveParamList
* @return array
*/
public function getPageParamList($sPageCode, $arRemoveParamList = []) : array
{
$arResult = [];
if (!empty($arRemoveParamList)) {
foreach ($arRemoveParamList as $sParamName) {
$arResult[$sParamName] = null;
}
}
//Get URL params for page
$arParamList = PageHelper::instance()->getUrlParamList($sPageCode, 'BrandPage');
if (!empty($arParamList)) {
$sPageParam = array_shift($arParamList);
$arResult[$sPageParam] = $this->slug;
}
return $arResult;
}
}

View File

@ -0,0 +1,259 @@
<?php namespace Lovata\Shopaholic\Classes\Item;
use Cms\Classes\Page as CmsPage;
use Kharanenka\Helper\CCache;
use Lovata\Toolbox\Classes\Item\ItemStorage;
use Lovata\Toolbox\Classes\Item\ElementItem;
use Lovata\Toolbox\Classes\Helper\PageHelper;
use Lovata\Shopaholic\Models\Settings;
use Lovata\Shopaholic\Models\Category;
use Lovata\Shopaholic\Classes\Collection\ProductCollection;
use Lovata\Shopaholic\Classes\Collection\CategoryCollection;
/**
* Class CategoryItem
* @package Lovata\Shopaholic\Classes\Item
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* @property $id
* @property string $name
* @property string $slug
* @property string $code
* @property int $nest_depth
* @property int $parent_id
* @property int $product_count
*
* @property string $preview_text
* @property \System\Models\File $preview_image
* @property \System\Models\File $icon
*
* @property string $description
* @property \October\Rain\Database\Collection|\System\Models\File[] $images
*
* @property \October\Rain\Argon\Argon $updated_at
*
* @property CategoryItem $parent
*
* @property array $children_id_list
* @property CategoryCollection|CategoryItem[] $children
*
* Properties for Shopaholic
* @see \Lovata\PropertiesShopaholic\Classes\Event\CategoryModelHandler::extendCategoryItem
*
* @property bool $inherit_property_set
* @property array $property_set_id
* @property \Lovata\PropertiesShopaholic\Classes\Collection\PropertySetCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertySetItem[] $property_set
*
* @property array $product_property_list
* @property \Lovata\PropertiesShopaholic\Classes\Collection\PropertyCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertyItem[] $product_property
*
* @property array $offer_property_list
* @property \Lovata\PropertiesShopaholic\Classes\Collection\PropertyCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertyItem[] $offer_property
*
* Filter for Shopaholic
* @property \Lovata\FilterShopaholic\Classes\Collection\FilterPropertyCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertyItem[] $product_filter_property
* @property \Lovata\FilterShopaholic\Classes\Collection\FilterPropertyCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertyItem[] $offer_filter_property
*
* VKontakte for Shopaholic
* @property int $category_vk_id
*/
class CategoryItem extends ElementItem
{
const MODEL_CLASS = Category::class;
public static $arQueryWith = ['preview_image', 'icon', 'images'];
/** @var Category */
protected $obElement = null;
public $arRelationList = [
'parent' => [
'class' => CategoryItem::class,
'field' => 'parent_id',
],
'children' => [
'class' => CategoryCollection::class,
'field' => 'children_id_list',
],
];
/**
* Clear product count cache
*/
public function clearProductCount()
{
$arCacheTag = [static::class];
$sCacheKey = 'product_count_'.$this->id;
CCache::clear($arCacheTag, $sCacheKey);
ItemStorage::clear(static::class, $this->id);
$obParentItem = $this->parent;
if ($obParentItem->isEmpty()) {
return;
}
$obParentItem->clearProductCount();
}
/**
* Returns URL of a category page.
*
* @param string|null $sPageCode
* @param array $arRemoveParamList
*
* @return string
*/
public function getPageUrl($sPageCode = null, $arRemoveParamList = [])
{
if (empty($sPageCode)) {
$sPageCode = Settings::getValue('default_category_page_id', 'catalog');
}
//Get URL params
$arParamList = $this->getPageParamList($sPageCode, $arRemoveParamList);
//Generate page URL
$sURL = CmsPage::url($sPageCode, $arParamList);
return $sURL;
}
/**
* Get URL param list by page code
* @param string $sPageCode
* @param array $arRemoveParamList
* @return array
*/
public function getPageParamList($sPageCode, $arRemoveParamList = []) : array
{
$arResult = [];
if (!empty($arRemoveParamList)) {
foreach ($arRemoveParamList as $sParamName) {
$arResult[$sParamName] = null;
}
}
//Get all slug params
$arParamList = PageHelper::instance()->getUrlParamList($sPageCode, null);
if (!empty($arParamList)) {
foreach ($arParamList as $sParamName) {
$arResult[$sParamName] = null;
}
}
//Get URL params for page
$arParamList = PageHelper::instance()->getUrlParamList($sPageCode, 'CategoryPage');
if (empty($arParamList)) {
return [];
}
//Get slug list
$arSlugList = $this->getSlugList();
$arWildcardParamList = PageHelper::instance()->getUrlParamList($sPageCode, 'CategoryPage', 'slug', true);
if (!empty($arWildcardParamList)) {
$arSlugList = array_reverse($arSlugList);
$arResult[array_shift($arWildcardParamList)] = implode('/', $arSlugList);
return $arResult;
} elseif (count($arParamList) == 1) {
$sParamName = array_shift($arParamList);
$arResult[$sParamName] = array_shift($arSlugList);
return $arResult;
}
//Prepare page property list
$arSlugList = array_reverse($arSlugList);
$arParamList = array_reverse($arParamList);
foreach ($arParamList as $sParamName) {
if (!empty($arSlugList)) {
$arResult[$sParamName] = array_shift($arSlugList);
}
}
return $arResult;
}
/**
* Get array with categories slugs
* @return array
*/
protected function getSlugList() : array
{
$arResult = [$this->slug];
$obParentCategory = $this->parent;
while ($obParentCategory->isNotEmpty()) {
$arResult[] = $obParentCategory->slug;
$obParentCategory = $obParentCategory->parent;
}
return $arResult;
}
/**
* Set element data from model object
*
* @return array
*/
protected function getElementData()
{
$arResult = [
'nest_depth' => $this->obElement->getDepth(),
];
$arResult['children_id_list'] = $this->obElement->children()
->active()
->orderBy('nest_left', 'asc')
->lists('id');
return $arResult;
}
/**
* Get product count for category
* @return int
*/
protected function getProductCountAttribute()
{
$iProductCount = $this->getAttribute('product_count');
if ($iProductCount !== null) {
return $iProductCount;
}
//Get product count from cache
$arCacheTag = [static::class];
$sCacheKey = 'product_count_'.$this->id;
$iProductCount = CCache::get($arCacheTag, $sCacheKey);
if ($iProductCount !== null) {
return $iProductCount;
}
//Calculate product count from child categories
$iProductCount = 0;
$obChildCategoryCollect = $this->children;
if ($obChildCategoryCollect->isNotEmpty()) {
/** @var CategoryItem $obChildCategoryItem */
foreach ($obChildCategoryCollect as $obChildCategoryItem) {
if ($obChildCategoryItem->isEmpty()) {
continue;
}
$iProductCount += $obChildCategoryItem->product_count;
}
}
$iProductCount += ProductCollection::make()->active()->category($this->id)->count();
CCache::forever($arCacheTag, $sCacheKey, $iProductCount);
$this->setAttribute('product_count', $iProductCount);
return $iProductCount;
}
}

View File

@ -0,0 +1,37 @@
<?php namespace Lovata\Shopaholic\Classes\Item;
use Lovata\Toolbox\Classes\Item\ElementItem;
use Lovata\Shopaholic\Models\Currency;
use Lovata\Shopaholic\Classes\Helper\CurrencyHelper;
/**
* Class CurrencyItem
* @package Lovata\Shopaholic\Classes\Item
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* @property int $id
* @property bool $is_default
* @property string $name
* @property string $code
* @property string $symbol
* @property float $rate
*/
class CurrencyItem extends ElementItem
{
const MODEL_CLASS = Currency::class;
/** @var Currency */
protected $obElement = null;
/**
* Check, currency is active
* @return bool
*/
public function isActive()
{
$bResult = $this->code == CurrencyHelper::instance()->getActiveCurrencyCode();
return $bResult;
}
}

View File

@ -0,0 +1,24 @@
<?php namespace Lovata\Shopaholic\Classes\Item;
use Lovata\Shopaholic\Models\Measure;
use Lovata\Toolbox\Classes\Item\ElementItem;
/**
* Class MeasureItem
* @package Lovata\Shopaholic\Classes\Item
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* @see \Lovata\Shopaholic\Tests\Unit\Item\MeasureItemTest
*
* @property int $id
* @property string $name
* @property string $code
*/
class MeasureItem extends ElementItem
{
const MODEL_CLASS = Measure::class;
/** @var Measure */
protected $obElement = null;
}

View File

@ -0,0 +1,506 @@
<?php namespace Lovata\Shopaholic\Classes\Item;
use Lovata\Toolbox\Classes\Helper\PriceHelper;
use Lovata\Toolbox\Classes\Item\ElementItem;
use Lovata\Toolbox\Traits\Helpers\PriceHelperTrait;
use Lovata\Shopaholic\Classes\Helper\MeasureHelper;
use Lovata\Shopaholic\Models\Offer;
use Lovata\Shopaholic\Models\Settings;
use Lovata\Shopaholic\Classes\Helper\TaxHelper;
use Lovata\Shopaholic\Classes\Helper\CurrencyHelper;
use Lovata\Shopaholic\Classes\Helper\PriceTypeHelper;
/**
* Class OfferItem
* @package Lovata\Shopaholic\Classes\Item
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* @property int $id
* @property bool $active
* @property bool $trashed
* @property string $name
* @property string $code
* @property int $product_id
* @property ProductItem $product
* @property double $weight
* @property double $height
* @property double $length
* @property double $width
* @property double $quantity_in_unit
* @property int $measure_id
* @property MeasureItem $measure
* @property int $measure_of_unit_id
* @property MeasureItem $measure_of_unit
* @property MeasureItem $dimensions_measure
* @property MeasureItem $weight_measure
*
* @property string $preview_text
* @property \System\Models\File $preview_image
*
* @property string $description
* @property \October\Rain\Database\Collection|\System\Models\File[] $images
*
* @property string $price
* @property float $price_value
* @property string $tax_price
* @property float $tax_price_value
* @property string $price_without_tax
* @property float $price_without_tax_value
* @property string $price_with_tax
* @property float $price_with_tax_value
*
* @property string $old_price
* @property float $old_price_value
* @property string $tax_old_price
* @property float $tax_old_price_value
* @property string $old_price_without_tax
* @property float $old_price_without_tax_value
* @property string $old_price_with_tax
* @property float $old_price_with_tax_value
*
* @property string $discount_price
* @property float $discount_price_value
* @property string $tax_discount_price
* @property float $tax_discount_price_value
* @property string $discount_price_without_tax
* @property float $discount_price_without_tax_value
* @property string $discount_price_with_tax
* @property float $discount_price_with_tax_value
*
* @property array $price_list
* @property string $currency
* @property string $currency_code
*
* @property float $tax_percent
* @property \Lovata\Shopaholic\Classes\Collection\TaxCollection|\Lovata\Shopaholic\Classes\Item\TaxItem[] $tax_list
*
* @property int $quantity
*
* Properties for Shopaholic
* @see \Lovata\PropertiesShopaholic\Classes\Event\OfferModelHandler::extendOfferItem
* @property array $property_value_array
* @property \Lovata\PropertiesShopaholic\Classes\Collection\PropertyCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertyItem[] $property
*
* Discounts for Shopaholic
* @property int $discount_id
* @property float $discount_value
* @property string $discount_type
*
* Subscriptions for Shopaholic
* @property int $subscription_period_id
* @property \Lovata\SubscriptionsShopaholic\Classes\Item\SubscriptionPeriodItem $subscription_period
*
* YandexMarket for Shopaholic
* @property \System\Models\File $preview_image_yandex
* @property \October\Rain\Database\Collection|\System\Models\File[] $images_yandex
*
* Facebook for Shopaholic
* @property \System\Models\File $preview_image_facebook
* @property \October\Rain\Database\Collection|\System\Models\File[] $images_facebook
*
* VKontakte for Shopaholic
* @property \System\Models\File $preview_image_vkontakte
* @property \October\Rain\Database\Collection|\System\Models\File[] $images_vkontakte
*
* Downloadable file for Shopaholic
* @property \October\Rain\Database\Collection|\System\Models\File[] $downloadable_file
*/
class OfferItem extends ElementItem
{
use PriceHelperTrait;
const MODEL_CLASS = Offer::class;
public static $arQueryWith = ['preview_image', 'images', 'main_price', 'price_link'];
/** @var Offer */
protected $obElement = null;
public $arRelationList = [
'product' => [
'class' => ProductItem::class,
'field' => 'product_id',
],
'measure' => [
'class' => MeasureItem::class,
'field' => 'measure_id',
],
];
public $arPriceField = [
'price',
'tax_price',
'price_without_tax',
'price_with_tax',
'old_price',
'tax_old_price',
'old_price_without_tax',
'old_price_with_tax',
'discount_price',
'tax_discount_price',
'discount_price_without_tax',
'discount_price_with_tax',
];
protected $iActivePriceType = null;
protected $sActiveCurrency = null;
/**
* Check element, active == true, trashed == false
* @return bool
*/
public function isActive()
{
return $this->active && !$this->trashed;
}
/**
* Set active price type
* @param int $iPriceTypeID
* @return OfferItem
*/
public function setActivePriceType($iPriceTypeID)
{
$this->iActivePriceType = $iPriceTypeID;
return $this;
}
/**
* Set active currency code
* @param string $sActiveCurrencyCode
* @return OfferItem
*/
public function setActiveCurrency($sActiveCurrencyCode)
{
$this->sActiveCurrency = $sActiveCurrencyCode;
return $this;
}
/**
* Get active price type
* @return int|null
*/
public function getActivePriceType()
{
if (empty($this->iActivePriceType)) {
$this->iActivePriceType = PriceTypeHelper::instance()->getActivePriceTypeID();
}
return $this->iActivePriceType;
}
/**
* Get active currency code
* @return int|null
*/
public function getActiveCurrency()
{
if (!empty($this->sActiveCurrency)) {
return $this->sActiveCurrency;
}
return CurrencyHelper::instance()->getActiveCurrencyCode();
}
/**
* Get price_value attribute
* @return float
*/
protected function getPriceValueAttribute()
{
$iActivePriceType = $this->getActivePriceType();
if (empty($iActivePriceType)) {
$fPrice = $this->getAttribute('price_value');
} else {
$fPrice = array_get($this->price_list, $iActivePriceType.'.price');
}
$fPrice = CurrencyHelper::instance()->convert($fPrice, $this->getActiveCurrency());
return $fPrice;
}
/**
* Get old_price_value attribute
* @return float
*/
protected function getOldPriceValueAttribute()
{
$iActivePriceType = $this->getActivePriceType();
if (empty($iActivePriceType)) {
$fPrice = $this->getAttribute('old_price_value');
} else {
$fPrice = array_get($this->price_list, $iActivePriceType.'.old_price');
}
$fPrice = CurrencyHelper::instance()->convert($fPrice, $this->getActiveCurrency());
return $fPrice;
}
/**
* Get discount_price_value attribute
* @return float
*/
protected function getDiscountPriceValueAttribute()
{
$fOldPrice = $this->old_price_value;
$fPrice = $this->price_value;
$fDiscountPrice = 0;
if ($fOldPrice > 0) {
$fDiscountPrice = PriceHelper::round($fOldPrice - $fPrice);
}
$fPrice = CurrencyHelper::instance()->convert($fDiscountPrice, $this->getActiveCurrency());
return $fPrice;
}
/**
* Get currency value
* @return null|string
*/
protected function getCurrencyAttribute()
{
if (empty($this->sActiveCurrency)) {
return CurrencyHelper::instance()->getActiveCurrencySymbol();
}
$sResult = CurrencyHelper::instance()->getCurrencySymbol($this->sActiveCurrency);
$this->sActiveCurrency = null;
return $sResult;
}
/**
* Get currency code value
* @return null|string
*/
protected function getCurrencyCodeAttribute()
{
if (empty($this->sActiveCurrency)) {
return CurrencyHelper::instance()->getActiveCurrencyCode();
}
$sResult = CurrencyHelper::instance()->getCurrencyCode($this->sActiveCurrency);
$this->sActiveCurrency = null;
return $sResult;
}
/**
* Get tax_price_value attribute value
* @return float
*/
protected function getTaxPriceValueAttribute()
{
$fPrice = PriceHelper::round($this->price_with_tax_value - $this->price_without_tax_value);
return $fPrice;
}
/**
* Get tax_old_price_value attribute value
* @return float
*/
protected function getTaxOldPriceValueAttribute()
{
$fPrice = PriceHelper::round($this->old_price_with_tax_value - $this->old_price_without_tax_value);
return $fPrice;
}
/**
* Get tax_discount_price_value attribute value
* @return float
*/
protected function getTaxDiscountPriceValueAttribute()
{
$fPrice = PriceHelper::round($this->discount_price_with_tax_value - $this->discount_price_without_tax_value);
return $fPrice;
}
/**
* Get price_with_tax_value attribute value
* @return float
*/
protected function getPriceWithTaxValueAttribute()
{
$fPrice = TaxHelper::instance()->getPriceWithTax($this->price_value, $this->tax_percent);
return $fPrice;
}
/**
* Get old_price_with_tax_value attribute value
* @return float
*/
protected function getOldPriceWithTaxValueAttribute()
{
$fPrice = TaxHelper::instance()->getPriceWithTax($this->old_price_value, $this->tax_percent);
return $fPrice;
}
/**
* Get discount_price_with_tax_value attribute value
* @return float
*/
protected function getDiscountPriceWithTaxValueAttribute()
{
$fPrice = TaxHelper::instance()->getPriceWithTax($this->discount_price_value, $this->tax_percent);
return $fPrice;
}
/**
* Get price_without_tax_value attribute value
* @return float
*/
protected function getPriceWithoutTaxValueAttribute()
{
$fPrice = TaxHelper::instance()->getPriceWithoutTax($this->price_value, $this->tax_percent);
return $fPrice;
}
/**
* Get old_price_without_tax_value attribute value
* @return float
*/
protected function getOldPriceWithoutTaxValueAttribute()
{
$fPrice = TaxHelper::instance()->getPriceWithoutTax($this->old_price_value, $this->tax_percent);
return $fPrice;
}
/**
* Get discount_price_without_tax_value attribute value
* @return float
*/
protected function getDiscountPriceWithoutTaxValueAttribute()
{
$fPrice = TaxHelper::instance()->getPriceWithoutTax($this->discount_price_value, $this->tax_percent);
return $fPrice;
}
/**
* Get tax_percent attribute value
* @return float
*/
protected function getTaxPercentAttribute()
{
$fTaxPercent = $this->getAttribute('tax_percent');
if ($fTaxPercent === null) {
$fTaxPercent = TaxHelper::instance()->getTaxPercent($this->tax_list);
$this->setAttribute('tax_percent', $fTaxPercent);
}
return $fTaxPercent;
}
/**
* Get tax_list attribute value
* @return \Lovata\Shopaholic\Classes\Collection\TaxCollection|TaxItem[]
*/
protected function getTaxListAttribute()
{
$obTaxList = $this->getAttribute('tax_list');
if ($obTaxList === null) {
$obTaxList = $this->getAppliedTaxList();
$this->setAttribute('tax_list', $obTaxList);
}
return $obTaxList;
}
/**
* Get measure of one unit
* @return \Lovata\Shopaholic\Classes\Item\MeasureItem
*/
protected function getMeasureOfUnitAttribute()
{
$iMeasureID = $this->measure_of_unit_id;
if (empty($iMeasureID)) {
$iMeasureID = Settings::getValue('measure_of_unit');
}
$obMeasureItem = MeasureItem::make($iMeasureID);
return $obMeasureItem;
}
/**
* Get dimensions unit measure
* @return \Lovata\Shopaholic\Classes\Item\MeasureItem
*/
protected function getDimensionsMeasureAttribute()
{
$obMeasureItem = MeasureHelper::instance()->getDimensionsMeasureItem();
return $obMeasureItem;
}
/**
* Get weight unit measure
* @return \Lovata\Shopaholic\Classes\Item\MeasureItem
*/
protected function getWeightMeasureAttribute()
{
$obMeasureItem = MeasureHelper::instance()->getWeightMeasureItem();
return $obMeasureItem;
}
/**
* Get applied tax list
* @return \Lovata\Shopaholic\Classes\Collection\TaxCollection|\Lovata\Shopaholic\Classes\Item\TaxItem[]
*/
protected function getAppliedTaxList()
{
$obResultTaxList = TaxHelper::instance()->getTaxList();
if ($obResultTaxList->isEmpty()) {
return $obResultTaxList;
}
foreach ($obResultTaxList as $obTaxItem) {
$bSkipTax = !$obTaxItem->is_global
&& !$obTaxItem->isAvailableForCategory($this->product->category)
&& !$obTaxItem->isAvailableForProduct($this->product)
&& !$obTaxItem->isAvailableForCountry(TaxHelper::instance()->getActiveCountry())
&& !$obTaxItem->isAvailableForState(TaxHelper::instance()->getActiveState());
if ($bSkipTax) {
$obResultTaxList->exclude($obTaxItem->id);
}
}
return $obResultTaxList;
}
/**
* Set element data from model object
*
* @return array
*/
protected function getElementData()
{
$obDefaultCurrency = CurrencyHelper::instance()->getDefault();
$sCurrencyCode = !empty($obDefaultCurrency) ? $obDefaultCurrency->code : null;
$arResult = [
'price_value' => $this->obElement->setActiveCurrency($sCurrencyCode)->setActivePriceType(null)->price_value,
'old_price_value' => $this->obElement->setActiveCurrency($sCurrencyCode)->setActivePriceType(null)->old_price_value,
'trashed' => $this->obElement->trashed(),
];
return $arResult;
}
}

View File

@ -0,0 +1,208 @@
<?php namespace Lovata\Shopaholic\Classes\Item;
use Cms\Classes\Page as CmsPage;
use Lovata\Toolbox\Classes\Item\ElementItem;
use Lovata\Toolbox\Classes\Helper\PageHelper;
use Lovata\Shopaholic\Models\Settings;
use Lovata\Shopaholic\Models\Product;
use Lovata\Shopaholic\Classes\Collection\CategoryCollection;
use Lovata\Shopaholic\Classes\Collection\OfferCollection;
/**
* Class ProductItem
* @package Lovata\Shopaholic\Classes\Item
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* @property int $id
* @property bool $active
* @property bool $trashed
* @property string $name
* @property string $slug
* @property string $code
*
* @property int $category_id
* @property CategoryItem $category
* @property array $additional_category_id
* @property CategoryCollection|CategoryItem[] $additional_category
*
* @property int $brand_id
* @property BrandItem $brand
*
* @property string $preview_text
* @property \System\Models\File $preview_image
*
* @property string $description
* @property \October\Rain\Database\Collection|\System\Models\File[] $images
*
* @property array $offer_id_list
* @property OfferCollection|OfferItem[] $offer
*
* Properties for Shopaholic
* @see \Lovata\PropertiesShopaholic\Classes\Event\ProductModelHandler::extendProductItem
* @property array $property_value_array
* @property \Lovata\PropertiesShopaholic\Classes\Collection\PropertyCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertyItem[] $property
*
* Reviews for Shopaholic
* @see \Lovata\ReviewsShopaholic\Classes\Event\ProductModelHandler::extendProductItem
* @property float $rating
* @property array $rating_data [1 => 0, 2 => 4, 3 => 7, 4 => 21, 5 => 48]
* @property \Lovata\ReviewsShopaholic\Classes\Collection\ReviewCollection|\Lovata\ReviewsShopaholic\Classes\Item\ReviewItem[] $review
*
* @method int getRatingCount(int $iRating)
* @method int getRatingPercent(int $iRating)
* @method int getRatingTotalCount()
*
* Related products for Shopaholic
* @property \Lovata\Shopaholic\Classes\Collection\ProductCollection|ProductItem[] $related
*
* Accessories for Shopaholic
* @property \Lovata\Shopaholic\Classes\Collection\ProductCollection|ProductItem[] $accessory
*
* Labels for Shopaholic
* @property \Lovata\LabelsShopaholic\Classes\Collection\LabelCollection|\Lovata\LabelsShopaholic\Classes\Item\LabelItem[] $label
*
* Compare for Shopaholic
* @method bool inCompare()
*
* Wish list for Shopaholic
* @method bool inWishList()
*
* YandexMarket for Shopaholic
* @property \System\Models\File $preview_image_yandex
* @property \October\Rain\Database\Collection|\System\Models\File[] $images_yandex
*
* Facebook for Shopaholic
* @property \System\Models\File $preview_image_facebook
* @property \October\Rain\Database\Collection|\System\Models\File[] $images_facebook
*
* VKontakte for Shopaholic
* @property bool $active_vk
* @property int $external_vk_id
* @property \System\Models\File $preview_image_vkontakte
* @property \October\Rain\Database\Collection|\System\Models\File[] $images_vkontakte
*
* Downloadable file for Shopaholic
* @property bool $is_file_access
*/
class ProductItem extends ElementItem
{
const MODEL_CLASS = Product::class;
public static $arQueryWith = [
'preview_image',
'images',
'additional_category',
'offer',
'offer.preview_image',
'offer.images',
'offer.main_price',
'offer.price_link'
];
/** @var Product */
protected $obElement = null;
public $arRelationList = [
'offer' => [
'class' => OfferCollection::class,
'field' => 'offer_id_list',
],
'category' => [
'class' => CategoryItem::class,
'field' => 'category_id',
],
'additional_category' => [
'class' => CategoryCollection::class,
'field' => 'additional_category_id',
],
'brand' => [
'class' => BrandItem::class,
'field' => 'brand_id',
],
];
/**
* Check element, active == true, trashed == false
* @return bool
*/
public function isActive()
{
return $this->active && !$this->trashed;
}
/**
* Returns URL of a category page.
*
* @param string|null $sPageCode
* @param array $arRemoveParamList
*
* @return string
*/
public function getPageUrl($sPageCode = null, $arRemoveParamList = [])
{
if (empty($sPageCode)) {
$sPageCode = Settings::getValue('default_product_page_id', 'product');
}
//Get URL params
$arParamList = $this->getPageParamList($sPageCode, $arRemoveParamList);
//Generate page URL
$sURL = CmsPage::url($sPageCode, $arParamList);
return $sURL;
}
/**
* Get URL param list by page code
* @param string $sPageCode
* @param array $arRemoveParamList
* @return array
*/
public function getPageParamList($sPageCode, $arRemoveParamList = []) : array
{
$arResult = [];
$arPageParamList = [];
if (!empty($arRemoveParamList)) {
foreach ($arRemoveParamList as $sParamName) {
$arResult[$sParamName] = null;
}
}
//Get URL params for categories
$aCategoryParamList = $this->category->getPageParamList($sPageCode);
$aBrandParamList = $this->brand->getPageParamList($sPageCode);
//Get URL params for page
$arParamList = (array) PageHelper::instance()->getUrlParamList($sPageCode, 'ProductPage');
if (!empty($arParamList)) {
$sPageParam = array_shift($arParamList);
$arPageParamList[$sPageParam] = $this->slug;
}
$arResult = array_merge($arResult, $aCategoryParamList, $aBrandParamList, $arPageParamList);
return $arResult;
}
/**
* Set element data from model object
* @return array
*/
protected function getElementData()
{
$arResult = [
'offer_id_list' => $this->obElement->offer->where('active', true)->pluck('id')->all(),
'additional_category_id' => $this->obElement->additional_category->pluck('id')->all(),
'trashed' => $this->obElement->trashed(),
];
foreach ($this->obElement->offer as $obOffer) {
OfferItem::make($obOffer->id, $obOffer);
}
return $arResult;
}
}

View File

@ -0,0 +1,93 @@
<?php namespace Lovata\Shopaholic\Classes\Item;
use Cms\Classes\Page as CmsPage;
use Lovata\Toolbox\Classes\Item\ElementItem;
use Lovata\Toolbox\Classes\Helper\PageHelper;
use Lovata\Shopaholic\Models\Settings;
use Lovata\Shopaholic\Models\PromoBlock;
use Lovata\Shopaholic\Classes\Collection\ProductCollection;
/**
* Class PromoBlockItem
* @package Lovata\PromoBlocksShopaholic\Classes\Item
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* @property int $id
* @property string $name
* @property string $slug
* @property string $code
* @property string $type
* @property \October\Rain\Argon\Argon $date_begin
* @property \October\Rain\Argon\Argon $date_end
*
* @property string $preview_text
* @property \System\Models\File $preview_image
* @property \System\Models\File $icon
*
* @property string $description
* @property \October\Rain\Database\Collection|\System\Models\File[] $images
* @property ProductCollection|\Lovata\Shopaholic\Classes\Item\ProductItem[] $product
*/
class PromoBlockItem extends ElementItem
{
const MODEL_CLASS = PromoBlock::class;
public static $arQueryWith = ['preview_image', 'icon', 'images'];
/** @var PromoBlock */
protected $obElement = null;
/**
* Returns URL of a promo block page.
*
* @param string|null $sPageCode
*
* @return string
*/
public function getPageUrl($sPageCode = null)
{
if (empty($sPageCode)) {
$sPageCode = Settings::getValue('default_promo_block_page_id', 'promo-block');
}
//Get URL params
$arParamList = $this->getPageParamList($sPageCode);
//Generate page URL
$sURL = CmsPage::url($sPageCode, $arParamList);
return $sURL;
}
/**
* Get URL param list by page code
* @param string $sPageCode
* @return array
*/
public function getPageParamList($sPageCode) : array
{
$arPageParamList = [];
//Get URL params for page
$arParamList = PageHelper::instance()->getUrlParamList($sPageCode, 'PromoBlockPage');
if (!empty($arParamList)) {
$sPageParam = array_shift($arParamList);
$arPageParamList[$sPageParam] = $this->slug;
}
return $arPageParamList;
}
/**
* Get product collection attribute
* @return ProductCollection
*/
protected function getProductAttribute() : ProductCollection
{
$obProductList = ProductCollection::make()->promo($this->id);
return $obProductList;
}
}

View File

@ -0,0 +1,116 @@
<?php namespace Lovata\Shopaholic\Classes\Item;
use System\Classes\PluginManager;
use Lovata\Toolbox\Classes\Item\ElementItem;
use Lovata\Shopaholic\Models\Tax;
/**
* Class TaxItem
* @package Lovata\Shopaholic\Classes\Item
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* @property int $id
* @property bool $is_global
* @property string $name
* @property string $description
* @property float $percent
* @property array $category_id_list
* @property array $product_id_list
* @property array $country_id_list
* @property array $state_id_list
*
* Orders for Shopaholic
* @property bool $applied_to_shipping_price
*/
class TaxItem extends ElementItem
{
const MODEL_CLASS = Tax::class;
/** @var Tax */
protected $obElement = null;
/**
* Check tax is available for category
* @param \Lovata\Shopaholic\Classes\Item\CategoryItem $obCategoryItem
* @return bool
*/
public function isAvailableForCategory($obCategoryItem) : bool
{
$arCategoryIDList = (array) $this->category_id_list;
if (empty($arCategoryIDList) || empty($obCategoryItem)) {
return false;
}
if (in_array($obCategoryItem->id, $arCategoryIDList)) {
return true;
}
if ($obCategoryItem->parent->isNotEmpty()) {
return $this->isAvailableForCategory($obCategoryItem->parent);
}
return false;
}
/**
* Check tax is available for product
* @param \Lovata\Shopaholic\Classes\Item\ProductItem $obProductItem
* @return bool
*/
public function isAvailableForProduct($obProductItem) : bool
{
$arProductIDList = (array) $this->product_id_list;
$bResult = !empty($arProductIDList) && !empty($obProductItem) && in_array($obProductItem->id, $arProductIDList);
return $bResult;
}
/**
* Check tax is available for country
* @param \RainLab\Location\Models\Country $obCountry
* @return bool
*/
public function isAvailableForCountry($obCountry) : bool
{
$arCountryIDList = (array) $this->country_id_list;
$bResult = !empty($arCountryIDList) && !empty($obCountry) && in_array($obCountry->id, $arCountryIDList);
return $bResult;
}
/**
* Check tax is available for state
* @param \RainLab\Location\Models\State $obState
* @return bool
*/
public function isAvailableForState($obState) : bool
{
$arStateIDList = (array) $this->state_id_list;
$bResult = !empty($arStateIDList) && !empty($obState) && in_array($obState->id, $arStateIDList);
return $bResult;
}
/**
* Set model data from object
* @return mixed
*/
protected function getElementData()
{
$arResult = [
'category_id_list' => $this->obElement->category()->lists('id'),
'product_id_list' => $this->obElement->product()->lists('id'),
];
if (PluginManager::instance()->hasPlugin('RainLab.Location')) {
$arResult['country_id_list'] = $this->obElement->country()->lists('id');
$arResult['state_id_list'] = $this->obElement->state()->lists('id');
}
return $arResult;
}
}

View File

@ -0,0 +1,30 @@
<?php namespace Lovata\Shopaholic\Classes\Store;
use Lovata\Toolbox\Classes\Store\AbstractListStore;
use Lovata\Shopaholic\Classes\Store\Brand\ActiveListStore;
use Lovata\Shopaholic\Classes\Store\Brand\SortingListStore;
use Lovata\Shopaholic\Classes\Store\Brand\ListByCategoryStore;
/**
* Class BrandListStore
* @package Lovata\Shopaholic\Classes\Store
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
* @property ActiveListStore $active
* @property SortingListStore $sorting
* @property ListByCategoryStore $category
*/
class BrandListStore extends AbstractListStore
{
protected static $instance;
/**
* Init store method
*/
protected function init()
{
$this->addToStoreList('sorting', SortingListStore::class);
$this->addToStoreList('category', ListByCategoryStore::class);
$this->addToStoreList('active', ActiveListStore::class);
}
}

View File

@ -0,0 +1,28 @@
<?php namespace Lovata\Shopaholic\Classes\Store;
use Lovata\Toolbox\Classes\Store\AbstractListStore;
use Lovata\Shopaholic\Classes\Store\Category\TopLevelListStore;
use Lovata\Shopaholic\Classes\Store\Category\ActiveListStore;
/**
* Class CategoryListStore
* @package Lovata\Shopaholic\Classes\Store
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* @property TopLevelListStore $top_level
* @property ActiveListStore $active
*/
class CategoryListStore extends AbstractListStore
{
protected static $instance;
/**
* Init store method
*/
protected function init()
{
$this->addToStoreList('top_level', TopLevelListStore::class);
$this->addToStoreList('active', ActiveListStore::class);
}
}

View File

@ -0,0 +1,27 @@
<?php namespace Lovata\Shopaholic\Classes\Store;
use Lovata\Toolbox\Classes\Store\AbstractListStore;
use Lovata\Shopaholic\Classes\Store\Currency\ActiveListStore;
use Lovata\Shopaholic\Classes\Store\Currency\SortingListStore;
/**
* Class CurrencyListStore
* @package Lovata\Shopaholic\Classes\Store
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
* @property ActiveListStore $active
* @property SortingListStore $sorting
*/
class CurrencyListStore extends AbstractListStore
{
protected static $instance;
/**
* Init store method
*/
protected function init()
{
$this->addToStoreList('active', ActiveListStore::class);
$this->addToStoreList('sorting', SortingListStore::class);
}
}

View File

@ -0,0 +1,33 @@
<?php namespace Lovata\Shopaholic\Classes\Store;
use Lovata\Toolbox\Classes\Store\AbstractListStore;
use Lovata\Shopaholic\Classes\Store\Offer\ActiveListStore;
use Lovata\Shopaholic\Classes\Store\Offer\SortingListStore;
/**
* Class OfferListStore
* @package Lovata\Shopaholic\Classes\Store
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* @property ActiveListStore $active
* @property SortingListStore $sorting
*/
class OfferListStore extends AbstractListStore
{
const SORT_NO = 'no';
const SORT_PRICE_ASC = 'price|asc';
const SORT_PRICE_DESC = 'price|desc';
const SORT_NEW = 'new';
protected static $instance;
/**
* Init store method
*/
protected function init()
{
$this->addToStoreList('sorting', SortingListStore::class);
$this->addToStoreList('active', ActiveListStore::class);
}
}

View File

@ -0,0 +1,45 @@
<?php namespace Lovata\Shopaholic\Classes\Store;
use Lovata\Toolbox\Classes\Store\AbstractListStore;
use Lovata\Shopaholic\Classes\Store\Product\ActiveListStore;
use Lovata\Shopaholic\Classes\Store\Product\ListByCategoryStore;
use Lovata\Shopaholic\Classes\Store\Product\ListByBrandStore;
use Lovata\Shopaholic\Classes\Store\Product\ListByPromoBlockStore;
use Lovata\Shopaholic\Classes\Store\Product\SortingListStore;
/**
* Class ProductListStore
* @package Lovata\Shopaholic\Classes\Store
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*
* @property ActiveListStore $active
* @property ListByCategoryStore $category
* @property ListByBrandStore $brand
* @property SortingListStore $sorting
* @property ListByPromoBlockStore $promo_block
*/
class ProductListStore extends AbstractListStore
{
const SORT_NO = 'no';
const SORT_PRICE_ASC = 'price|asc';
const SORT_PRICE_DESC = 'price|desc';
const SORT_NEW = 'new';
const SORT_POPULARITY_DESC = 'popularity|desc';
const SORT_RATING_DESC = 'rating|desc';
const SORT_RATING_ASC = 'rating|asc';
protected static $instance;
/**
* Init store method
*/
protected function init()
{
$this->addToStoreList('sorting', SortingListStore::class);
$this->addToStoreList('category', ListByCategoryStore::class);
$this->addToStoreList('brand', ListByBrandStore::class);
$this->addToStoreList('active', ActiveListStore::class);
$this->addToStoreList('promo_block', ListByPromoBlockStore::class);
}
}

View File

@ -0,0 +1,39 @@
<?php namespace Lovata\Shopaholic\Classes\Store;
use Lovata\Toolbox\Classes\Store\AbstractListStore;
use Lovata\Shopaholic\Classes\Store\PromoBlock\ActiveListStore;
use Lovata\Shopaholic\Classes\Store\PromoBlock\SortingListStore;
use Lovata\Shopaholic\Classes\Store\PromoBlock\HiddenListStore;
use Lovata\Shopaholic\Classes\Store\PromoBlock\NotHiddenListStore;
/**
* Class PromoBlockListStore
* @package Lovata\Shopaholic\Classes\Store
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
* @property ActiveListStore $active
* @property SortingListStore $sorting
* @property HiddenListStore $hidden
* @property NotHiddenListStore $not_hidden
*/
class PromoBlockListStore extends AbstractListStore
{
protected static $instance;
const SORT_DEFAULT = 'default';
const SORT_DATE_BEGIN_ASC = 'date_begin|asc';
const SORT_DATE_BEGIN_DESC = 'date_begin|desc';
const SORT_DATE_END_ASC = 'date_end|asc';
const SORT_DATE_END_DESC = 'date_end|desc';
/**
* Init store method
*/
protected function init()
{
$this->addToStoreList('active', ActiveListStore::class);
$this->addToStoreList('sorting', SortingListStore::class);
$this->addToStoreList('hidden', HiddenListStore::class);
$this->addToStoreList('not_hidden', NotHiddenListStore::class);
}
}

View File

@ -0,0 +1,27 @@
<?php namespace Lovata\Shopaholic\Classes\Store;
use Lovata\Toolbox\Classes\Store\AbstractListStore;
use Lovata\Shopaholic\Classes\Store\Tax\ActiveListStore;
use Lovata\Shopaholic\Classes\Store\Tax\SortingListStore;
/**
* Class TaxListStore
* @package Lovata\Shopaholic\Classes\Store
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
* @property ActiveListStore $active
* @property SortingListStore $sorting
*/
class TaxListStore extends AbstractListStore
{
protected static $instance;
/**
* Init store method
*/
protected function init()
{
$this->addToStoreList('active', ActiveListStore::class);
$this->addToStoreList('sorting', SortingListStore::class);
}
}

View File

@ -0,0 +1,26 @@
<?php namespace Lovata\Shopaholic\Classes\Store\Brand;
use Lovata\Toolbox\Classes\Store\AbstractStoreWithoutParam;
use Lovata\Shopaholic\Models\Brand;
/**
* Class ActiveListStore
* @package Lovata\Shopaholic\Classes\Store\Brand
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ActiveListStore extends AbstractStoreWithoutParam
{
protected static $instance;
/**
* Get ID list from database
* @return array
*/
protected function getIDListFromDB() : array
{
$arElementIDList = (array) Brand::active()->lists('id');
return $arElementIDList;
}
}

View File

@ -0,0 +1,67 @@
<?php namespace Lovata\Shopaholic\Classes\Store\Brand;
use Lovata\Shopaholic\Models\Category;
use Lovata\Toolbox\Classes\Store\AbstractStoreWithParam;
use Lovata\Shopaholic\Models\Product;
use Lovata\Shopaholic\Classes\Store\ProductListStore;
/**
* Class ListByCategoryStore
* @package Lovata\Shopaholic\Classes\Store\Brand
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class ListByCategoryStore extends AbstractStoreWithParam
{
protected static $instance;
/**
* Get ID list from database
* @return array
*/
protected function getIDListFromDB() : array
{
$arElementIDList = (array) Product::getByCategory($this->sValue)
->where('brand_id', '>', 0)
->lists('brand_id', 'id');
$obCategory = Category::find($this->sValue);
if (!empty($obCategory)) {
$arAdditionalElementIDList = (array) $obCategory->product_link()
->where('brand_id', '>', 0)
->lists('brand_id', 'id');
$arElementIDList = $arElementIDList + $arAdditionalElementIDList;
}
return $arElementIDList;
}
/**
* Get ID list from cache
* @return array
*/
protected function getIDListFromCache() : array
{
$arElementIDList = parent::getIDListFromCache();
//Get active product list
$arActiveProductIDList = ProductListStore::instance()->active->get();
if (empty($arActiveProductIDList) || empty($arElementIDList)) {
return [];
}
$arResult = [];
foreach ($arElementIDList as $iProductID => $iBrandID) {
if (!in_array($iProductID, $arActiveProductIDList)) {
continue;
}
$arResult[] = $iBrandID;
}
$arResult = array_unique($arResult);
return $arResult;
}
}

View File

@ -0,0 +1,26 @@
<?php namespace Lovata\Shopaholic\Classes\Store\Brand;
use Lovata\Toolbox\Classes\Store\AbstractStoreWithoutParam;
use Lovata\Shopaholic\Models\Brand;
/**
* Class SortingListStore
* @package Lovata\Shopaholic\Classes\Store\Brand
* @author Andrey Kharanenka, a.khoronenko@lovata.com, LOVATA Group
*/
class SortingListStore extends AbstractStoreWithoutParam
{
protected static $instance;
/**
* Get ID list from database
* @return array
*/
protected function getIDListFromDB() : array
{
$arElementIDList = (array) Brand::orderBy('sort_order', 'asc')->lists('id');
return $arElementIDList;
}
}

Some files were not shown because too many files have changed in this diff Show More