Best Improved Navigation Extension

Thursday, March 23, 2017

A research has noticed that eight away from ten students between the ages of ten and fifteen access it the web, posting personal profile in social network sites like Google+, Facebook, Twitter, MySpace and StumbleUpon, gossiping online layered navigation extension for magento 2 via IM application such as MSN, Yahoo Messenger, ICQ, Gtalk and etc. Someday, you suddenly discover a great deal of unknown persons on your own children's friend lists, these unknown persons aren't playmates, friends members, but people from all of within the country. What do they discuss? As parents, you'd definitely feel anxious over it. Are the pedophiles? Pedophiles are hiding out there and kids are already targeted, and they cannot awake on the peril after parents explain and inform them the potential risk of over exposure of private details as well as the significance about self-protection.
layered navigation extension for magento 2
1 - Pixel Mask This is easily the most common type of masking technique. It is used to hide and reveal pixel information. The mask can be applied in a number of ways. My preferred method is to create a selection using a pixel based selection tool including the polygonal lasso tool. Next choose the pixel mask button in the mask palette. On the resulting mask, black indicates hidden information and white visible information
Inside, you get a multi-layered dash, high-grade materials, neat fit and finish plus a real spacious feel. The functional controls are ergonomically designed, large and logically placed. The seats throughout are happy and can easily accommodate wider frames. Leg room for rear passengers can be a noteworthy plus. The Camry also provides storage a-plenty. The car emerges in four trim levels, the beds base L, LE, SE and XLE. In the XLE, you obtain easy-on-the-back, reclining rear seats (all trim levels get 60/40 split folding rear seating) which is not something that is normally offered in this segment. Across the board, the vehicles get Bluetooth phone connectivity, tilt-telescopic tire, as well as a touchscreen sound system, Bluetooth audio streaming, an iPod interface and a USB port. Other great options add the stressless voice command-based navigation system (by 50 % screen sizes--a 6.1-inch and 7.0-inch), keyless ignition, JBL audio and Toyota's Entune,' a smartphone connectivity system that allows users to adopt good thing about popular mobile apps like Pandora and sports and stock info.
Adding a verification number field only requires some small coding for the eCommerce area of the website, but it will aid greatly to fight charge card fraud. It is very important to request individuals to enter this number mainly because it eliminates the instances where people who steal charge card information from others through unconventional methods that may then utilize the information. Customers realize that this 3-digit number is available for the back with the card so ensure the shopping cart solution script which you have includes this feature.
magento 2 improved navigation The administrator portion of a shopping cart gives store owners a chance to add products for display on his or her web store and yes it usually supplies a mechanism for categorizing the items. The changes produced by an administrator in the backend section of the website should automatically be reflected in the public store.
A multi-user login script is a software system where many users can login using their unique login name and password and magento 2 layered navigation extension access protected division of that system. This protected area could be common to all users or could be user specific. All though a multi-user login script employed in any software application but here I'm going to discuss the principle of working of login script utilized in internet world.
layered navigation extension for magento 2
After all of such steps are completed as well as your eCommerce web page is fully tested, you should be capable of start your site for the public with full confidence because your small business finally gets linked to people online. However, this does not really imply your eCommerce site is fully safe. As a webmaster, you'll still should handle your site and its particular visitors properly to combat one of the most concerning issue - credit card fraud. This is something the web hosting cannot deal with so you should apply these ideas to completely leave any fraud through your eCommerce web site.
In this project, we'll start with an electronic digital photo of a desert mountain top. Next, we'll cover what steps are needed to include within an image of a jet so that it appears to be flying within the area. The screenshots below show the 'before' and 'after' with the digital photo editing process. (Click on images for a larger view.)
Symfony web design framework is really a database engine independent framework in PHP and may be effortlessly installed as well as configured too. It generates a readable code with the help of PHP Web Development. This framework allows integration with various vendor libraries features Propel plugins and in addition is definitely extendable. The developers can simply make best use of the different built-in internalization layer feature that enables data and also interface translation, content localization and decrease in the presentation code amount too by combining large shares of the codes through simple function calls. Those who will not have knowledge with the Symfony web development framework can take advantage of the layouts and templates that are built through the HTML designers.
layered navigation extension for magento 2 Tip 2:After the completing the operation of slicing using the image editor software just continue with the process by cutting the pixel perfect images. Most of the designers also prefer while using the Adobe photoshop or similar alternative on an ease including Microsoft paint. However, Adobe Photoshop is the option that makes the full task facile as well as simple to organize.
P.F. Changs can be a popular chain restaurant famous for it's Asian fusion cuisine. magento 2 layered navigation The Market Fair location in Princeton is usually crowded and more often than not needs a reservation. The menu is fairly large and offers something for everyone including both vegetarian items and gluten free items. In addition to the regular menu, P.F. Changs has added four additional items inspired by flavors from Southeast Asia. These items will only be designed for a restricted time.
magento 2 layered navigation extension
The new 2014 Soul sports updates which might be subtle enough to preserve the iconic design and spirit of the Soul while rendering it better still with more premium features, improved driving dynamics as well as a better value for that consumer - by having an MSRP still under $15,000 first whopper of an fun ride - with or without hamsters.
Perhaps the most moving and forceful portion of 'Dallas Buyers Club' 's what can be perhaps the most touching, heart-wrenching friendships ever captured on film, along with the true conscience on this story: the smoothness development engendered with the relationship between Jared Leto's character 'Rayon', a cross-dressing, gender-dissonant transsexual coping with AIDS, and McConaughey's character, who partner up inside black-market business of unapproved pharmaceuticals. Vall??e's depiction of multi-faceted global navigation between illegal pharmaceutical trafficking- trying to find never-ending loopholes to FDA regulations, and depicting how patient rights evolved via terminally ill groups fighting the United States government to revolutionize drug trials through compassionate usage of inchoate medicine/treatments- is the thing that jettisons this film into the very best released since January. Don't miss it. There is no sentimentality, or schmaltz. Only reality, brutally and honestly told.
This latest version of Magento Enterprise 1.12 can quickly and incredibly easily produce a storefront optimized for mobile devices hence the customers can shop regardless if these are moving around. This interface uses HTML5 technology and facilitates iPhone, Android and Mobile Opera browsers. It also includes specific out-of-the-box features such as:
layered navigation extension for magento 2 When I brought my dad to the Mission Viejo Audi where he bought the automobile I designed to show him some replacement alternatives for his Acura TL such as the A4 and A6. I never imagined however fall so head over heels in love with the sleek black roadster on the showroom floor. But apparently there is certainly such a thing being a ¾-life crisis (as I love to refer to it as) as he bought the automobile tomorrow and truly is his prized toy.

