Skip to content

Commit

Permalink
PT-2775: code clean up; prepare plugin.json for store update
Browse files Browse the repository at this point in the history
  • Loading branch information
mitelg committed Jun 25, 2015
1 parent 0ed924b commit dedf01f
Show file tree
Hide file tree
Showing 29 changed files with 820 additions and 313 deletions.
128 changes: 102 additions & 26 deletions Bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
<?php

/**
* Shopware 5
* Copyright (c) shopware AG
*
* According to our dual licensing model, this program can be used either
* under the terms of the GNU Affero General Public License, version 3,
* or under a proprietary license.
*
* The texts of the GNU Affero General Public License with an additional
* permission and of our proprietary license can be found at and
* in the LICENSE file you have received along with this program.
*
* 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 Affero General Public License for more details.
*
* "Shopware" is a registered trademark of shopware AG.
* The licensing of the program under the AGPLv3 does not imply a
* trademark license. Therefore any rights, title and interest in
* our trademarks remain entirely with us.
*/

use Shopware\Models\Config\Element;
use Shopware\Models\Config\Form;
use Shopware\SwagCustomSort\Subscriber\Backend;
use Shopware\SwagCustomSort\Subscriber\ControllerPath;
use Shopware\SwagCustomSort\Subscriber\Frontend;
use Shopware\SwagCustomSort\Subscriber\Resource;
use Shopware\SwagCustomSort\Subscriber\Sort;

/**
* Class Shopware_Plugins_Frontend_SwagCustomSort_Bootstrap
*/
class Shopware_Plugins_Frontend_SwagCustomSort_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
/**
* Returns the plugin label which is displayed in the plugin information and
* in the Plugin Manager.
*
* @return string
*/
public function getLabel()
{
return 'Custom sorting';
return 'Individuelle Sortierung';
}

/**
Expand All @@ -32,8 +67,8 @@ public function getVersion()
/**
* Install Plugin / Add Events
*
* @throws Enlight_Exception
* @return bool
* @throws Exception
*/
public function install()
{
Expand All @@ -47,6 +82,32 @@ public function install()
$this->createMenu();
$this->createForm($this->Form());

return true;
}

/**
* Standard plugin enable method
*
* @return array
*/
public function enable()
{
$sql = "UPDATE s_core_menu SET active = 1 WHERE controller = 'CustomSort';";
Shopware()->Db()->query($sql);

return array('success' => true, 'invalidateCache' => array('backend'));
}

/**
* Standard plugin disable method
*
* @return array
*/
public function disable()
{
$sql = "UPDATE s_core_menu SET active = 0 WHERE controller = 'CustomSort';";
Shopware()->Db()->query($sql);

return array('success' => true, 'invalidateCache' => array('backend'));
}

Expand All @@ -64,11 +125,11 @@ public function subscribeEvents()
public function onStartDispatch()
{
$subscribers = array(
new \Shopware\SwagCustomSort\Subscriber\Resource(Shopware()->Container()),
new \Shopware\SwagCustomSort\Subscriber\ControllerPath($this),
new \Shopware\SwagCustomSort\Subscriber\Frontend($this),
new \Shopware\SwagCustomSort\Subscriber\Backend($this, Shopware()->Models()),
new \Shopware\SwagCustomSort\Subscriber\Sort($this)
new Resource($this->get('models')),
new ControllerPath($this->Path()),
new Frontend($this->Path()),
new Backend($this, $this->get('models')),
new Sort()
);

foreach ($subscribers as $subscriber) {
Expand Down Expand Up @@ -97,7 +158,7 @@ public function createMenu()
'label' => 'Custom sort',
'controller' => 'CustomSort',
'action' => 'Index',
'active' => 1,
'active' => 0,
'class' => 'sprite-blue-document-text-image',
'parent' => $parent,
'position' => 6,
Expand All @@ -110,7 +171,8 @@ public function createMenu()
*/
public function createDatabase()
{
$em = $this->Application()->Models();
/** @var \Shopware\Components\Model\ModelManager $em */
$em = $this->get('models');
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);

$classes = array(
Expand All @@ -119,14 +181,19 @@ public function createDatabase()

try {
$tool->createSchema($classes);
} catch(\Doctrine\ORM\Tools\ToolsException $e) {
} catch (\Doctrine\ORM\Tools\ToolsException $e) {
//
}
}

/**
* creates necessary attributes for categories
*/
public function createAttributes()
{
$em = $this->Application()->Models();
/** @var \Shopware\Components\Model\ModelManager $em */
$em = $this->get('models');

$em->addAttribute(
's_categories_attributes',
'swag',
Expand Down Expand Up @@ -161,31 +228,40 @@ public function createAttributes()
null
);

$em->generateAttributeModels(array(
's_categories_attributes'
));
$em->generateAttributeModels(
array(
's_categories_attributes'
)
);
}

protected function createForm(Shopware\Models\Config\Form $form)
/**
* @param Form $form
*/
protected function createForm(Form $form)
{
$form->setElement('text', 'swagCustomSortName',
$form->setElement(
'text',
'swagCustomSortName',
array(
'label' => 'Name',
'value' => 'Custom Sorting',
'description' => 'The new sort, will be visible in the frontend under this name option.',
'value' => 'Individuelle Sortierung',
'description' => 'Die neue Sortierung ist unter diesem Namen im Frontend sichtbar.',
'required' => true,
'scope' => \Shopware\Models\Config\Element::SCOPE_SHOP
'scope' => Element::SCOPE_SHOP
)
);

$this->addFormTranslations(
array('en_GB' => array(
'swagCustomSortName' => array(
'label' => 'Name',
'description' => 'The new sort, will be visible in the frontend under this name option.',
'value' => 'Custom Sorting'
array(
'en_GB' => array(
'swagCustomSortName' => array(
'label' => 'Name',
'description' => 'The new sort will be visible in the frontend under this name.',
'value' => 'Custom Sorting'
)
)
))
)
);
}
}
}
Loading

0 comments on commit dedf01f

Please sign in to comment.