Magento 2 Request Flow
You can learn about Magento 2 Request Flow from this presentation by Anton Kril:
You can learn about Magento 2 Request Flow from this presentation by Anton Kril:
Right in refresh .less files, since it “collects, processes and publishes source LESS files”:
1 |
php bin/magento dev:css:deploy |
You can also use dev mode during development. According to
In a case of a controller that extends Magento\Framework\App\Action\Action, it is possible to get the request with the aid of $this->getRequest()->getPost().
For a custom class, inject the request in the constructor:
1 |
<?php namespace Namespace\Module\Something; class ClassName { protected $request; public function __construct( \Magento\Framework\App\Request\Http $request, ....//rest of parameters here ) { $this->request = $request; ...//rest of constructor here } public function getPost() { return $this->request->getPost(); } } |
In Magento 2, the LESS PHP adapter is located in \lib\internal\Magento\Framework\View\Page\Config\Renderer, and you can easily replace it with another one (SASS for instance) by updating the following lines of code in the di.xml configuration:
1 |
<item name=”server_side_compilation” xsi:type=”string”>Magento\Framework\View\Page\Config\Renderer</item> |
By calling setTemplate method of course!
1 2 3 4 5 |
<referenceBlock name='copyright'> <action method='setTemplate'> <argument name='template' xsi:type='string'>Dfr_Backend::page/copyright.phtml</argument> </action> </referenceBlock> |
Being a boolean attribute, defer specifies that the script is executed after the page parsing. The attribute is aimed at external scripts only (the src attribute should be present). Find more information about defer
Despite Magento 2 supports standard script deferring, it never uses defer in its core. To change the situation, you can use the following code:
1 2 3 4 5 6 7 8 |
<?xml version='1.0'?> <page xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' layout='admin-login' xsi:noNamespaceSchemaLocation='../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd'> <head> <script src='Dfe_Login::main.js' defer='defer'/> </head> </page> |
Go to Magento 2 Admin -> Stores -> Configuration -> Developer; select a specific store scope, and set “Template page hints” and “Add block names to hints” to Yes. You should get the following results:
More tips from Magento 2 Developer’s Cookbook Continue Reading
First of all, I’d like to draw your attention to this blog post:
This is a great fork of Magento 2 from Mageinferno. It includes all composer packages (vendor folder), and you can get in on Github:
More tips from Magento 2 Developer’s Cookbook Continue Reading
If the simple and configurable products are not assigned together like in the folowing example, there is a reliable solution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
//simple product $simple_product = $this->_objectManager->create('\Magento\Catalog\Model\Product'); $simple_product->setSku('test-simple'); $simple_product->setName('test name simple'); $simple_product->setAttributeSetId(4); $simple_product->setSize_general(193); // value id of S size $simple_product->setStatus(1); $simple_product->setTypeId('simple'); $simple_product->setPrice(10); $simple_product->setWebsiteIds(array(1)); $simple_product->setCategoryIds(array(31)); $simple_product->setStockData(array( 'use_config_manage_stock' => 0, //'Use config settings' checkbox 'manage_stock' => 1, //manage stock 'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart 'max_sale_qty' => 2, //Maximum Qty Allowed in Shopping Cart 'is_in_stock' => 1, //Stock Availability 'qty' => 100 //qty ) ); $simple_product->save(); $simple_product_id = $simple_product->getId(); echo "simple product id: ".$simple_product_id."\n"; //configurable product $configurable_product = $this->_objectManager->create('\Magento\Catalog\Model\Product'); $configurable_product->setSku('test-configurable'); $configurable_product->setName('test name configurable'); $configurable_product->setAttributeSetId(4); $configurable_product->setStatus(1); $configurable_product->setTypeId('configurable'); $configurable_product->setPrice(11); $configurable_product->setWebsiteIds(array(1)); $configurable_product->setCategoryIds(array(31)); $configurable_product->setStockData(array( 'use_config_manage_stock' => 0, //'Use config settings' checkbox 'manage_stock' => 1, //manage stock 'is_in_stock' => 1, //Stock Availability ) ); $configurable_product->getTypeInstance()->setUsedProductAttributeIds(array(152),$configurable_product); //attribute ID of attribute 'size_general' in my store $configurableAttributesData = $configurable_product->getTypeInstance()->getConfigurableAttributesAsArray($configurable_product); $configurable_product->setCanSaveConfigurableAttributes(true); $configurable_product->setConfigurableAttributesData($configurableAttributesData); $configurableProductsData = array(); $configurableProductsData[$simple_product_id] = array( //[$simple_product_id] = id of a simple product associated with this configurable '0' => array( 'label' => 'S', //attribute label 'attribute_id' => '152', //attribute ID of attribute 'size_general' in my store 'value_index' => '193', //value of 'S' index of the attribute 'size_general' 'is_percent' => 0, 'pricing_value' => '10', ) ); $configurable_product->setConfigurableProductsData($configurableProductsData); $configurable_product->save(); echo "configurable product id: ".$configurable_product->getId()."\n"; |
You can review on API functional test aimed at
1 2 3 4 5 6 |
$product = $productFactory->create(['name'=> 'configurable product', ... ]); $configurableOption = $optionFactory->create([]); $linkedProduct = $linkFactory->create([]); $product->getExtensionAttributes()->setConfigurableProductOptions($configurableOption)l $product->getExtensionAttributes()->setConfigurableProductLinks($linkedProduct); $productRepository->save($product) |
It is also necessary to mention that the API does not generate simple product, so there is the need to create in advance.