Monday, February 6, 2017

On 7:11 AM by Trọng Huỳnh Nguyễn   No comments
Magento 2 Create Payment Method proves that store admin has rights to generate as many payment methods as they need when your store is based on Magento 2 platform, an great era of ecommerce architecture. Depending on the customer’s requirement, you probably plug it in your list of the existing payment method. The additional payment methods surely bring the diversity of customer choice when they proceed to checkout on your site. On the other’s hands, multiple payment method is the great strategy to reach out the global marketplace.

In the tutorial, you will learn how to create own Payment Gateway integration in Magento 2 stores. After launching the new payment methods, you will find and configure it according the path Admin panel > Stores > Settings > Configuration > Sales > Payment Methods. There, admin possibly assigns a payment method to specific shipping method, this means they will work in pairs when enabling.

Step 1: Create payment method module



  1. Create file registration.php


<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
"Mageplaza_Payment",
__DIR__
);


  1. Declare module.xml file


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Mageplaza_Payment" setup_version="0.1.0">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
<module name="Magento_Checkout"/>
<module name="Magento_Directory" />
<module name="Magento_Config" />
</sequence>
</module>
</config>


This module have to run after the Magento_Sales, Magento_Payment, Magento_Checkout, Magento_Directory, and Magento_Config. So we add depends (sequence) them like above block of code.

Step 2: Declare payment method module


  1. Now we create file payment.xml file in etc folder etc/payment.xml


<?xml version="1.0" ?>
<payment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Payment:etc/payment.xsd">
<groups>
<group id="offline">
<label>Offline Payment Methods</label>
</group>
</groups>
<methods>
<method name="simple">
<allow_multiple_address>1</allow_multiple_address>
</method>
</methods>
</payment>


  1. Create config.xml file in etc folder.


