diff --git a/Bootstrap.php b/Bootstrap.php index 809f5ab..6bbcfce 100644 --- a/Bootstrap.php +++ b/Bootstrap.php @@ -1,15 +1,50 @@ 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')); } @@ -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) { @@ -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, @@ -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( @@ -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', @@ -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' + ) ) - )) + ) ); } -} \ No newline at end of file +} diff --git a/Components/Listing.php b/Components/Listing.php index d3e11a0..4476b7a 100644 --- a/Components/Listing.php +++ b/Components/Listing.php @@ -1,16 +1,44 @@ config = $config; $this->em = $em; } + /** + * @return Config + */ public function getConfig() { return $this->config; } + /** + * @return ModelManager + */ public function getEntityManager() { return $this->em; } + /** + * @return null|\Shopware\Components\Model\ModelRepository + */ public function getCategoryAttributesRepository() { if ($this->categoryAttributesRepo === null) { @@ -44,6 +82,9 @@ public function getCategoryAttributesRepository() return $this->categoryAttributesRepo; } + /** + * @return null|\Shopware\Models\Category\Repository + */ public function getCategoryRepository() { if ($this->categoryRepo === null) { @@ -53,6 +94,9 @@ public function getCategoryRepository() return $this->categoryRepo; } + /** + * @return null|\Shopware\CustomModels\CustomSort\CustomSortRepository + */ public function getCustomSortRepository() { if ($this->customSortRepo === null) { @@ -62,6 +106,10 @@ public function getCustomSortRepository() return $this->customSortRepo; } + /** + * @param $categoryId + * @return bool + */ public function showCustomSortName($categoryId) { $sortName = $this->getFormattedSortName(); @@ -77,6 +125,9 @@ public function showCustomSortName($categoryId) return false; } + /** + * @return string + */ public function getFormattedSortName() { $formattedName = $this->getSortName(); @@ -84,6 +135,9 @@ public function getFormattedSortName() return trim($formattedName); } + /** + * @return null + */ public function getSortName() { $name = $this->getConfig()->get('swagCustomSortName'); @@ -91,6 +145,10 @@ public function getSortName() return $name; } + /** + * @param $categoryId + * @return bool + */ public function hasCustomSort($categoryId) { $isLinked = $this->isLinked($categoryId); @@ -106,11 +164,15 @@ public function hasCustomSort($categoryId) return false; } + /** + * @param $categoryId + * @return bool + */ public function isLinked($categoryId) { - /* @var \Shopware\Models\Attribute\Category $categoryAttributes */ + /* @var CategoryAttributes $categoryAttributes */ $categoryAttributes = $this->getCategoryAttributesRepository()->findOneBy(array('categoryId' => $categoryId)); - if (!$categoryAttributes instanceof \Shopware\Models\Attribute\Category) { + if (!$categoryAttributes instanceof CategoryAttributes) { return false; } @@ -119,9 +181,9 @@ public function isLinked($categoryId) return false; } - /* @var \Shopware\Models\Category\Category $category */ + /* @var Category $category */ $category = $this->getCategoryRepository()->find($linkedCategoryId); - if (!$category instanceof \Shopware\Models\Category\Category) { + if (!$category instanceof Category) { return false; } @@ -146,9 +208,9 @@ public function hasOwnSort($categoryId) */ public function showCustomSortAsDefault($categoryId) { - /* @var \Shopware\Models\Attribute\Category $categoryAttributes */ + /* @var Category $categoryAttributes */ $categoryAttributes = $this->getCategoryAttributesRepository()->findOneBy(array('categoryId' => $categoryId)); - if (!$categoryAttributes instanceof \Shopware\Models\Attribute\Category) { + if (!$categoryAttributes instanceof Category) { return false; } @@ -170,9 +232,9 @@ public function showCustomSortAsDefault($categoryId) */ public function getLinkedCategoryId($categoryId) { - /* @var \Shopware\Models\Attribute\Category $categoryAttributes */ + /* @var Category $categoryAttributes */ $categoryAttributes = $this->getCategoryAttributesRepository()->findOneBy(array('categoryId' => $categoryId)); - if (!$categoryAttributes instanceof \Shopware\Models\Attribute\Category) { + if (!$categoryAttributes instanceof Category) { return false; } @@ -181,9 +243,9 @@ public function getLinkedCategoryId($categoryId) return false; } - /* @var \Shopware\Models\Category\Category $category */ + /* @var Category $category */ $category = $this->getCategoryRepository()->find($linkedCategoryId); - if (!$category instanceof \Shopware\Models\Category\Category) { + if (!$category instanceof Category) { return false; } @@ -199,7 +261,7 @@ public function getLinkedCategoryId($categoryId) public function getCategoryBaseSort($categoryId) { $categoryAttributes = $this->getCategoryAttributesRepository()->findOneBy(array('categoryId' => $categoryId)); - if (!$categoryAttributes instanceof \Shopware\Models\Attribute\Category) { + if (!$categoryAttributes instanceof Category) { return false; } @@ -210,4 +272,4 @@ public function getCategoryBaseSort($categoryId) return $baseSortId; } -} \ No newline at end of file +} diff --git a/Controllers/Backend/CustomSort.php b/Controllers/Backend/CustomSort.php index c7f37db..d6c4fa2 100644 --- a/Controllers/Backend/CustomSort.php +++ b/Controllers/Backend/CustomSort.php @@ -1,14 +1,40 @@ setFirstResult($offset) - ->setMaxResults($limit); + ->setMaxResults($limit); } $getProducts = $builder->execute()->fetchAll(); @@ -146,7 +172,9 @@ public function getCategorySettingsAction() 'baseSort' => $defaultSort ); - $categoryAttributes = $this->getModelManager()->getRepository('\Shopware\Models\Attribute\Category')->findOneBy(array('categoryId' => $categoryId)); + /** @var \Shopware\Models\Attribute\Category $categoryAttributes */ + $categoryAttributes = $this->getModelManager()->getRepository('\Shopware\Models\Attribute\Category') + ->findOneBy(array('categoryId' => $categoryId)); if ($categoryAttributes) { $baseSort = $categoryAttributes->getSwagBaseSort(); if ($baseSort > 0) { @@ -178,7 +206,7 @@ public function saveCategorySettingsAction() $this->getSortRepository()->updateCategoryAttributes($categoryId, $baseSort, $categoryLink, $defaultSort); $this->View()->assign(array('success' => true)); - } catch(\Exception $ex) { + } catch (\Exception $ex) { $this->View()->assign(array('success' => false, 'message' => $ex->getMessage())); } } @@ -255,7 +283,7 @@ private function applyNewPosition($allProducts, $products, $index) //apply new positions for the products $result = array(); - foreach($products as $productData) { + foreach ($products as $productData) { $newPosition = $productData['position']; $oldPosition = $productData['oldPosition']; @@ -264,12 +292,12 @@ private function applyNewPosition($allProducts, $products, $index) $result[$newPosition]['oldPosition'] = $oldPosition; } - foreach($allProducts as $id => &$product) { + foreach ($allProducts as $id => &$product) { if (array_key_exists($id, $products)) { continue; } - while($result[$index]) { + while ($result[$index]) { $index++; } @@ -293,7 +321,7 @@ private function applyNewPosition($allProducts, $products, $index) private function getSQLValues($productsForUpdate, $categoryId) { $sqlValues = ''; - foreach($productsForUpdate as $newArticle) { + foreach ($productsForUpdate as $newArticle) { if ($newArticle['id'] > 0) { $sqlValues .= "('" . $newArticle['positionId'] . "', '" . $categoryId . "', '" . $newArticle['id'] . "', '" . $newArticle['position'] . "', '" . $newArticle['pin'] . "'),"; } @@ -305,7 +333,7 @@ private function getSQLValues($productsForUpdate, $categoryId) private function prepareKeys($products) { $result = array(); - foreach($products as $product) { + foreach ($products as $product) { $result[$product['id']] = $product; } @@ -323,7 +351,7 @@ private function prepareKeys($products) private function getOffset($products, $categoryId) { $offset = null; - foreach($products as $productData) { + foreach ($products as $productData) { $newPosition = $productData['position']; $oldPosition = $productData['oldPosition']; @@ -360,7 +388,7 @@ private function getOffset($products, $categoryId) private function getLength($products, $offset, $categoryId) { $length = null; - foreach($products as $productData) { + foreach ($products as $productData) { $newPosition = $productData['position']; $oldPosition = $productData['oldPosition']; @@ -394,14 +422,14 @@ public function unpinArticleAction() throw new Exception("Unpin product '{$product['name']}' with id '{$product['id']}', failed!"); } - $categoryId = (int)$this->Request()->getParam('categoryId'); + $categoryId = (int) $this->Request()->getParam('categoryId'); $this->getSortRepository()->unpinById($sortId); $this->getSortRepository()->deleteUnpinnedRecords($categoryId); $this->View()->assign(array('success' => true)); - } catch(\Exception $ex) { + } catch (\Exception $ex) { $this->View()->assign(array('success' => false, 'message' => $ex->getMessage())); } } @@ -452,6 +480,7 @@ public function removeProductAction() if ($categories) { foreach ($categories as $childCategoryId) { + /** @var \Shopware\Models\Category\Category $childCategoryModel */ $childCategoryModel = Shopware()->Models()->getReference('Shopware\Models\Category\Category', $childCategoryId); if ($childCategoryModel) { $article->removeCategory($childCategoryModel); @@ -509,6 +538,4 @@ public function setCategoryIdCollection($categoryIdCollection) { $this->categoryIdCollection[] = $categoryIdCollection; } - - -} \ No newline at end of file +} diff --git a/Controllers/Widgets/CustomSort.php b/Controllers/Widgets/CustomSort.php index e0fe52e..6519f9c 100644 --- a/Controllers/Widgets/CustomSort.php +++ b/Controllers/Widgets/CustomSort.php @@ -1,14 +1,35 @@ Plugins()->Frontend()->SwagCustomSort(); $isEmotion = Shopware()->Shop()->getTemplate()->getVersion() < 3; @@ -39,8 +60,7 @@ public function defaultSortAction() $showCustomSortOption = false; } - $this->View()->showCustomSort = $showCustomSortOption; - $this->View()->sSort = $sSort; + $this->View()->assign('showCustomSort', $showCustomSortOption); + $this->View()->assign('sSort', $sSort); } - -} \ No newline at end of file +} diff --git a/Models/CustomSort/ArticleSort.php b/Models/CustomSort/ArticleSort.php index 0370ca9..1b513be 100644 --- a/Models/CustomSort/ArticleSort.php +++ b/Models/CustomSort/ArticleSort.php @@ -1,5 +1,28 @@ id; @@ -104,11 +130,17 @@ public function setPosition($position) $this->position = $position; } + /** + * @return bool + */ public function getPin() { return $this->pin; } + /** + * @param $pin + */ public function setPin($pin) { $this->pin = $pin; diff --git a/Models/CustomSort/CustomSortRepository.php b/Models/CustomSort/CustomSortRepository.php index 2f4f05c..c1d6616 100644 --- a/Models/CustomSort/CustomSortRepository.php +++ b/Models/CustomSort/CustomSortRepository.php @@ -1,12 +1,36 @@ getEntityManager()->getDBALQueryBuilder(); + $builder = $this->getQueryBuilder(); + $builder->select('id') ->from('s_articles_sort', 'sort') ->where('categoryId = :categoryId') @@ -36,7 +61,8 @@ public function hasCustomSort($categoryId) public function getMaxPosition($categoryId) { $categoryId = (int) $categoryId; - $builder = $this->getEntityManager()->getDBALQueryBuilder(); + $builder = $this->getQueryBuilder(); + $builder->select('MAX(position)') ->from('s_articles_sort', 'sort') ->where('categoryId = :categoryId') @@ -56,9 +82,10 @@ public function getMaxPosition($categoryId) */ public function getArticleImageQuery($categoryId, $orderBy) { - $builder = $this->getEntityManager()->getDBALQueryBuilder(); + $builder = $this->getQueryBuilder(); - $builder->select(array( + $builder->select( + array( 'sort.id as positionId', 'product.id', 'product.name', @@ -67,7 +94,8 @@ public function getArticleImageQuery($categoryId, $orderBy) 'sort.position as position', 'sort.position as oldPosition', 'sort.pin as pin', - )) + ) + ) ->from('s_articles', 'product') ->innerJoin('product', 's_articles_categories_ro', 'productCategory', 'productCategory.articleID = product.id') ->leftJoin('product', 's_articles_img', 'images', 'product.id = images.articleID') @@ -91,7 +119,7 @@ public function getArticleImageQuery($categoryId, $orderBy) */ public function getArticleImageCountQuery($categoryId) { - $builder = $this->getEntityManager()->getDBALQueryBuilder(); + $builder = $this->getQueryBuilder(); $builder->select('COUNT(DISTINCT product.id) as Total') ->from('s_articles', 'product') @@ -107,7 +135,7 @@ public function getArticleImageCountQuery($categoryId) /** * Sort products for current category by passed sort type * - * @param \Shopware\Components\Model\QueryBuilder $builder + * @param QueryBuilder $builder * @param integer $orderBy */ private function sortUnsortedByDefault($builder, $orderBy) @@ -161,11 +189,12 @@ private function sortUnsortedByDefault($builder, $orderBy) */ public function unpinById($id) { - $builder = $this->getEntityManager()->getDBALQueryBuilder(); + $builder = $this->getQueryBuilder(); + $builder->update('s_articles_sort') - ->set('pin', 0) - ->where('id = :id') - ->setParameter('id', $id); + ->set('pin', 0) + ->where('id = :id') + ->setParameter('id', $id); $builder->execute(); } @@ -182,13 +211,14 @@ public function deleteUnpinnedRecords($categoryId) $maxPinPosition = 0; } - $builder = $this->getEntityManager()->getDBALQueryBuilder(); + $builder = $this->getQueryBuilder(); + $builder->delete('s_articles_sort') - ->where('categoryId = :categoryId') - ->andWhere('position >= :maxPinPosition') - ->andWhere('pin = 0') - ->setParameter('categoryId', $categoryId) - ->setParameter(':maxPinPosition', $maxPinPosition); + ->where('categoryId = :categoryId') + ->andWhere('position >= :maxPinPosition') + ->andWhere('pin = 0') + ->setParameter('categoryId', $categoryId) + ->setParameter(':maxPinPosition', $maxPinPosition); $builder->execute(); } @@ -201,13 +231,14 @@ public function deleteUnpinnedRecords($categoryId) */ public function getMaxPinPosition($categoryId) { - $builder = $this->getEntityManager()->getDBALQueryBuilder(); + $builder = $this->getQueryBuilder(); + $builder->select(array('MAX(position) AS maxPinPosition')) - ->from('s_articles_sort') - ->where('categoryId = :categoryId') - ->andWhere('pin = 1') - ->orderBy('position', 'DESC') - ->setParameter('categoryId', $categoryId); + ->from('s_articles_sort', 'sort') + ->where('categoryId = :categoryId') + ->andWhere('pin = 1') + ->orderBy('position', 'DESC') + ->setParameter('categoryId', $categoryId); $maxPinPosition = $builder->execute()->fetchColumn(); @@ -222,11 +253,13 @@ public function getMaxPinPosition($categoryId) */ public function getPositionByArticleId($articleId) { - $builder = $this->getEntityManager()->getDBALQueryBuilder(); + $builder = $this->getQueryBuilder(); + $builder->select(array('position')) - ->from('s_articles_sort') + ->from('s_articles_sort', 'sort') ->where('articleId = :articleId') ->setParameter('articleId', $articleId); + $position = $builder->execute()->fetchColumn(); return $position; @@ -240,9 +273,10 @@ public function getPositionByArticleId($articleId) */ public function getPositionOfDeletedProduct($categoryId) { - $builder = $this->getEntityManager()->getDBALQueryBuilder(); + $builder = $this->getQueryBuilder(); + $builder->select(array('swag_deleted_position')) - ->from('s_categories_attributes') + ->from('s_categories_attributes', 'categories_attributes') ->where('categoryID = :categoryId') ->setParameter('categoryId', $categoryId); @@ -258,7 +292,8 @@ public function getPositionOfDeletedProduct($categoryId) */ public function resetDeletedPosition($categoryId) { - $builder = $this->getEntityManager()->getDBALQueryBuilder(); + $builder = $this->getQueryBuilder(); + $builder->update('s_categories_attributes') ->set('swag_deleted_position', 'null') ->where('categoryID = :categoryId') @@ -277,7 +312,8 @@ public function resetDeletedPosition($categoryId) */ public function updateCategoryAttributes($categoryId, $baseSort, $categoryLink = null, $defaultSort = null) { - $builder = $this->getEntityManager()->getDBALQueryBuilder(); + $builder = $this->getQueryBuilder(); + $builder->update('s_categories_attributes') ->where('categoryID = :categoryId') ->setParameter('categoryId', $categoryId); @@ -296,4 +332,17 @@ public function updateCategoryAttributes($categoryId, $baseSort, $categoryLink = $builder->execute(); } + + /** + * @return QueryBuilder + */ + private function getQueryBuilder() + { + /** @var ModelManager $em */ + $em = $this->getEntityManager(); + /** @var QueryBuilder $builder */ + $builder = $em->getDBALQueryBuilder(); + + return $builder; + } } diff --git a/Snippets/backend/custom_sort/main.ini b/Snippets/backend/custom_sort/main.ini index 47c7754..6962468 100644 --- a/Snippets/backend/custom_sort/main.ini +++ b/Snippets/backend/custom_sort/main.ini @@ -35,10 +35,10 @@ view/sorting = "Basissortierung" list/pagingCombo/products = "Produkte" main/success/title = "Erfolg" main/success/message = "Änderungen erfolgreich angewendet" -main/success/remove/message = "Product successfully removed" +main/success/remove/message = "Artikel erfolgreich gelöscht" main/error/title = "Fehler" main/error/message = "Änderungen wurden nicht gespeichert" -main/error/remove/message = "Product was not removed" +main/error/remove/message = "Artikel wurde nicht gelöscht" view/sort/release = "Erscheinungsdatum" view/sort/popularity = "Beliebtheit" view/sort/price_lowest = "Niedrigster Preis" diff --git a/Sorter/Sort/DragDropSorting.php b/Sorter/Sort/DragDropSorting.php index e805fb9..73e5277 100644 --- a/Sorter/Sort/DragDropSorting.php +++ b/Sorter/Sort/DragDropSorting.php @@ -1,5 +1,28 @@ Container()->get('swagcustomsort.listing_component'); @@ -103,4 +137,4 @@ protected function getDefaultData($defaultSort) ); } } -} \ No newline at end of file +} diff --git a/Sorter/SortFactory.php b/Sorter/SortFactory.php index b672742..99871cd 100644 --- a/Sorter/SortFactory.php +++ b/Sorter/SortFactory.php @@ -1,7 +1,31 @@ request = $request; + $this->request = $request; $this->criteria = $criteria; } diff --git a/Subscriber/Backend.php b/Subscriber/Backend.php index cd1a229..6de8c05 100644 --- a/Subscriber/Backend.php +++ b/Subscriber/Backend.php @@ -1,19 +1,53 @@ bootstrap = $bootstrap; $this->em = $em; } @@ -41,8 +75,7 @@ public static function getSubscribedEvents() */ public function onPostDispatchSecureBackendIndex(Enlight_Event_EventArgs $args) { - //TODO: check license - + /** @var \Enlight_View_Default $view */ $view = $args->getSubject()->View(); $view->addTemplateDir($this->bootstrap->Path() . 'Views/'); @@ -55,7 +88,7 @@ public function preRemoveArticle(Enlight_Event_EventArgs $arguments) $articleDetailId = $articleModel->getId(); $position = $this->getSortRepository()->getPositionByArticleId($articleDetailId); - if ($position !== null) { + if ($position) { $categories = $articleModel->getCategories(); foreach ($categories as $category) { $catAttributes = $category->getAttribute(); @@ -86,4 +119,4 @@ public function preRemoveCategory(Enlight_Event_EventArgs $arguments) $builder->execute(); } -} \ No newline at end of file +} diff --git a/Subscriber/ControllerPath.php b/Subscriber/ControllerPath.php index cb78e4c..e2df26f 100644 --- a/Subscriber/ControllerPath.php +++ b/Subscriber/ControllerPath.php @@ -1,17 +1,42 @@ bootstrap = $bootstrap; + $this->bootstrapPath = $bootstrapPath; } public static function getSubscribedEvents() @@ -27,9 +52,7 @@ public static function getSubscribedEvents() */ protected function registerView() { - Shopware()->Template()->addTemplateDir( - $this->bootstrap->Path() . 'Views/' - ); + Shopware()->Template()->addTemplateDir($this->bootstrapPath . 'Views/'); } /** @@ -44,10 +67,9 @@ public function onGetCustomSortControllerPath(\Enlight_Event_EventArgs $args) switch ($args->getName()) { case 'Enlight_Controller_Dispatcher_ControllerPath_Backend_CustomSort': - return $this->bootstrap->Path() . 'Controllers/Backend/CustomSort.php'; + return $this->bootstrapPath . 'Controllers/Backend/CustomSort.php'; case 'Enlight_Controller_Dispatcher_ControllerPath_Widgets_CustomSort': - return $this->bootstrap->Path() . 'Controllers/Widgets/CustomSort.php'; + return $this->bootstrapPath . 'Controllers/Widgets/CustomSort.php'; } } - -} \ No newline at end of file +} diff --git a/Subscriber/Frontend.php b/Subscriber/Frontend.php index b2379a4..a26ba5f 100644 --- a/Subscriber/Frontend.php +++ b/Subscriber/Frontend.php @@ -1,17 +1,45 @@ bootstrap = $bootstrap; + $this->bootstrapPath = $bootstrapPath; } public static function getSubscribedEvents() @@ -27,13 +55,12 @@ public static function getSubscribedEvents() */ public function onPostDispatchSecureListing(Enlight_Event_EventArgs $args) { - //TODO: check license - $categoryComponent = Shopware()->Container()->get('swagcustomsort.listing_component'); if (!$categoryComponent instanceof Listing) { return; } + /** @var \Enlight_View_Default $view */ $view = $args->getSubject()->View(); $hideFilters = $view->sCategoryContent['hideFilter']; $categoryId = $view->sCategoryContent['id']; @@ -45,26 +72,29 @@ public function onPostDispatchSecureListing(Enlight_Event_EventArgs $args) } } + /** + * @param \Enlight_View_Default $view + * @param $templatePath + */ protected function extendsTemplate($view, $templatePath) { $version = Shopware()->Shop()->getTemplate()->getVersion(); if ($version >= 3) { - $view->addTemplateDir($this->bootstrap->Path() . 'Views/responsive/'); + $view->addTemplateDir($this->bootstrapPath . 'Views/responsive/'); } else { - $view->addTemplateDir($this->bootstrap->Path() . 'Views/emotion/'); + $view->addTemplateDir($this->bootstrapPath . 'Views/emotion/'); $view->extendsTemplate($templatePath); } } public function onPreDispatchListing(Enlight_Event_EventArgs $args) { - //TODO: check license - $categoryComponent = Shopware()->Container()->get('swagcustomsort.listing_component'); if (!$categoryComponent instanceof Listing) { return; } + /** @var \Enlight_Controller_Request_RequestHttp $request */ $request = $args->getSubject()->Request(); $categoryId = (int) $request->getParam('sCategory'); $useDefaultSort = $categoryComponent->showCustomSortAsDefault($categoryId); @@ -74,6 +104,6 @@ public function onPreDispatchListing(Enlight_Event_EventArgs $args) return; } - $request->setParam('sSort', \Shopware\SwagCustomSort\Sorter\SortFactory::DRAG_DROP_SORTING); + $request->setParam('sSort', SortFactory::DRAG_DROP_SORTING); } -} \ No newline at end of file +} diff --git a/Subscriber/Resource.php b/Subscriber/Resource.php index 5b24213..5f4434f 100644 --- a/Subscriber/Resource.php +++ b/Subscriber/Resource.php @@ -1,39 +1,68 @@ container = $container; - } + public function __construct(ModelManager $modelManager) + { + $this->modelManager = $modelManager; + } - /** - * Returns an array of event names this subscriber wants to listen to. - * - * @return array The event names to listen to - */ - public static function getSubscribedEvents() - { - $base = 'Enlight_Bootstrap_InitResource_'; - return array( - $base . 'swagcustomsort.listing_component' => 'onInitListingComponent' - ); - } + /** + * Returns an array of event names this subscriber wants to listen to. + * + * @return array The event names to listen to + */ + public static function getSubscribedEvents() + { + return array( + 'Enlight_Bootstrap_InitResource_swagcustomsort.listing_component' => 'onInitListingComponent' + ); + } - public function onInitListingComponent() - { - return new Listing( - Shopware()->Config(), - $this->container->get('Models') - ); - } -} \ No newline at end of file + /** + * returns new instance of Listing + * + * @return Listing + */ + public function onInitListingComponent() + { + return new Listing( + Shopware()->Config(), + $this->modelManager + ); + } +} diff --git a/Subscriber/Sort.php b/Subscriber/Sort.php index 2f48d80..076f098 100644 --- a/Subscriber/Sort.php +++ b/Subscriber/Sort.php @@ -1,25 +1,47 @@ bootstrap = $bootstrap; - } - + /** + * Returns an array of event names this subscriber wants to listen to. + * + * @return array The event names to listen to + */ public static function getSubscribedEvents() { return array( - 'Shopware_SearchBundle_Create_Listing_Criteria' => 'onCreateListingCriteria', - 'Shopware_SearchBundleDBAL_Collect_Sorting_Handlers' => 'onCollectSortingHandlers' + 'Shopware_SearchBundle_Create_Listing_Criteria' => 'onCreateListingCriteria', + 'Shopware_SearchBundleDBAL_Collect_Sorting_Handlers' => 'onCollectSortingHandlers' ); } @@ -30,8 +52,6 @@ public static function getSubscribedEvents() */ public function onCreateListingCriteria(Enlight_Event_EventArgs $args) { - //TODO: check license - $request = $args->get('request'); $criteria = $args->get('criteria'); $sorter = new SortFactory($request, $criteria); @@ -47,9 +67,8 @@ public function onCreateListingCriteria(Enlight_Event_EventArgs $args) */ public function onCollectSortingHandlers(Enlight_Event_EventArgs $args) { - //TODO: check license - $args->setReturn(new DragDropHandler()); + return $args->getReturn(); } -} \ No newline at end of file +} diff --git a/Views/backend/_resources/css/custom_sort.css b/Views/backend/_resources/css/custom_sort.css index 41b8e26..91c0cfc 100644 --- a/Views/backend/_resources/css/custom_sort.css +++ b/Views/backend/_resources/css/custom_sort.css @@ -1,28 +1,32 @@ .swag-custom-sort-bold-checkbox { font-weight: bold; } + .swag-custom-sort-radiobtn-topmargin { margin-top: 3px; margin-left: 5px; } + .x-article-sort .thumb { float: left; position: relative; width: 175px; height: 205px; - border: 1px solid #C7C7C7; + border: 1px solid #c7c7c7; margin: 10px; padding: 5px; text-align: center; -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.35); - -moz-box-shadow: 0 0 5px rgba(0,0,0,0.35); + -moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.35); box-shadow: 0 0 5px rgba(0, 0, 0, 0.35); } + .x-article-sort .thumb .detail { position: absolute; bottom: 0; width: 95%; } + .x-article-sort .thumb .pin { position: absolute; top: 5px; @@ -31,18 +35,22 @@ height: 16px; background-position: 0 -1044px !important } + .x-article-sort .thumb .remove { display: block; width: 16px; height: 16px; } + .x-article-sort .thumb .pin, .x-article-sort .thumb .remove { cursor: pointer; } + .thumb .detail .paging { margin: 0 auto; } + .thumb .detail .paging span { display: inline-block; width: 16px; @@ -51,45 +59,56 @@ background-image: url('../images/sprite-arrows.png'); background-repeat: no-repeat; } + .detail .paging span.first { background-position: 0 -198px; } + .detail .paging span.first.disabled { cursor: auto; background-position: 0 -132px; } + .detail .paging span.prev { background-position: 0px -66px; } + .detail .paging span.prev.disabled { cursor: auto; background-position: 0 0; } + .detail .paging span.next { background-position: 0px -462px; } + .detail .paging span.next.disabled { cursor: auto; background-position: 0 -396px; } + .detail .paging span.last { background-position: 0px -330px; } + .detail .paging span.last.disabled { cursor: auto; background-position: 0 -264px; } + .x-article-sort .thumb span { display: block; width: 95%; text-align: center; } + .x-article-sort .thumb.x-item-selected { - -webkit-box-shadow: 0 0 5px #189EFF; + -webkit-box-shadow: 0 0 5px #189eff; -moz-box-shadow: 0 0 5px #189eff; - box-shadow: 0 0 5px #189EFF; - border-color: #189EFF; + box-shadow: 0 0 5px #189eff; + border-color: #189eff; } + .x-article-sort .thumb.drag-over:before { position: absolute; height: 205px; @@ -101,21 +120,23 @@ background-repeat: no-repeat, no-repeat, repeat-y; background-position: left bottom, left top, 3px top; } + .x-article-sort .empty-text { - box-shadow: #F5F7F8 0 1px 0px 0 inset,#F5F7F8 0 -1px 0px 0 inset,#F5F7F8 -1px 0 0px 0 inset,#F5F7F8 1px 0 0px 0 inset; + box-shadow: #f5f7f8 0 1px 0px 0 inset, #f5f7f8 0 -1px 0px 0 inset, #f5f7f8 -1px 0 0px 0 inset, #f5f7f8 1px 0 0px 0 inset; top: 50%; left: 50%; width: 150px; margin: 0 0 0 -75px; position: absolute; - border: 1px solid #C9CFD4; + border: 1px solid #c9cfd4; padding: 6px; } + .x-article-sort .empty-text span { display: block; - background: #F0F2F4; + background: #f0f2f4; color: #668498; - text-shadow: 0 1px 0 #FFF; + text-shadow: 0 1px 0 #ffffff; font: 11px/18px Arial, Verdana, sans-serif; text-align: center; padding: 4px 0; diff --git a/Views/backend/custom_sort/app.js b/Views/backend/custom_sort/app.js index 4ff207d..7efb1d5 100644 --- a/Views/backend/custom_sort/app.js +++ b/Views/backend/custom_sort/app.js @@ -1,25 +1,25 @@ //{namespace name="backend/custom_sort/view/main"} //{block name="backend/custom_sort/app"} Ext.define('Shopware.apps.CustomSort', { - + /** * The name of the module. Used for internal purpose * @string */ name: 'Shopware.apps.CustomSort', - + /** * Extends from our special controller, which handles the sub-application behavior and the event bus * @string */ extend: 'Enlight.app.SubApplication', - + /** * Enable bulk loading * @boolean */ bulkLoad: true, - + /** * Sets the loading path for the sub-application. * @@ -57,9 +57,8 @@ Ext.define('Shopware.apps.CustomSort', { * This method will be called when all dependencies are solved and * all member controllers, models, views and stores are initialized. */ - launch: function() { + launch: function () { return this.getController('Main').mainWindow; } - }); //{/block} \ No newline at end of file diff --git a/Views/backend/custom_sort/controller/main.js b/Views/backend/custom_sort/controller/main.js index c220ccd..5937058 100644 --- a/Views/backend/custom_sort/controller/main.js +++ b/Views/backend/custom_sort/controller/main.js @@ -32,16 +32,16 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * * @return void */ - init: function() { + init: function () { var me = this; me.categoryId = null; - me.subApplication.treeStore = me.subApplication.getStore('Tree'); + me.subApplication.treeStore = me.subApplication.getStore('Tree'); me.subApplication.treeStore.load(); - me.subApplication.articleStore = me.subApplication.getStore('Article'); + me.subApplication.articleStore = me.subApplication.getStore('Article'); - me.subApplication.categorySettings = me.subApplication.getStore('Settings'); + me.subApplication.categorySettings = me.subApplication.getStore('Settings'); me.control({ 'sort-category-tree': { @@ -77,7 +77,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * Event listener function of the article list panel. * Fired when the user uses paging navigation. */ - onPageChange: function() { + onPageChange: function () { var me = this, list = me.getArticleList(); @@ -91,7 +91,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * @param [object] view - Ext.view.View * @param [Ext.data.Model] The selected record */ - onCategorySelect: function(view, record) { + onCategorySelect: function (view, record) { var me = this, grid = me.getArticleView(), list = me.getArticleList(); @@ -105,7 +105,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { me.subApplication.categorySettings.getProxy().extraParams = { categoryId: me.categoryId }; me.subApplication.categorySettings.load({ - callback: function(records, operation, success) { + callback: function (records, operation, success) { if (success) { var record = records[0]; var linkedCategoryId = record.get('categoryLink'); @@ -126,7 +126,10 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { list.setDisabled(false); } - me.subApplication.articleStore.getProxy().extraParams = { categoryId: me.categoryId, sortBy: baseSort }; + me.subApplication.articleStore.getProxy().extraParams = { + categoryId: me.categoryId, + sortBy: baseSort + }; me.subApplication.articleStore.filters.clear(); me.subApplication.articleStore.currentPage = 1; me.subApplication.articleStore.load(); @@ -136,10 +139,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { } }); - - - - me.subApplication.articleStore.on('load', function(){ + me.subApplication.articleStore.on('load', function () { list.setLoading(false); }); }, @@ -150,7 +150,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * @param [integer] linkedCategoryId * @returns [boolean] */ - prepareTreeCombo: function(linkedCategoryId) { + prepareTreeCombo: function (linkedCategoryId) { var me = this, comboBox = me.getArticleView().categoryTreeCombo, treePanel = comboBox.getPicker(), @@ -163,7 +163,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { } //helper function for selecting tree node - var selectNode = function() { + var selectNode = function () { var node = treeStore.getNodeById(linkedCategoryId); if (node) { comboBox.setRawValue(node.get('name')); @@ -173,7 +173,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { }; //load whole category tree - treeStore.on('load', function() { + treeStore.on('load', function () { treePanel.expandAll(); treePanel.collapseAll(); @@ -192,7 +192,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * * @param [Ext.data.Model] The selected record */ - onSortChange: function(record) { + onSortChange: function (record) { var me = this, list = me.getArticleList(); @@ -202,7 +202,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { me.subApplication.articleStore.getProxy().extraParams = { categoryId: me.categoryId, sortBy: record } me.subApplication.articleStore.load({ - callback: function() { + callback: function () { list.setLoading(false); } }); @@ -212,7 +212,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * Event listener function of the article view panel. * Fired when the user change default display or linked category */ - onSaveSettings: function() { + onSaveSettings: function () { var me = this, grid = me.getArticleView(), list = me.getArticleList(), @@ -231,10 +231,10 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { record.set(values); record.save({ - success: function() { + success: function () { Shopware.Notification.createGrowlMessage('{s name=main/success/title}Success{/s}', '{s name=main/success/message}Successfully applied changes{/s}'); }, - failure: function() { + failure: function () { Shopware.Notification.createGrowlMessage('{s name=main/error/title}Error{/s}', '{s name=main/error/message}Changes were not saved{/s}'); } }); @@ -244,7 +244,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * * @param [Ext.data.Store] The article store */ - onMoveToStart: function(articleStore) { + onMoveToStart: function (articleStore) { if (!articleStore instanceof Ext.data.Store) { return false; } @@ -256,7 +256,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { list.setLoading(true); - selectedRecords.forEach(function(record, index) { + selectedRecords.forEach(function (record, index) { if (!record instanceof Ext.data.Model) { return false; } @@ -271,13 +271,14 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { return true; }, + /** * Event listener function of the article list. * Fired when the user click on "move to end" fast move icon. * * @param [Ext.data.Store] The article store */ - onMoveToEnd: function(articleStore) { + onMoveToEnd: function (articleStore) { if (!articleStore instanceof Ext.data.Store) { return false; } @@ -290,7 +291,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { list.setLoading(true); - selectedRecords.forEach(function(record, index) { + selectedRecords.forEach(function (record, index) { if (!record instanceof Ext.data.Model) { return false; } @@ -312,7 +313,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * * @param [Ext.data.Store] The article store */ - onMoveToPrevPage: function(articleStore) { + onMoveToPrevPage: function (articleStore) { if (!articleStore instanceof Ext.data.Store) { return false; } @@ -326,7 +327,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { list.setLoading(true); - selectedRecords.forEach(function(record) { + selectedRecords.forEach(function (record) { if (!record instanceof Ext.data.Model) { return false; } @@ -360,7 +361,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * * @param [Ext.data.Store] The article store */ - onMoveToNextPage: function(articleStore) { + onMoveToNextPage: function (articleStore) { if (!articleStore instanceof Ext.data.Store) { return false; } @@ -373,7 +374,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { list.setLoading(true); - selectedRecords.forEach(function(record, index) { + selectedRecords.forEach(function (record, index) { if (!record instanceof Ext.data.Model) { return false; } @@ -408,7 +409,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * @param [Array] Array with selected article in article view list * @param [Shopware.apps.Article.model.Article] The target record, on which the dragged record dropped */ - onArticleMove: function(articleStore, articleModel, targetRecord) { + onArticleMove: function (articleStore, articleModel, targetRecord) { var me = this, list = me.getArticleList(), startPosition = (articleStore.currentPage - 1) * articleStore.pageSize; @@ -425,7 +426,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { var positionIndex = articleStore.indexOf(targetRecord) + startPosition; var forward = [], backward = [], temp = 0; - Ext.each(articleModel, function(record) { + Ext.each(articleModel, function (record) { var oldPosition = articleStore.indexOf(record) + startPosition; if (oldPosition < positionIndex) { forward.push(record); @@ -436,7 +437,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { } }); - Ext.each(articleModel, function(record, index) { + Ext.each(articleModel, function (record, index) { if (!record instanceof Ext.data.Model) { return; } @@ -469,7 +470,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * * @param [Ext.data.Store] The article store */ - onSaveArticles: function(articleStore) { + onSaveArticles: function (articleStore) { articleStore.update(); }, @@ -481,7 +482,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * @param [Ext.data.Model] The selected record * @param [boolean] */ - onUnpin: function(articleStore, record) { + onUnpin: function (articleStore, record) { var me = this, list = me.getArticleList(); @@ -495,11 +496,11 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { record.set('pin', 0); articleStore.remove(record); articleStore.sync({ - success: function() { + success: function () { Shopware.Notification.createGrowlMessage('{s name=main/success/title}Success{/s}', '{s name=main/success/message}Successfully applied changes{/s}'); }, - failure: function() { - Shopware.Notification.createGrowlMessage('{s name=main/error/title}Error{/s}','{s name=main/error/message}Changes were not saved{/s}'); + failure: function () { + Shopware.Notification.createGrowlMessage('{s name=main/error/title}Error{/s}', '{s name=main/error/message}Changes were not saved{/s}'); store.load(); } }); @@ -515,7 +516,7 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { * @param [Ext.data.Model] The selected record * @param [boolean] */ - onRemove: function(articleStore, record) { + onRemove: function (articleStore, record) { var me = this, list = me.getArticleList(); @@ -534,17 +535,16 @@ Ext.define('Shopware.apps.CustomSort.controller.Main', { articleId: record.get('id'), categoryId: me.categoryId }, - success: function() { + success: function () { Shopware.Notification.createGrowlMessage('{s name=main/success/title}Success{/s}', '{s name=main/success/remove/message}Product successfully removed{/s}'); store.load(); }, - failure: function() { - Shopware.Notification.createGrowlMessage('{s name=main/error/title}Error{/s}','{s name=main/error/remove/message}Product was not removed{/s}'); + failure: function () { + Shopware.Notification.createGrowlMessage('{s name=main/error/title}Error{/s}', '{s name=main/error/remove/message}Product was not removed{/s}'); } }); return true; } - }); //{/block} \ No newline at end of file diff --git a/Views/backend/custom_sort/header.tpl b/Views/backend/custom_sort/header.tpl index 0fc5583..6c081a5 100644 --- a/Views/backend/custom_sort/header.tpl +++ b/Views/backend/custom_sort/header.tpl @@ -1,3 +1,3 @@ {block name="backend/base/header/css" append} - + {/block} \ No newline at end of file diff --git a/Views/backend/custom_sort/model/article.js b/Views/backend/custom_sort/model/article.js index dbfb373..ccd3516 100644 --- a/Views/backend/custom_sort/model/article.js +++ b/Views/backend/custom_sort/model/article.js @@ -1,5 +1,6 @@ //{block name="backend/custom_sort/model/article"} Ext.define('Shopware.apps.CustomSort.model.Article', { + /** * Extend for the standard ExtJS 4 * @string @@ -22,11 +23,11 @@ Ext.define('Shopware.apps.CustomSort.model.Article', { { name: 'thumbnail', type: 'string', - convert: function(value, record) { + convert: function (value, record) { if (record.get('path').indexOf('media/image') === -1) { return 'media/image/thumbnail/' + record.get('path') + '_140x140.' + record.get('extension'); } else { - var name = record.get('path').replace('media/image/', ''); + var name = record.get('path').replace('media/image/', ''); name = name.replace('.' + record.get('extension'), ''); return 'media/image/thumbnail/' + name + '_140x140.' + record.get('extension'); } @@ -39,7 +40,7 @@ Ext.define('Shopware.apps.CustomSort.model.Article', { * Configure the data communication * @object */ - proxy:{ + proxy: { /** * Set proxy type to ajax * @string diff --git a/Views/backend/custom_sort/model/settings.js b/Views/backend/custom_sort/model/settings.js index 5ba3a2d..8944775 100644 --- a/Views/backend/custom_sort/model/settings.js +++ b/Views/backend/custom_sort/model/settings.js @@ -1,5 +1,6 @@ //{block name="backend/custom_sort/model/settings"} Ext.define('Shopware.apps.CustomSort.model.Settings', { + /** * Extend for the standard ExtJS 4 * @string diff --git a/Views/backend/custom_sort/store/article.js b/Views/backend/custom_sort/store/article.js index dd282cd..32e5acc 100644 --- a/Views/backend/custom_sort/store/article.js +++ b/Views/backend/custom_sort/store/article.js @@ -1,5 +1,6 @@ //{block name="backend/custom_sort/store/article"} Ext.define('Shopware.apps.CustomSort.store.Article', { + /** * Extend for the standard ExtJS 4 * @string @@ -16,7 +17,7 @@ Ext.define('Shopware.apps.CustomSort.store.Article', { * Define the used model for this store * @string */ - model : 'Shopware.apps.CustomSort.model.Article', + model: 'Shopware.apps.CustomSort.model.Article', /** * Page range of the store @@ -24,7 +25,7 @@ Ext.define('Shopware.apps.CustomSort.store.Article', { pageSize: 10, listeners: { - write: function(store) { + write: function (store) { store.load(); } } diff --git a/Views/backend/custom_sort/store/settings.js b/Views/backend/custom_sort/store/settings.js index 1023635..b557ab8 100644 --- a/Views/backend/custom_sort/store/settings.js +++ b/Views/backend/custom_sort/store/settings.js @@ -1,5 +1,6 @@ //{block name="backend/custom_sort/store/settings"} Ext.define('Shopware.apps.CustomSort.store.Settings', { + /** * Extend for the standard ExtJS 4 * @string @@ -16,7 +17,7 @@ Ext.define('Shopware.apps.CustomSort.store.Settings', { * Define the used model for this store * @string */ - model : 'Shopware.apps.CustomSort.model.Settings' + model: 'Shopware.apps.CustomSort.model.Settings' }); //{/block} \ No newline at end of file diff --git a/Views/backend/custom_sort/store/tree.js b/Views/backend/custom_sort/store/tree.js index b81edab..bcb63d8 100644 --- a/Views/backend/custom_sort/store/tree.js +++ b/Views/backend/custom_sort/store/tree.js @@ -1,5 +1,6 @@ //{block name="backend/custom_sort/store/tree"} Ext.define('Shopware.apps.CustomSort.store.Tree', { + /** * Extend for the standard ExtJS 4 * @string @@ -13,7 +14,7 @@ Ext.define('Shopware.apps.CustomSort.store.Tree', { */ defaultRootId: 1, - alias : 'store.category', + alias: 'store.category', /** * Disable auto loading for this store diff --git a/Views/backend/custom_sort/view/article/list.js b/Views/backend/custom_sort/view/article/list.js index 17bd4f0..0d51dc7 100644 --- a/Views/backend/custom_sort/view/article/list.js +++ b/Views/backend/custom_sort/view/article/list.js @@ -55,8 +55,8 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { } }; - me.items = [ me.createArticleView() ]; - me.dockedItems = [ me.getPagingBar() ]; + me.items = [me.createArticleView()]; + me.dockedItems = [me.getPagingBar()]; me.callParent(arguments); }, @@ -67,7 +67,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { * * @return [object] this.dataView - created Ext.view.View */ - createArticleView: function() { + createArticleView: function () { var me = this; me.dataView = Ext.create('Ext.view.View', { @@ -80,7 +80,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { loadMask: false, tpl: me.createArticleViewTemplate(), listeners: { - itemclick: function(view, record, item, idx, event, opts) { + itemclick: function (view, record, item, idx, event, opts) { if (event.target.classList.contains('remove')) { me.fireEvent('remove', me.store, record); } @@ -104,7 +104,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { * * @return [object] generated Ext.XTemplate */ - createArticleViewTemplate: function() { + createArticleViewTemplate: function () { var me = this; return new Ext.XTemplate( '{literal}', @@ -131,7 +131,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { '
{/literal}', { //Add class if current product is first position in store list - startPage: function(article, index) { + startPage: function (article, index) { var store = me.store, view = me.dataView, position, @@ -139,12 +139,12 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { position = store.indexOf(record) + ((store.currentPage - 1) * store.pageSize); if (position == 0) { - return ' disabled'; + return ' disabled'; } }, //Add class if current product is on first page in store list - prevPage: function(index) { + prevPage: function (index) { var store = me.store, pageSize = store.allProductsPageSize; @@ -156,7 +156,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { }, //Add class if current product is on last page in store list - nextPage: function(index) { + nextPage: function (index) { var store = me.store, lastPage, pageSize = store.allProductsPageSize; @@ -170,7 +170,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { }, //Add class if current product is on last position in store list - endPage: function(article, index) { + endPage: function (article, index) { var store = me.store, view = me.dataView, position, @@ -188,12 +188,12 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { /** * Create trigger catch when fast move button is click */ - registerMoveActions: function() { + registerMoveActions: function () { var me = this; var el = me.el; //Trigger event when "move to start" action is clicked - el.on('click', function(event, target) { + el.on('click', function (event, target) { if (target.classList.contains('disabled')) { return false; } @@ -204,7 +204,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { }); //Trigger event when "move to end" action is clicked - el.on('click', function(event, target) { + el.on('click', function (event, target) { if (target.classList.contains('disabled')) { return false; } @@ -215,7 +215,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { }); //Trigger event when "move to prev page" action is clicked - el.on('click', function(event, target) { + el.on('click', function (event, target) { if (target.classList.contains('disabled')) { return false; } @@ -226,7 +226,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { }); //Trigger event when "move to next page" action is clicked - el.on('click', function(event, target) { + el.on('click', function (event, target) { if (target.classList.contains('disabled')) { return false; } @@ -242,7 +242,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { * * @return Ext.toolbar.Paging */ - getPagingBar: function() { + getPagingBar: function () { var me = this, productSnippet = '{s name=list/pagingCombo/products}products{/s}', allProducts = '{s name=list/pagingCombo/allProducts}All products{/s}'; @@ -259,7 +259,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { select: me.onPageSizeChange }, store: Ext.create('Ext.data.Store', { - fields: [ 'value', 'name' ], + fields: ['value', 'name'], data: [ { value: '10', name: '10 ' + productSnippet }, { value: '25', name: '25 ' + productSnippet }, @@ -280,7 +280,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { }); //Fire event when user uses paging toolbar - pagingBar.on('beforechange', function() { + pagingBar.on('beforechange', function () { me.fireEvent('pageChange'); }); @@ -289,7 +289,6 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { pageSize ]); - return pagingBar; }, @@ -320,20 +319,20 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { /** * Creates the drag and drop zone for the Ext.view.View to allow */ - initDragAndDrop: function() { + initDragAndDrop: function () { var me = this; - me.dataView.on('afterrender', function(v) { + me.dataView.on('afterrender', function (v) { var selModel = v.getSelectionModel(); me.dataView.dragZone = new Ext.dd.DragZone(v.getEl(), { ddGroup: 'Article', - getDragData: function(e) { + getDragData: function (e) { var sourceEl = e.getTarget(v.itemSelector, 10); if (sourceEl) { var selected = selModel.getSelection(), record = v.getRecord(sourceEl); - if(!selected.length) { + if (!selected.length) { selModel.select(record); selected = selModel.getSelection(); } @@ -353,29 +352,29 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { return result; } }, - getRepairXY: function() { + getRepairXY: function () { return this.dragData.repairXY; } }); me.dataView.dropZone = new Ext.dd.DropZone(me.dataView.getEl(), { ddGroup: 'Article', - getTargetFromEvent: function(e) { + getTargetFromEvent: function (e) { return e.getTarget(me.dataView.itemSelector); }, - onNodeEnter : function(target, dd, e, data) { + onNodeEnter: function (target, dd, e, data) { var record = me.dataView.getRecord(target); if (record !== data.draggedRecord) { Ext.fly(target).addCls(me.dragOverCls); } }, - onNodeOut : function(target, dd, e, data) { + onNodeOut: function (target, dd, e, data) { Ext.fly(target).removeCls(me.dragOverCls); }, - onNodeDrop : function(target, dd, e, data) { + onNodeDrop: function (target, dd, e, data) { var draggedRecord = me.dataView.getRecord(target); var articleModels = data.articleModels; @@ -386,6 +385,5 @@ Ext.define('Shopware.apps.CustomSort.view.article.List', { me.registerMoveActions(); }); } - }); //{/block} \ No newline at end of file diff --git a/Views/backend/custom_sort/view/article/view.js b/Views/backend/custom_sort/view/article/view.js index 4b03325..d974564 100644 --- a/Views/backend/custom_sort/view/article/view.js +++ b/Views/backend/custom_sort/view/article/view.js @@ -12,7 +12,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.View', { * Register the alias for this class. * @string */ - alias : 'widget.sort-articles-view', + alias: 'widget.sort-articles-view', /** * The Ext.container.Container.layout for the fieldset's immediate child items. @@ -32,14 +32,16 @@ Ext.define('Shopware.apps.CustomSort.view.article.View', { * * @return void */ - initComponent: function() { + initComponent: function () { var me = this; me.tbar = me.createActionToolbar(); - me.items = [{ - xtype: 'sort-articles-list', - store: me.articleStore - }]; + me.items = [ + { + xtype: 'sort-articles-list', + store: me.articleStore + } + ]; me.callParent(arguments); }, @@ -49,7 +51,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.View', { * * @return [Ext.toolbar.Toolbar] grid toolbar */ - createActionToolbar: function() { + createActionToolbar: function () { var me = this; //Create checkbox for displaying custom sort by default @@ -60,7 +62,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.View', { inputValue: 1, uncheckedValue: 0, listeners: { - change: function(oldValue, newValue) { + change: function (oldValue, newValue) { if (me.store.data.items[0].data.defaultSort != newValue) { me.fireEvent('defaultSort'); } @@ -73,7 +75,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.View', { valueField: 'id', displayField: 'name', treeField: 'categoryId', - selectedRecord : me.record, + selectedRecord: me.record, store: Ext.create('Shopware.store.CategoryTree'), forceSelection: true, fieldLabel: '{s name=view/category_sync}Sync from category{/s}', @@ -85,7 +87,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.View', { rootVisible: false, enableKeyEvents: true, listeners: { - select: function(field, record) { + select: function (field, record) { me.fireEvent('categoryLink', record); }, keyup: function () { @@ -107,7 +109,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.View', { name: 'baseSort', labelClsExtra: 'swag-custom-sort-radiobtn-topmargin', store: Ext.create('Ext.data.Store', { - fields: [ 'id', 'name' ], + fields: ['id', 'name'], data: [ { id: 1, name: '{s name=view/sort/release}Release date{/s}' }, { id: 2, name: '{s name=view/sort/popularity}Popularity{/s}' }, @@ -121,7 +123,7 @@ Ext.define('Shopware.apps.CustomSort.view.article.View', { ] }), listeners: { - select: function(field, records) { + select: function (field, records) { var sort = records[0].get('id'); me.fireEvent('sortChange', sort); } @@ -135,6 +137,5 @@ Ext.define('Shopware.apps.CustomSort.view.article.View', { me.sorting ]; } - }); //{/block} \ No newline at end of file diff --git a/Views/backend/custom_sort/view/category/tree.js b/Views/backend/custom_sort/view/category/tree.js index 43f38d1..9ae5eb6 100644 --- a/Views/backend/custom_sort/view/category/tree.js +++ b/Views/backend/custom_sort/view/category/tree.js @@ -12,7 +12,7 @@ Ext.define('Shopware.apps.CustomSort.view.category.Tree', { * Register the alias for this class. * @string */ - alias : 'widget.sort-category-tree', + alias: 'widget.sort-category-tree', collapsible: true, @@ -33,7 +33,7 @@ Ext.define('Shopware.apps.CustomSort.view.category.Tree', { /** * Initialize the controller and defines the necessary default configuration */ - initComponent : function() { + initComponent: function () { var me = this; me.columns = me.createColumns(); @@ -46,16 +46,17 @@ Ext.define('Shopware.apps.CustomSort.view.category.Tree', { * * @return [array] columns - generated columns */ - createColumns : function() { - var columns = [{ + createColumns: function () { + var columns = [ + { xtype: 'treecolumn', sortable: false, - flex:1, + flex: 1, dataIndex: 'text' - }]; + } + ]; return columns; } - }); //{/block} diff --git a/Views/backend/custom_sort/view/main/window.js b/Views/backend/custom_sort/view/main/window.js index a85c515..b04d79d 100644 --- a/Views/backend/custom_sort/view/main/window.js +++ b/Views/backend/custom_sort/view/main/window.js @@ -1,7 +1,7 @@ //{namespace name="backend/custom_sort/view/main"} //{block name="backend/custom_sort/view/main/main"} Ext.define('Shopware.apps.CustomSort.view.main.Window', { - + extend: 'Enlight.app.Window', alias: 'widget.sort-main-window', @@ -24,7 +24,7 @@ Ext.define('Shopware.apps.CustomSort.view.main.Window', { * Sets up the ui component * @return void */ - initComponent: function() { + initComponent: function () { var me = this; me.items = me.createItems(); @@ -36,21 +36,23 @@ Ext.define('Shopware.apps.CustomSort.view.main.Window', { * Creates the elements for this component. * @return array */ - createItems: function() { + createItems: function () { var me = this; - return [{ - xtype: 'sort-category-tree', - region: 'west', - flex: 0.25, - store: me.treeStore - }, { - xtype: 'sort-articles-view', - region: 'center', - store: me.categorySettings, - treeStore: me.treeStore, - articleStore: me.articleStore - }]; + return [ + { + xtype: 'sort-category-tree', + region: 'west', + flex: 0.25, + store: me.treeStore + }, { + xtype: 'sort-articles-view', + region: 'center', + store: me.categorySettings, + treeStore: me.treeStore, + articleStore: me.articleStore + } + ]; } }); diff --git a/plugin.json b/plugin.json index 32a2076..41eb7e1 100644 --- a/plugin.json +++ b/plugin.json @@ -1,6 +1,6 @@ { "label": { - "de": "Custom sorting", + "de": "Individuelle Sortierung", "en": "Custom sorting" }, "copyright": "(c) by Shopware AG", @@ -11,12 +11,12 @@ "currentVersion": "1.0.0", "changelog": { - "de": { - "1.0.0": "First version of Custom sorting" - }, - "en": { - "1.0.0": "First version of Custom sorting" - } + "de": { + "1.0.0": "PT-2775 - Erstveröffentlichung;" + }, + "en": { + "1.0.0": "PT-2775 - First release;" + } }, "compatibility": { @@ -25,4 +25,4 @@ "blacklist": [ ] } -} \ No newline at end of file +}