How to create multiple store in Magento 2? | Step-by-Step Guide: Creating Multiple Stores in Magento 2 | magento 2 demo



If you require then I can give you magento 2 demo.

To create multiple stores in Magento 2, you can follow these steps:

  1. Log in to your Magento 2 admin panel.

  2. Navigate to the Stores menu and select All Stores.

  3. Click on the Create Store button.

  4. In the Create Store dialog box, enter the Store Name and Store Code. The Store Code should be a unique identifier for the store.

  5. Select the Website that the store will be associated with. If you haven’t created a website yet, you can create one by going to Stores > All Stores > Create Website.

  6. Choose the Root Category for the store. This will determine the catalog and product listings shown in the store.

  7. Save the store configuration.

  8. To create a store view, go to Stores > All Stores and click on the Create Store View button.

  9. Provide a Store View Name and Store View Code. The Store View Code should be unique.

  10. Select the Store that the store view will be associated with.

  11. Choose the Locale and the Timezone for the store view.

  12. Save the store view configuration. Than you can see magento 2 demo.

Repeat these steps as needed to create multiple stores and store views in Magento 2. Each store can have its own unique configuration, catalog, and storefront design. Make sure to configure the necessary settings for each store, such as currencies, languages, and pricing, according to your business requirements.

Note: Creating multiple stores in Magento 2 can be a complex process, especially if you have specific customization needs or require advanced configurations. It is recommended to refer to the official Magento 2 documentation or consult with a Magento developer for more detailed guidance tailored to your specific requirements.

you can try these steps on your magento 2 demo store.

Puneet Kumar Magento Developer

Magento 2 what does checkout session replaceQuote?

 In Magento 2, the checkout/session object represents the customer’s session during the checkout process. It stores and manages various data related to the checkout, including the quote object.

The quote object (MagentoQuoteModelQuote) represents the current state of the customer’s shopping cart. It contains information about the products added to the cart, their quantities, prices, applied discounts, shipping and payment methods, and other relevant details.

The replaceQuote($quote) method of the checkout/session object is used to replace the current quote object with a new quote object. This can be useful in scenarios where you want to update the cart with a modified quote, such as when applying custom pricing rules, adding or removing items programmatically, or handling specific business logic.

By calling replaceQuote($quote), you can set a new quote object, and the existing quote in the session will be replaced with the new one. This ensures that any subsequent operations or calculations related to the checkout will be based on the updated quote object.

Here’s an example of how you can use replaceQuote($quote) in your custom code:

php
<?php use MagentoCheckoutModelSession as CheckoutSession; use MagentoQuoteModelQuoteFactory; class CustomClass { protected $checkoutSession; protected $quoteFactory; public function __construct( CheckoutSession $checkoutSession, QuoteFactory $quoteFactory ) { $this->checkoutSession = $checkoutSession; $this->quoteFactory = $quoteFactory; } public function updateQuote() { // Create a new quote or load an existing quote $newQuote = $this->quoteFactory->create(); $newQuote->load($quoteId); // Replace the current quote in the session with the new quote $this->checkoutSession->replaceQuote($newQuote); // Perform other operations on the updated quote // ... } }

Remember to replace $quoteId with the actual ID of the quote you want to load.

Puneet Kumar Magento Developer

Magento 2 : How to get Shipping Methods for Specific Customer Group

 To get the available shipping methods for a specific customer group in Magento 2, you can follow these steps:

  1. Inject the necessary dependencies in your class constructor or method. You will need the following dependencies:
php
use MagentoCustomerApiGroupRepositoryInterface; use MagentoQuoteApiShippingMethodManagementInterface; use MagentoQuoteModelQuoteAddressRateCollectorInterface;
  1. Create class properties for the injected dependencies:
php
protected $groupRepository; protected $shippingMethodManagement; protected $rateCollector;
  1. Initialize the dependencies in the constructor:
php
public function __construct( GroupRepositoryInterface $groupRepository, ShippingMethodManagementInterface $shippingMethodManagement, RateCollectorInterface $rateCollector ) { $this->groupRepository = $groupRepository; $this->shippingMethodManagement = $shippingMethodManagement; $this->rateCollector = $rateCollector; }
  1. Use the following code to retrieve the available shipping methods for a specific customer group:
php
$customerGroupId = 1; // Replace with the desired customer group ID try { $group = $this->groupRepository->getById($customerGroupId); $rateRequest = $this->rateCollector->createRateRequest(); $rateRequest->setAllItems([]); $rateRequest->setDestCountryId('US'); // Replace with the desired country ID $rateRequest->setDestPostcode('12345'); // Replace with the desired postal code $rateRequest->setCustomerGroupId($group->getId()); $shippingMethods = $this->shippingMethodManagement->getList($rateRequest); foreach ($shippingMethods as $shippingMethod) { echo $shippingMethod->getMethodCode(); // Output the shipping method code } } catch (Exception $e) { echo $e->getMessage(); // Handle any exceptions that occur }

Make sure to replace the $customerGroupId, 'US', and '12345' with the appropriate values for your specific use case.

By executing this code, you will retrieve the available shipping methods for the specified customer group in Magento 2.

Puneet Kumar Magento Developer

Adding an Auto-increment Column in db_schema.xml: A Professional Guide

 

Introduction:

In Magento 2, the db_schema.xml file plays a crucial role in defining the database structure for your module. One common requirement when designing database tables is the inclusion of an auto-increment column. This column type automatically generates a unique value for each new record inserted into the table. In this article, we will explore how to add an auto-increment column in db_schema.xml with a step-by-step guide.

Understanding Auto-increment Columns:
An auto-increment column is a special type of column in a database table that assigns a unique numeric value to each new record. This value increments automatically as new records are inserted, ensuring uniqueness and simplifying data retrieval and management.

Adding an Auto-increment Column in db_schema.xml:
Follow these steps to add an auto-increment column using the db_schema.xml file in Magento 2:

Step 1: Locate or create the db_schema.xml file:
In your Magento module, navigate to the etc/db_schema.xml file. If it doesn’t exist, create one in the appropriate directory.

Step 2: Define the table structure:
Inside the <schema> tag, define the structure of your table using the <table> tag. Specify the table name and any additional attributes required.

Step 3: Add the column declaration:
Within the <table> tag, add a <column> tag for the auto-increment column. Define the column name, type, and any other attributes.

xml
<column xsi:type="int" name="entity_id" nullable="false" unsigned="true" identity="true" comment="Entity ID"/>

Here, the identity="true" attribute signifies that the column should be an auto-increment column.

Step 4: Complete the db_schema.xml file:
Save the db_schema.xml file with the complete table and column definitions.

Step 5: Run the database upgrade:
To apply the changes, run the following command from the Magento root directory:


bin/magento setup:upgrade

This command triggers the installation and upgrade process, which executes the changes defined in the db_schema.xml file.

Conclusion:
Adding an auto-increment column to a database table is a common requirement when working with Magento 2. By following the steps outlined in this article, you can easily include an auto-increment column in the db_schema.xml file of your module. Utilizing the db_schema.xml file and its declarative approach ensures consistent and efficient management of your module’s database structure. Incorporating auto-increment columns enhances data integrity and simplifies the retrieval and manipulation of records within your Magento 2 application.

Puneet Kumar Magento Developer

Magento 2 giving error in plugin beforegetName


I am getting error while using plugin before have any one idea why it is happening? 


Fatal error: Uncaught ArgumentCountError: Too few arguments to function PuneetTestModelPluginName::beforegetName(), 1 passed in /var/www/html/m2/vendor/magento/framework/Interception/Interceptor.php on line 121 and exactly 2 expected in /var/www/html/m2/app/code/Puneet/Test/Model/Plugin/Name.php:15 Stack trace: #0 /var/www/html/m2/vendor/magento/framework/Interception/Interceptor.php(121): PuneetTestModelPluginName->beforegetName(Object(MagentoCatalogModelProductInterceptor)) #1 /var/www/html/m2/vendor/magento/framework/Interception/Interceptor.php(153): MagentoCatalogModelProductInterceptor->MagentoFrameworkInterception{closure}() #2 /var/www/html/m2/generated/code/Magento/Catalog/Model/Product/Interceptor.php(26): MagentoCatalogModelProductInterceptor->___callPlugins('getName', Array, Array) #3 /var/www/html/m2/vendor/magento/module-catalog/Helper/Product/View.php(119): MagentoCatalogModelProductInterceptor->getName() #4 /var/www/html/m2/vendor/magento/module-catalog/Helper/Product/View.php(28 in /var/www/html/m2/app/code/Puneet/Test/Model/Plugin/Name.php on line 15


My class and before method is.

<?php
/*
* Puneet_Test
* Name change
*/
namespace PuneetTestModelPlugin;
class Name {
// public function aftergetName(MagentoCatalogModelProduct $subject, $result){
// return "SS: " . $result;
// }
public function beforegetName(MagentoCatalogModelProduct $subject, $name){
return   $result . "SS";
}
}


Puneet Kumar Magento Developer

5. What step during the layout loading is the node processed?

5. What step during the layout loading is the node processed?

A. After the generation of layout blocks.

B. Vefore the generation of layout update XML, but after the generation of layout blocks.

C. Before the generation of layout blocks, but after the generation of layout XML.

D. After the generation of layout blocks, but before rendering the page.

Puneet Kumar Magento Developer

Magento 2 | How can we use jQuery without “require([‘jquery’],function($){” this code.

Magento 2 | How can we use jQuery without “require([‘jquery’],function($){” this code.

We have face problem we implement some slider and also we have wrighten many script in phtml.
If we add the jquery library then magento is giving the error in core files and all script are stopped accept my cutome script once i remove the the jquery library
then core script are working but my custom script are not working its giving jquery not define you can see error below screenshots.

Puneet Kumar Magento Developer

Magento 2 | How to set production mode manually

In magento 2 probubly have permission issues with server. if you are not able to set production mode by CLI command you can follow below changes.

open your magento 2 root dirctory, Open file “/app/etc/evn.php” and search “‘MAGE_MODE’ =>“. you can change your mgento mode here manually.

CLI command for production mode

magento deploy:mode:set production

CLI command for developer mode

magento deploy:mode:set developer

Puneet Kumar Magento Developer

Magento 2 | how to see current magento mode

Display the current mode

User below commnad for make sure which mode currently are nunning.

Command
php bin/magento deploy:mode:show

Puneet Kumar Magento Developer

Add custom field for all products for order line

How to add custom fields for Order Line Items in magento

 

 

Work Flow to add custom Field to Order line Item
Use this url to add to cart: Ex: http://magento.com/checkout/cart/add/?product=196&qty=2&training_location=California
1. checkout_cart_item_default.phtml:::
Add the following below product name
<dl class=”item-options Kiran” id=”checkout_cart_item_default”>
<dt>Training Location</dt>
<dd><?php echo $_item->getTrainingLocation(); ?></dd>
</dl>
2. Table: sales_flat_quote_item
Add field: training_location
3. Product Detailed Page: Add training_location text field as input
4. Code -> Core -> Mage -> Sales -> Model -> Quote.php
Find: public function addItem(Mage_Sales_Model_Quote_Item $item)
Add: $item->setTrainingLocation($_REQUEST[‘training_location’]);
Befoe: $item->setQuote($this);
—————
5. Table: sales_flat_order_item
Add field: training_location
6. XML: code_core_mage_sales_etc_config.xml
ADD: <training_location><to_order_item>*</to_order_item></training_location>
Between: <sales_convert_quote_item> and </sales_convert_quote_item>
Also Add:
<training_location><to_quote_item>*</to_quote_item><to_invoice_item>*</to_invoice_item><to_shipment_item>*</to_shipment_item><to_cm_item>*</to_
cm_item></training_location>
Between: <sales_convert_order_item> and </sales_convert_order_item>
—— Show The Info In Various Locations ——
To show in admin orders area
7. app_design_adminHTML_default_default_template_sales_order_view_items_renderer_default.phtml
Add:
<?php if($_item->getTrainingLocation()): ?>
<?php echo “<strong>Training Location:</strong> “.$_item->getTrainingLocation(); ?>
<?php endif; ?>
Below: <?php echo $this->getColumnHtml($_item, ‘name’) ?>
8. To Show in Checkout/Order review Page
frontend_template_checkout_onepage_review_item.phtml
Add: <?php if ($_item->getTrainingLocation()):?>
<dl class=”item-options Kiran” id=”checkout_cart_item_default”>
<dt>Training Location</dt>
<dd><?php echo $_item->getTrainingLocation(); ?></dd>
</dl>
<?php endif; ?>
Below: <h3 class=”product-name”><?php echo $this->htmlEscape($this->getProductName()) ?></h3>
9. To show in Myorders view page
frontend_template_sales_order_items_renderer_default.phtml
Add: <?php if ($_item->getTrainingLocation()):?>
<dl class=”item-options Kiran” id=”checkout_cart_item_default”>
<dt>Training Location</dt>
<dd><?php echo $_item->getTrainingLocation(); ?></dd>
</dl>
<?php endif; ?>
Below: <h3 class=”product-name”><?php echo $this->htmlEscape($_item->getName()) ?></h3>
10.
######################################
Usefull Links:
http://www.magentocommerce.com/boards/viewthread/19344/
http://magentocoder.jigneshpatel.co.in/add-to-cart-with-custom-attributes-values/
Use like below in product view page
<input type=”text”title=”Qty” value=”My Test Location” maxlength=”12″ id=”training_location” name=”training_location”>

Puneet Kumar Magento Developer