<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<payment>
<simple>
<active>1</active>
<model>Mageplaza\Payment\Model\Payment\Simple</model>
<order_status>pending</order_status>
<title>Simple</title>
<allowspecific>0</allowspecific>
<group>Offline</group>
</simple>
</payment>
</default>
</config>


In this file, we declare Model of this payment method, we calle Simple model.
  1. Create Simple model file


Create file Model/Payment/Simple.php

<?php
namespace Mageplaza\Payment\Model\Payment;
class Simple extends \Magento\Payment\Model\Method\Cc
InfoInterface $payment
* @param float $amount
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @api
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/

public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)

if (!$this->canRefund())
throw new \Magento\Framework\Exception\LocalizedException(__("The refund action is not available."));

return $this;




This model includes basic functions such as - authorize(): Authorize the payment e.g: card - capture(): Capture money from a customer - refund(): Chargeback money to the customer.

Step 3: Display payment method in checkout page


In previous steps, we talked about declare module, config and model files. Now we need to display this Simple payment method in checkout page.
  1. Create layout file: view/frontend/layout/checkout_index_index.xml


<?xml version="1.0" ?>
<pagepage layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="billing-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="payment" xsi:type="array">
<item name="children" xsi:type="array">
<item name="renders" xsi:type="array">
<item name="children" xsi:type="array">
<item name="offline-payments" xsi:type="array">
<item name="component" xsi:type="string">Magento_OfflinePayments/js/view/payment/offline-payments</item>
<item name="methods" xsi:type="array">
<item name="simple" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</pagepage>


  1. Create js files to load KO template in checkout page


define(
[
"uiComponent",
"Magento_Checkout/js/model/payment/renderer-list"
],
function (Component,
rendererList)
"use strict";
rendererList.push(

type: "simple",
component: "Mageplaza_Payment/js/view/payment/method-renderer/simple-method"

);
return Component.extend();

);


In this file, it call another component: js/view/payment/method-renderer/simple-method

Now we need to create /view/frontend/web/js/view/payment/method-renderer/simple-method.js

define(
[
"Magento_Checkout/js/view/payment/default"
],
function (Component)
"use strict";
return Component.extend(
defaults:
template: "Mageplaza_Payment/payment/simple"
,
getMailingAddress: function ()
return window.checkoutConfig.payment.checkmo.mailingAddress;
,
);

);


  1. Finally, create KO template file /view/frontend/web/template/payment/simple.html


<div class="payment-method" data-bind="css: "_active": (getCode() == isChecked())">
<div class="payment-method-title field choice">
<input type="radio"
name="payment[method]"
class="radio"
data-bind="attr: "id": getCode(), value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
<label data-bind="attr: "for": getCode()" class="label"><span data-bind="text: getTitle()"></span></label>
</div>
<div class="payment-method-content">
<!-- ko foreach: getRegion("messages") -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<div class="payment-method-billing-address">
<!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion("before-place-order") -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<div class="actions-toolbar">
<div class="primary">
<button class="action primary checkout"
type="submit"
data-bind="
click: placeOrder,
attr: title: $t("Place Order"),
css: disabled: !isPlaceOrderActionAllowed(),
enable: (getCode() == isChecked())
"

disabled>
<span data-bind="i18n: "Place Order""></span>
</button>
</div>
</div>
</div>
</div>


You maybe also interested in Magento 2 Create Shipping Methods to custom the shipping methods as expected.

https://www.mageplaza.com/magento-2-create-payment-method/

Saturday, February 4, 2017

On 11:54 PM by Trọng Huỳnh Nguyễn   No comments
Using VirtualType in Magento 2 is really necessary when you are running an virtual store based on Magento 2 platform? On Magento 2 platform, the di.xml supports for two types of node which are a node type and a node virtualtype, meanwhile virtualtype is considered as a perfect method instead of the type. The virtual tape allows inserting different dependencies into the existing classes but not making any change to other classes. With this tutorial, Mageplaza team will lead you to learn how to create and use VirtualType in Magento 2.

