Missing PHP extensions during composer install/update 2


If you get any error saying missing PHP extensions during composer update or install please do followings.

  1. Make sure you have those extensions installed by running
    php -m
  2. If you do not have missing extensions enable it from php.ini or install them. Installation instructions depends on your desto.
  3. If you are still getting the error while you already have installed the extensions your composer need to be updated.
     composer selfupdate

Magento 2 CDN / Static file signing 0


Magento 1 does not come with built in CDN support (version control system). In Magento 2 you can enable version control for static files by setting Store=>Configuration=>Advanced=>Developer=>Static file settings to yes. This will create text file under pub/static/deployed_version.txt with version number. In developer mode it will automatically get updated with time stamp.

CDN, Static, Signing, Magento 2

CDN, Static, Signing, Magento 2

Magento 2 Theming with Grunt / Less Part 2 0


Installing and configuring Grunt

  1. Install node.js to any location on your machine.
  2. Install Grunt CLI tool globally. To do this, run the following command in a command prompt:
    npm install -g grunt-cli
  3. Install Grunt in your Magento directory. To do this, run the following commands in a command prompt:
    cd <your_Magento_instance_directory>
    npm install grunt --save-dev
  4. Install (or refresh) the node.js project dependency for your Magento instance. To do this, run the following commands in a command prompt:
    cd <your_Magento_instance_directory>
    npm install
    npm update
  5. Add your theme to Grunt configuration. To do this, in the dev/tools/grunt/configs/theme.js file
  6. If you want to use Grunt for “watching” changes automatically, without reloading pages in a browser each time, install the LiveReload extension in your browser.
  7. Check the video for complete Magento 2 installation, creating theme, installing and configuring grunt and some debugging. Magento 2 Installation

Magento 2 setup Upgrade scripts 0


  1. Under your Magento 2 module > inside the directory “Setup”
    (Create Magento 2 Module, Magento 2 install scripts)
    Create a new file: “UpgradeData.php” with the below content.

    
    <?php
    namespace Magleaks\Catalog\Setup;
    
    use Magento\Catalog\Model\Product;
    use Magento\Eav\Setup\EavSetupFactory;
    use Magento\Framework\Setup\ModuleContextInterface;
    use Magento\Framework\Setup\ModuleDataSetupInterface;
    use Magento\Framework\Setup\UpgradeDataInterface;
    
    class UpgradeData implements UpgradeDataInterface
    {
        /**
         * EAV setup factory
         *
         * @var EavSetupFactory
         */
        private $eavSetupFactory;
    
        /**
         * Init
         *
         * @param EavSetupFactory $eavSetupFactory
         */
        public function __construct(EavSetupFactory $eavSetupFactory)
        {
            $this->eavSetupFactory = $eavSetupFactory;
        }
    
        /**
         * @param ModuleDataSetupInterface $setup
         * @param ModuleContextInterface   $context
         */
        public function upgrade(
            ModuleDataSetupInterface $setup,
            ModuleContextInterface $context
        ) {
            $dbVersion = $context->getVersion();
            /** @var EavSetup $eavSetup */
            $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
    
            if (version_compare($dbVersion, '2.0.1', '<')) { // update an existing product attribute to add as soring options
                $eavSetup->updateAttribute(
                    Product::ENTITY,
                    'name',
                    'used_for_sort_by',
                    false
                );
            }
        }
    }
    
    
  2. Update the setup_version of your module in “etc/module.xml” file in your Module.

    
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
        <module name="Magleaks_Catalog" setup_version="2.0.1"/>
    </config>
    
    
  3. Go to your Magento 2 root folder from your terminal and run

    
    bin/magento setup:upgrade
    

Magento 2 create product attributes using install scripts 0


  1. Under your Magento 2 module, create a directory called “Setup”. (Create Magento 2 Module)
  2. Create a new file: “InstallData.php” inside the Setup directory with the below content.

    
    <?php
    namespace Magleaks\Catalog\Setup;
    
    use Magento\Catalog\Model\Product;
    use Magento\Catalog\Model\Product\Type;
    use Magento\Catalog\Model\Resource\Eav\Attribute;
    use Magento\Eav\Setup\EavSetupFactory;
    use Magento\Framework\Setup\InstallDataInterface;
    use Magento\Framework\Setup\ModuleContextInterface;
    use Magento\Framework\Setup\ModuleDataSetupInterface;
    
    /**
     * Class InstallData
     *
     * @package Magleaks\Catalog\Setup
     */
    class InstallData implements InstallDataInterface
    {
        /**
         * @var \Magento\Eav\Setup\EavSetupFactory
         */
        private $eavSetupFactory;
        /**
         * @param EavSetupFactory $eavSetupFactory
         */
        public function __construct(EavSetupFactory $eavSetupFactory)
        {
            $this->eavSetupFactory = $eavSetupFactory;
        }
        /**
         * @param ModuleDataSetupInterface $setup
         * @param ModuleContextInterface   $context
         */
        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
            /** @var EavSetup $eavSetup */
            $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
            $productTypes = [
                Type::TYPE_SIMPLE,
                Type::TYPE_VIRTUAL,
            ];
            $productTypes = join(',', $productTypes);
            $eavSetup->addAttribute(
                Product::ENTITY,
                'on_sale',
                [
                    'type'                    => 'int',
                    'label'                   => 'Sale',
                    'input'                   => 'boolean',
                    'sort_order'              => 50,
                    'global'                  => Attribute::SCOPE_WEBSITE,
                    'user_defined'            => true,
                    'required'                => false,
                    'used_in_product_listing' => true,
                    'apply_to'                => $productTypes,
                    'group'                   => 'General',
                    'unique'                  => false,
                    'visible_on_front'        => false,
                    'searchable'              => false,
                    'filterable'              => false,
                    'comparable'              => false,
                    'visible'                 => true,
                    'backend'                 => '',
                    'frontend'                => '',
                    'class'                   => '',
                    'source'                  => '',
                    'default'                 => '',
                ]
            );
        }
    }
    
    
  3. Go to your Magento 2 root folder from your terminal and run

    
    bin/magento setup:upgrade