Run the following command to disable developer mode
php bin/magento deploy:mode:set production
Run the following command to disable developer mode
php bin/magento deploy:mode:set production
Run the following command to enable developer mode
php bin/magento deploy:mode:set developer
Run the following commands to fix this issue.
php bin/magento cache:flush
bin/magento setup:di:compile
php bin/magento setup:upgrade
bin/magento setup:di:compile
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productcollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $subscriptionProductcollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection') ->addAttributeToSelect('*') ->addAttributeToFilter( array( array('attribute'=>'subscripion_product','eq'=>1) ) );
You can set the deault layout as layout attribute value of page tag. For example
<page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” layout=”2columns-left” xsi:noNamespaceSchemaLocation=”urn:magento:framework:View/Layout/etc/page_configuration.xsd”>
You can limit the number of products per page from admin panel.
1) Go to Admin panel and click Stores > Configuration .
2) Then click Catalog in the lept panel and then select Catalog > Storefront section > Products per Page on Grid Default Value
Here i am creating upgradeData script that will add custom product attribute with yes and no options.
<?php namespace PHPCodez\Subscription\Setup; use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; class upgradeData implements UpgradeDataInterface { private $eavSetupFactory; protected $logger; public function __construct(EavSetupFactory $eavSetupFactory,\Psr\Log\LoggerInterface $logger) { $this->eavSetupFactory = $eavSetupFactory; $this->logger = $logger; } public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { if (version_compare($context->getVersion(), '0.0.8', '<=')) { $this->logger->info("System - upgrading module - removing product attribute - subscripion_product"); $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); $eavSetup->addAttribute( \Magento\Catalog\Model\Product::ENTITY, 'subscripion_product',[ 'type' => 'text', 'backend' => '', 'frontend' => '', 'label' => 'Enable Subscription', 'input' => 'select', 'class' => '', 'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean', 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, 'visible' => true, 'required' => true, 'user_defined' => false, 'default' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'visible_on_front' => false, 'used_in_product_listing' => true, 'unique' => false, 'apply_to' => '' ] ); } } }
You can add a new non catgory navigation menu as follows
1) Add the below code in layout XML
File : app\code\PHPcodez\Subscription\view\frontend\layout\default.xml
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="catalog.topnav"> <block class="PHPCodez\Subscription\Block\Link" name="your.link"> <arguments> <argument name="label" xsi:type="string">Subscription</argument> <argument name="path" xsi:type="string">subscription</argument> </arguments> </block> </referenceContainer> </body> </page>
2) Define the block Link.php
File : app\code\PHPcodez\Subscription\Block\Link.php
<?php namespace PHPCodez\Subscription\Block; class Link extends \Magento\Framework\View\Element\Html\Link { protected function _toHtml() { if (false != $this->getTemplate()) { return parent::_toHtml(); } return '<li class="level0 "><a ' . $this->getLinkAttributes() . ' class="level-top" >' . $this->escapeHtml($this->getLabel()) . '</a></li>'; } }