Creating VirtualType in Magento 2



Creating virtualtype in Magneto 2 means creating a sub-class for an existing class. All are available to help you create the virtualtype in magento 2.

<?php
class OurVirtualTypeName extends \Mageplaza\HelloWorld\Model\Virtualtype




The following script code is inserted to the module’s di.xml to create a virtualtype in Magento 2.

#File: app/code/Mageplaza/HelloWorld/etc/di.xml
<config>
<!-- ... -->
<virtualType name="ourVirtualTypeName" type="Mageplaza\HelloWorld\Model\Virtualtype">
</virtualType>
</config>


Namely, the nodes are placed under the main node and include two attributes: name and type. While the name attribute is mostly the universally special name of that node, the type attribute is the real PHP for the virtual type.

As you see, it is simple to give some descriptions about the virtual type. If you erase the cache and repeat the request, the output is still the same.

$ php bin/magento hw:tutorial-virtual-type
First, we"ll report on the Mageplaza\HelloWorld\Model\Example object
The Property $property_of_example_object
is an object
created with the class:
Mageplaza\HelloWorld\Model\Virtualtype

Next, we"re going to report on the Example object"s one property (an Virtualtype class)
The Property $property_of_argument1_object
is an object
created with the class:
Mageplaza\HelloWorld\Model\Argument2

Finally, we"ll report on an Virtualtype object, instantiated separate from Example
The Property $property_of_argument1_object
is an object
created with the class:
Mageplaza\HelloWorld\Model\Argument2


Using Virtual Type in Magento 2


The functionality of a virtual type is replacing the position of PHP classes and you wouldn’t have to use a configuration as the below if you wanted to custom the argument injected into the Example class’s constructor.

#File: app/code/Mageplaza/HelloWorld/etc/di.xml 
<config>
<!-- ... -->
<virtualType name="ourVirtualTypeName" type="Mageplaza\HelloWorld\Model\Virtualtype">
</virtualType>

<type name="Mageplaza\HelloWorld\Model\Example">
<arguments>
<argument name="the_object" xsi:type="object">Some\Other\Class</argument>
</arguments>
</type>

</config>


However, applying that command will lead you to the following error even though you have already cleaned your cache.

$ php bin/magento hw:tutorial-virtual-type

[ReflectionException]
Class Some\Other\Class does not exist


Let’s move to a smart way with the virtual type. This means Some\Other\Class is recovered by ourVirtualTypeName. You can ensure that no error is caused unless you call the command with the above in place.

#File: app/code/Mageplaza/HelloWorld/etc/di.xml 
<config>
<!-- ... -->
<virtualType name="ourVirtualTypeName" type="Mageplaza\HelloWorld\Model\Virtualtype">
</virtualType>

<type name="Mageplaza\HelloWorld\Model\Example">
<arguments>
<argument name="the_object" xsi:type="object">ourVirtualTypeName</argument>
</arguments>
</type>

</config>


Thanks for your reading and I hope that your business become more perfect with our guides of creating and using virtual types.

https://www.mageplaza.com/using-virtual-type-magento-2.html
On 12:44 PM by Trọng Huỳnh Nguyễn   No comments
Creating composer.json in Magento 2 brings you more and more convenience to manage components better that used in your project. This topic is the well-documented instruction to assist the store owners to be familiar with the composer.json file.

Overview of Magento 2 Composer



Composer is a dependency management for PHP and in Magento 2, the composer plays the role in gathering components and product editions. When using the Magento 2 composer, there is no requirement of storing all code of each component, and you only need to create composer.json file and declare the needed components in that file instead that. Immediately, the composer will auto-define and take the corresponding data of those components to run for your project.

Here are some situations of the Magento 2 components including composer.json file:
  • When a component contains composer.json file, and needs to install via magneto 2 composer as well (like from Packagist, the Magento Marketplace, or another source), the Component Manager can update, uninstall, enable, or disable the component.

  • When a component still includes composer.json file but doesn’t need to install via Magento 2 composer such as the customization of written codes by a developer, the Component Manager can still enable or disable the component.


So, it is easier for you to run the project smoothly when your component’s root directory is added the composer.json file.

Explanation of composer.json files


