├── .gitignore ├── modman ├── documentation ├── backend_configuration.jpg └── product_configuration.jpg ├── nbproject ├── project.properties └── project.xml ├── app └── code │ └── Lemundo │ └── FeaturedProducts │ ├── etc │ ├── module.xml │ ├── catalog_attributes.xml │ ├── config.xml │ ├── di.xml │ ├── view.xml │ └── adminhtml │ │ └── system.xml │ ├── view │ └── frontend │ │ ├── web │ │ └── css │ │ │ └── module.less │ │ ├── layout │ │ └── default.xml │ │ └── templates │ │ └── list.phtml │ ├── data │ └── lemundo_featuredproducts_setup │ │ └── data-install-0.0.1.php │ └── Block │ └── ProductList.php ├── composer.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /nbproject/private/ -------------------------------------------------------------------------------- /modman: -------------------------------------------------------------------------------- 1 | app/code/Lemundo/FeaturedProducts/ app/code/Lemundo/FeaturedProducts/ -------------------------------------------------------------------------------- /documentation/backend_configuration.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mpaepper/Magento2-FeaturedProducts/HEAD/documentation/backend_configuration.jpg -------------------------------------------------------------------------------- /documentation/product_configuration.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mpaepper/Magento2-FeaturedProducts/HEAD/documentation/product_configuration.jpg -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | include.path=${php.global.include.path} 2 | php.version=PHP_54 3 | source.encoding=UTF-8 4 | src.dir=. 5 | tags.asp=false 6 | tags.short=false 7 | web.root=. 8 | -------------------------------------------------------------------------------- /app/code/Lemundo/FeaturedProducts/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/code/Lemundo/FeaturedProducts/etc/catalog_attributes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.php.project 4 | 5 | 6 | m2featuredProducts 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/code/Lemundo/FeaturedProducts/view/frontend/web/css/module.less: -------------------------------------------------------------------------------- 1 | div.main { 2 | ul.products.list.featured { 3 | margin: 0 -10px; 4 | 5 | &:after { 6 | content: ""; 7 | display: block; 8 | clear: both; 9 | } 10 | 11 | li { 12 | float: left; 13 | 14 | div.product { 15 | padding: 10px; 16 | } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /app/code/Lemundo/FeaturedProducts/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 3 13 | 300 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/code/Lemundo/FeaturedProducts/etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Magento\Catalog\Model\Resource\Setup 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/code/Lemundo/FeaturedProducts/view/frontend/layout/default.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 17 | 18 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lemundo/featured-products", 3 | "description": "This module enables products to be marked as featured products which can then be shown in a special block, e.g. on your home page.", 4 | "require": { 5 | "php": "~5.4.11|~5.5.0|~5.6.0", 6 | "magento/magento-composer-installer": "*" 7 | }, 8 | "type": "magento2-module", 9 | "authors": [ 10 | { 11 | "name": "Michael Timm", 12 | "email": "m.timm@lemundo.de" 13 | }, 14 | { 15 | "name": "Marc Päpper", 16 | "email": "m.paepper@lemundo.de" 17 | } 18 | ], 19 | "version": "0.42.0-beta6", 20 | "license": [ 21 | "OSL-3.0", 22 | "AFL-3.0" 23 | ], 24 | "extra": { 25 | "map": [ 26 | [ 27 | "*", 28 | "Lemundo/FeaturedProducts" 29 | ] 30 | ] 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/code/Lemundo/FeaturedProducts/view/frontend/templates/list.phtml: -------------------------------------------------------------------------------- 1 | getProducts(); 3 | $_config = $this->getConfig(); 4 | $_columnWidth = 100 / $this->getProductLimit(); 5 | $_imageWidth = $this->getImageWidth(); 6 | ?> 7 | 8 |

9 | 10 | -------------------------------------------------------------------------------- /app/code/Lemundo/FeaturedProducts/data/lemundo_featuredproducts_setup/data-install-0.0.1.php: -------------------------------------------------------------------------------- 1 | startSetup(); 7 | 8 | $installer->addAttribute( 9 | \Magento\Catalog\Model\Product::ENTITY, 10 | 'lemundo_featured_product', 11 | [ 12 | 'type' => 'int', 13 | 'backend' => '', 14 | 'frontend' => '', 15 | 'label' => 'Is Featured Product', 16 | 'input' => 'select', 17 | 'class' => '', 18 | 'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean', 19 | 'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL, 20 | 'visible' => true, 21 | 'required' => false, 22 | 'user_defined' => true, 23 | 'default' => '0', 24 | 'searchable' => false, 25 | 'filterable' => false, 26 | 'comparable' => false, 27 | 'visible_on_front' => false, 28 | 'used_in_product_listing' => true, 29 | 'unique' => false, 30 | 'group' => 'Product Details' 31 | ] 32 | ); 33 | 34 | $installer->endSetup(); -------------------------------------------------------------------------------- /app/code/Lemundo/FeaturedProducts/etc/view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 1 11 | 50 12 | 75 13 | 85 14 | 135 15 | 56 16 | 265 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/code/Lemundo/FeaturedProducts/etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Documentation for mage2Modules/featuredProducts 2 | 3 | ### First words 4 | 5 | This module was created during our monthly hackathon at Lemundo (http://www.lemundo.de) to get comfortable with Magento2. 6 | Since Magento2 is still in the early beta, use it at your own risk. No guarantee from our side ;) 7 | 8 | ### Purpose of this module 9 | 10 | The module creates a new boolean product attribute which you can set to Yes/No at the product. 11 | All products which are set to Yes are featured products. 12 | They will be shown in a custom block of this module, which you can include within a CMS file using: 13 | ```{{block class="Lemundo\FeaturedProducts\Block\ProductList" template="list.phtml"}}``` 14 | or in the XML via `````` 15 | 16 | ### Backend configuration 17 | 18 | There are two possible settings in the backend under the group "Featured Products" in the system configuration. 19 | You can set a limit of products which is the maximum number of featured products shown inside the block (they are randomized, Default: 3). 20 | And you can set the width of the product image in pixels (Default: 300). 21 | 22 | See screenshot: 23 | 24 | ![Backend Configuration](documentation/backend_configuration.jpg) 25 | 26 | When you edit a product, the new attribute will be visible in the "Product Details" group at the very bottom. 27 | By default it is set to No for all products. Set it to Yes for your featured products as shown in the screenshot and save the product: 28 | 29 | ![Product Configuration](documentation/product_configuration.jpg) 30 | 31 | ### Installation 32 | 33 | You can install this module in three ways: 34 | 35 | * a) Copy the folder app/ into your magento2 store 36 | * b) Using modman: modman init followed by modman clone /url/to/this/repository 37 | * c) Using composer: Add the module to your composer.json file 38 | 39 | After either of theses three ways, you need to activate the module by editing your app/etc/config.php file: 40 | 41 | ``` 42 | ... 43 | 'modules' => 44 | array ( 45 | 'Lemundo_FeaturedProducts' => 1, 46 | ... 47 | ``` 48 | 49 | Afterwards, make sure that Magento installs the new attribute by running: ```php setup/index.php update``` 50 | 51 | ### Authors 52 | 53 | * Michael Timm 54 | * Marc Päpper (https://twitter.com/mpaepper) 55 | -------------------------------------------------------------------------------- /app/code/Lemundo/FeaturedProducts/Block/ProductList.php: -------------------------------------------------------------------------------- 1 | _objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 53 | $this->_collection = $collection; 54 | $this->_config = $scopeConfig->getValue('featured_products/settings'); 55 | $this->_imageHelper = $imageHelper; 56 | 57 | parent::__construct($context, $data); 58 | } 59 | 60 | 61 | /** 62 | * Get product collection 63 | */ 64 | public function getProducts() { 65 | $limit = $this->getProductLimit(); 66 | 67 | $collection = $this->_collection 68 | ->addMinimalPrice() 69 | ->addFinalPrice() 70 | ->addTaxPercents() 71 | ->addAttributeToSelect('name') 72 | ->addAttributeToSelect('image') 73 | ->addAttributeToFilter('is_saleable', 1, 'left') 74 | ->addAttributeToFilter('lemundo_featured_product', 1, 'left'); 75 | 76 | $collection->getSelect() 77 | ->order('rand()') 78 | ->limit($limit); 79 | 80 | return $collection; 81 | } 82 | 83 | 84 | /** 85 | * Get image helper 86 | */ 87 | public function getImageHelper() { 88 | return $this->_imageHelper; 89 | } 90 | 91 | 92 | /** 93 | * Get module configuration 94 | */ 95 | public function getConfig() { 96 | return $this->_config; 97 | } 98 | 99 | /** 100 | * Get the configured limit of products 101 | * @return int 102 | */ 103 | public function getProductLimit() { 104 | return $this->_config["limit"]; 105 | } 106 | 107 | /** 108 | * Get the configured width of images 109 | * @return int 110 | */ 111 | public function getImageWidth() { 112 | return $this->_config["image_width"]; 113 | } 114 | 115 | } --------------------------------------------------------------------------------