Book Image

Magento Extensions Development

By : Bouchet
Book Image

Magento Extensions Development

By: Bouchet

Overview of this book

Magento has been revealed as the best and the most popular open source e-commerce platform in the world, with about 250k+ online stores. Magento 2 is the most recent version of this awesome toolset: every new and modern development techniques are used to offer a real modular approach and powerful architecture. The book will support you in the writing of innovative and complex extensions. Starting from the beginning, we will cover how to set up a development environment that allows you to be really efficient in your functionality writing, including GIT registering and many other development tools. We then move on to provide a large overview of the best practices to scale your module in a high-load environment. After these foundations, you will see how to use test driven-development (TDD) and unit tests to handle your code. We then build a complex extension together, step by step, and internationally-ready. Next, you will find out how to protect the users’ data. Finally, we will take a look a publishing the extension on the new Magento Connect marketplace and how to protect your intellectual property. After you read this book, you will know everything you need to know to become an invaluable extension editor, whether it is for your customers’ needs or for your own requirements.
Table of Contents (11 chapters)
10
Index

Store relation table

In our extension, we will handle the store views scope by using a relation table. This behavior is also used for the CMS pages or blocks, reviews, ratings, and all the models that are not EAV-based and need to be store views-related.

Creating the new table

The first step is to create the new table to store the new data:

  1. Create the [extension_path]/Setup/UpgradeSchema.php file and add the following code:
    <?php
    
    namespace Blackbird\TicketBlaster\Setup;
    
    use Magento\Eav\Setup\EavSetup;
    use Magento\Eav\Setup\EavSetupFactory;
    use Magento\Framework\Setup\UpgradeSchemaInterface;
    use Magento\Framework\Setup\ModuleContextInterface;
    use Magento\Framework\Setup\SchemaSetupInterface;
    
    /**
     * @codeCoverageIgnore
     */
    class UpgradeSchema implements UpgradeSchemaInterface
    {
        /**
         * EAV setup factory
         *
         * @varEavSetupFactory
         */
        private $eavSetupFactory;
    
        /**
         * Init
         *
         * @paramEavSetupFactory $eavSetupFactory
         */
        public function __construct...