Both Magento 2 components and product editions can work with composer.json files, specifically:

Root


  • Location: composer.json

  • Name: magento/magento2ce

  • Type: project


This is the main composer.json file. It can be used as a template for every root composer.json file to call dependencies on third-party components.

CE project


  • Location: composer.json

  • Name: magento/project-community-edition

  • Type: project


This file is used for the Magento Community Edition project. It allows calling the dependencies on the Magento product and the class autoloader. In addition, you can use it to deploy Magento using Composer via Magento system integrators.

CE product


  • Location: composer.json

  • Name: magento/product-community-edition

  • Type: metapackage


This file is used for the Magento Community Edition product. It allows calling the dependencies on the Magento components (modules, themes, and so on) and third-party components. In addition, you can use it to deploy Magento using Composer via Magento system integrators.

Magento Framework


  • Location: lib/internal/Magento/Framework/composer.json

  • Name: magento/framework

  • Type: magento2-library


You only used this file for Magento framework.

Module


  • Locations:

app/code/<vendor-name>/<module-name>/composer.json

vendor/<vendor-name>/<module-name>/composer.json
  • Name: <vendor-name>/<package-name>

  • Type: magento2-module


The composer.json file will aid a module extension to call external dependencies when it needs to be functioned.

Theme


  • Locations:

app/design/frontend/<vendor-name>/<theme-name>/composer.json

app/design/adminhtml/<vendor-name>/<theme-name>/composer.json
  • Name: <vendor-name>/<package-name>

  • Type: magento2-theme


For a theme component, this file consists of parent theme dependencies which are used for the inheritance of the extension.

Language Package


  • Location: app/i18n/<vendor-name>/<language-code>/composer.json

  • Name: <vendor-name>/<package-name>

  • Type: magento2-language


The composer.json file for language packages have to include the correct ISO code that is suitable for the language code.

Kinds of the component in Magento 2 Composer


There are many kinds of Magento 2 component like a module, theme, or language package. However in the case of not being assigning to an exact category, that will be called generally as magento-2-component.

To determine the type of Magento 2 component, the system possibly combines the directories and files to the correct locations, that is based on the Magento 2 directory structure.

Naming conventions of the component in Magento 2 Composer


When creating Magneto 2 composer, you are compulsory to use the format of the namespace: <vendor-name>/<package-name>. Thus, in this part, we will learn the conventions of the vendor-name and package-name.

vendor-name


The vendor-name must be lowercase as the following format for Magento 2 extensions: magento2/*

In case that you want to submit the extension to Magento Marketplace, you have to use the name you have registered the account there. That name is injected into the composer.json file as the vendor-name part of the extension name. I have a specific illustrator for your approach:

 
"name": "mageplaza/magento-2-seo-extension",
"description": "Magento 2 SEO extension",
"require": ~7.0.0",
"mageplaza/core-m2": "dev-master"
,
"type": "magento2-module",
"version": "1.1.1",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"authors": [

"name": "Mageplaza",
"email": "hi@mageplaza.com",
"homepage": "https://www.mageplaza.com",
"role": "Leader"

],
"autoload":
"files": [
"registration.php"
],
"psr-4":
"Mageplaza\\Seo\\": ""





package-name


The package-name also contains the lowercase with multiple words, so Magento 2 Composer asks for separating them by dash as the following convention:

magento2/<type-prefix>-<suffix>[-<suffix>]...

In particular, type-prefix is a type of Magento 2 component and suffix is a thing to realize which component it is within that type.

That is all things you need to pay attention when creating a composer.json file in Magento 2. Please follow carefully and make yourself more comfortable with the composer.json file when running your projects.

https://www.mageplaza.com/magento-2-create-composer-json.html
On 5:29 AM by Trọng Huỳnh Nguyễn   No comments
Magento 2 URL Rewrite programmatically is one of the awesome solutions for online retailers as you who want to really create a huge number of the traffics of your website. The purpose of rewriting the url is allowing you generating 301 redirects into Magento 2 by the programmatical way.

What is URL Redirect?



URL redirect is a popular term in SEO and it is used for navigating the visitors to any link store owners expect. There are two main type of redirect: 301 redirect and 302 redirect. Therefore, if you are wondering how to continue working with the existing visitor at the current site while you are planning to build a new site with more efficiencies, the best answer is creating the search redirection through the redirect 301.

Overview of Magento 2 URL Rewrite programmatically


  • Step 1 : Generate constructor file

  • Step 2 : Insert custom URL rewrite in execute method

Step 1 : Generate constructor file



/**
* @var \Magento\UrlRewrite\Model\ResourceModel\UrlRewriteFactory
*/
protected $_urlRewriteFactory;

/**
* @param Context $context
* @param \Magento\UrlRewrite\Model\ResourceModel\UrlRewriteFactory $urlRewriteFactory
*/
public function __construct(
Context $context,
\Magento\UrlRewrite\Model\ResourceModel\UrlRewriteFactory $urlRewriteFactory
)
$this->_eavAttributeFactory = $eavAttributeFactory;
parent::__construct(
$context
);



Step 2 : Insert custom URL rewrite in execute method


Only if your original website is www.example.com/customModule/customController/customAction, you want to rewrite the URL by www.example.com/xyz, instead. Then you can run the following method:

$urlRewriteModel = $this->_urlRewriteFactory->create()
/* set current store id */
$urlRewriteModel->setStoreId(1);
/* this url is not created by system so set as 0 */
$urlRewriteModel->setIsSystem(0);
/* unique identifier - set random unique value to id path */
$urlRewriteModel->setIdPath(rand(1, 100000));
/* set actual url path to target path field */
$urlRewriteModel->setTargetPath("www.example.com/customModule/customController/customAction");
/* set requested path which you want to create */
$urlRewriteModel->setRequestPath("www.example.com/xyz");
/* set current store id */
$urlRewriteModel->save();


 

https://www.mageplaza.com/magento-2-url-rewrite-programmatically.html

Friday, February 3, 2017

On 10:15 PM by Trọng Huỳnh Nguyễn   No comments
Magento 2 registry is the next topic Mageplaza wants to introduce in the series of this module development. Magento 1, as well as Magento 2, authorize you to register global variable that supports the static registry method.

To implement that, maybe you used to work with Mage::register() and Mage::registry() in Magento 1, but now in Magento 2 platform, there is a difference in running the registry. You will be required to apply \Magento\Framework\Registry, that accepts the settings and the registry of the restored data. However, first of all, you need to learn how to create or use the own custom registry and also show you how to retrieve global Magento 2 registry objects like current product, category, cms page, cms block, etc.

And that is lucky because all of them will be referred here. The topic today will help you be familiar with Magento 2 registry objects.

Please follow the following code snippet:

How to get and set custom attribute in registry / register




/**
* @var \Magento\Framework\Registry
*/

protected $_registry;

/**
* ...
* ...
* @param \Magento\Framework\Registry $registry,
*/
public function __construct(
...,
...,
\Magento\Framework\Registry $registry,
...
)
$this->_registry = $registry;
...
...


/**
* Setting custom variable in registry to be used
*
*/

public function setCustomVariable()

$this->registry->register("custom_var", "Added Value");


/**
* Retrieving custom variable from registry
* @return string
*/
public function getCustomVariable()

return $this->registry->registry("custom_var");




How to get registry of current Product, Category, CMS Page




/**
* @var \Magento\Framework\Registry
*/

protected $_registry;

/**
* ...
* ...
* @param \Magento\Framework\Registry $registry,
*/
public function __construct(
...,
...,
\Magento\Framework\Registry $registry,
...
)
$this->_registry = $registry;
...
...


/**
* Return catalog product object
*
* @return \Magento\Catalog\Model\Product
*/

public function getProduct()

return $this->_registry->registry("current_product");


/**
* Return catalog current category object
*
* @return \Magento\Catalog\Model\Category
*/

public function getCurrentCategory()

return $this->_registry->registry("current_category");



/**
* Return catalog current cms page object
*
*/
public function getCurrentCategory()

return $this->_registry->registry("current_cms_page");




With this instruction, you can achieve the best results of Magento 2 registry. Thanks for your watching and hope you are happy with it.

Happy coding!

https://www.mageplaza.com/magento-2-registry-register.html
On 5:47 AM by Trọng Huỳnh Nguyễn   No comments

In Magento 2, apart from creating product and customer programmatically, you can also create invoice programmatically with ease when following the given guides in the Magento 2 create invoice programmatically topic.

Why do Magento 2 stores need to set up the program for creating the invoice? As you know, each time an invoice is created, that means an order is placed successfully and at the same time, Magento will notify you have earned the amount of money from the customer. However, by such normal way, you will get mass notifications from Magento 2 system as well as create the equivalent number of the invoices if your customer implements partial payment within the order. Therefore, this topic is the great solution to form the invoice while there is no dependency on the total paid of order.

Mageplaza brings you two simple steps for that and here you are!

Overview of creating invoice programmatically in Magento 2



  • Step 1: Declare event sales_order_invoice_pay

  • Step 2: Setup the observer class

Step 1: Declare event sales_order_invoice_pay


Start the settings with events.xml file in your custom module: /app/code/Mageplaza/HelloWorld/etc/events.xml

<?xml version="1.0"?>
<event name="sales_order_invoice_pay">
<observer name="webpos_sales_order_invoice_pay" instance="Mageplaza\HelloWorld\Observer\SalesOrderInvoicePay" />
</event>
</config>


Step 2: Setup the observer class


/app/code/Mageplaza/HelloWorld/Observer/SalesOrderInvoicePay.php

<?php
namespace Mageplaza\HelloWorld\Observer\Sales;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
class SalesOrderInvoicePay implements ObserverInterface

/**
* @param EventObserver $observer
* @return $this
*/
public function execute(EventObserver $observer)

$invoice = $observer->getEvent()->getInvoice();
$order = $invoice->getOrder();

/* reset total_paid & base_total_paid of order */
$order->setTotalPaid($order->getTotalPaid() - $invoice->getGrandTotal());
$order->setBaseTotalPaid($order->getBaseTotalPaid() - $invoice->getBaseGrandTotal());





https://www.mageplaza.com/magento-2-create-invoice-programmatically.html

Thursday, February 2, 2017

On 7:18 AM by Trọng Huỳnh Nguyễn   No comments
Joining 2 tables in Magento 2 is the usual operation you need to implement when working with Magento 2 project. In order to make you do that with ease, the developer team from Mageplaza recommend the topic “Join Data Between 2 Tables in Magento 2”. In this topic, I will guide you how to get all orders that created with a specify payment method such as “Check Money Order”.

Overview of joining data between 2 tables in Magento 2



  • Step 1: Set a Collection class that extends

  • Step 2: Set your own function to get data

  • Step 3: Get the collection and call to filterOrder function above

  • Step 4: Save

Step 1: Set a Collection class


In the first step, you will form the Collection class that extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection


In the Collection class, there are two parameters you need to understand:
  • The first is your module name

  • The second is Sale order resource model from Magento sales module


 protected function _construct()

$this->_init("Mageplaza\HelloWorld\Model\YourModel", "Magento\Sales\Model\ResourceModel\Order");



Step 2: Set your own function to get data


Use the code script to set the own function, then get data as need.

protected function filterOrder($payment_method)


$this-&gt;sales_order_table = "main_table";
$this-&gt;sales_order_payment_table = $this-&gt;getTable("sales_order_payment");
$this-&gt;getSelect()
-&gt;join(array("payment" =&gt; $this-&gt;sales_order_payment_table), $this-&gt;sales_order_table . ".entity_id= payment.parent_id",
array("payment_method" =&gt; "payment.method",

"order_id" =&gt; $this-&gt;sales_order_table.".entity_id"
)
);

$this-&gt;getSelect()-&gt;where("payment_method=".$payment_method);



Step 3: Get the collection and call to filterOrder function above


In your model, you just need to get the collection and call to filterOrder function above.

$collection = $this-&gt;YourCollectionFactory-&gt;create();

$collection-&gt;filterOrder("checkmo");

foreach ($collection as $item)
{
//do what you want with the data here.


Step 4: Save


Finally, Save all to complete with the joining data between 2 tables in Magento 2.

That’s all for you. Thanks for your reading!

https://www.mageplaza.com/how-join-2-tables-magento-2.html