<h5 style="color:red;">系统学习magento二次开发,推荐小册:<a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank">《Magento中文全栈二次开发 》</a></h5> <div class="image-container"> <p> <a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank"> <img src="https://www.maxiaoke.com/uploads/images/20230218/bb9c82995c24d1105676e02f373755f5.jpg" alt="Magento中文全栈二次开发"> </a> </p> </div> <div class="text-container" style="font-size:14px; color:#888"> <p>本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。</p> </div> <hr><p>以编程方式在Magento 2发票电子邮件中的发票总计中添加自定义字段的步骤:</p><p>步骤1:第一步,您需要 在以下文件路径中创建sales_order_invoice.xml文件</p><p>app/code/Vendor/Extension/view/frontend/layout/sales_order_invoice.xml</p><p>然后添加代码,如下所示</p><pre class="brush:bash;toolbar:false"><?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="invoice_totals"> <block class="Vendor\Extension\Block\CustomFieldinInvoice" name="invoice"/> <action method="setLabel"> <argument name="label" xsi:type="string">Custom Field Name</argument> </action> </referenceBlock> </body> </page></pre><p>步骤2:现在在 以下路径创建自定义字段发票.php文件</p><p>app/code/Vendor/Extension/Block/CustomFieldinInvoice.php</p><p>现在添加以下代码</p><pre class="brush:bash;toolbar:false"><?php namespace Vendor\Extension\Block; use Magento\Framework\View\Element\Template; class CustomFieldinInvoice extends Template { public function __construct( Template\Context $context, array $data = [] ) { parent::__construct($context, $data); $this->setInitialFields(); } public function setInitialFields() { if (!$this->getLabel()) { $this->setLabel(__('Custom Field Name')); } } public function initTotals() { $this->getParentBlock()->addTotal( new \Magento\Framework\DataObject( [ 'code' => 'customfield', 'strong' => $this->getStrong(), 'value' => $this->getOrder()->getCustom(), // extension attribute field 'base_value' => $this->getOrder()->getCustom(), 'label' => __($this->getLabel()), ] ), $this->getAfter() ); return $this; } public function getOrder() { return $this->getParentBlock()->getOrder(); } public function getSource() { return $this->getParentBlock()->getSource(); } }</pre><p>结论:</p><p>因此,通过这种方式,您可以轻松地以编程方式在Magento 2发票电子邮件中的发票总计中添加自定义字段。</p><p><br/></p>
文章列表
<h5 style="color:red;">系统学习magento二次开发,推荐小册:<a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank">《Magento中文全栈二次开发 》</a></h5> <div class="image-container"> <p> <a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank"> <img src="https://www.maxiaoke.com/uploads/images/20230218/bb9c82995c24d1105676e02f373755f5.jpg" alt="Magento中文全栈二次开发"> </a> </p> </div> <div class="text-container" style="font-size:14px; color:#888"> <p>本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。</p> </div> <hr><p>在Magento 2中将默认排序顺序从升序更改为降序的步骤:</p><p>第 1 步:创建app\design\frontend\Themes\Yourtheme\Magento_Catalog\layout\catalog_category_view.xml 或者您可以在 以下位置覆盖自定义扩展中的catalog_category_view.xml文件</p><p>app\code\Vendor\Extension\view\frontend\layout\catalog_category_view.xml</p><p>现在添加代码,如下所示</p><pre class="brush:bash;toolbar:false"><?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="content"> <referenceBlock class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list"> <action method="setDefaultDirection"> <argument name="dir" xsi:type="string">desc</argument> </action> </referenceBlock> </referenceContainer> </body> </page></pre><p>结论:</p><p>因此,借助上述方法,您可以轻松地在Magento 2中将类别页面中产品列表的顺序从升序更改为降序。</p><p><br/></p>
<h5 style="color:red;">系统学习magento二次开发,推荐小册:<a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank">《Magento中文全栈二次开发 》</a></h5> <div class="image-container"> <p> <a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank"> <img src="https://www.maxiaoke.com/uploads/images/20230218/bb9c82995c24d1105676e02f373755f5.jpg" alt="Magento中文全栈二次开发"> </a> </p> </div> <div class="text-container" style="font-size:14px; color:#888"> <p>本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。</p> </div> <hr><p>在Magento 2中显示特定类别的付款方式的步骤:</p><p>步骤1:首先,在 以下文件路径的etc文件夹中创建一个事件.xml文件</p><p>app\code\Vendor\Extension\etc</p><p>现在添加代码,如下所述。</p><pre class="brush:bash;toolbar:false"><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="payment_method_is_active"> <observer name="payment_method_is_active" instance="Vendor\Extension\Observer\ActivePaymentMethod" /> </event> </config></pre><p>步骤2:在第二步中,在 模型文件夹中创建ActivePaymentMethod.php文件,路径如下</p><p>app\code\Vendor\Extension\Observer</p><p>然后添加代码,如下所示。</p><pre class="brush:bash;toolbar:false"><?php namespace Vendor\Extension\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Catalog\Api\ProductRepositoryInterface; class ActivePaymentMethod implements ObserverInterface { protected $_cart; protected $_checkoutSession; protected $productRepository; public function __construct( \Magento\Checkout\Model\Cart $cart, \Magento\Checkout\Model\Session $checkoutSession, ProductRepositoryInterface $productRepository ) { $this->_cart = $cart; $this->_checkoutSession = $checkoutSession; $this->productRepository = $productRepository; } /** * Execute observer * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { $quote = $this->getCheckoutSession()->getQuote(); $categoryID = "Add your category ID"; $items = $quote->getAllItems(); $flag = false; foreach($items as $item) { $product = $this->getProduct($item->getProductId()); $categoryIds = $product->getCategoryIds(); if(in_array($categoryID, $categoryIds)) { $flag = true; break; } } if($flag == false && $observer->getEvent()->getMethodInstance()->getCode()=="Enter Your Payment Method Code") { $checkResult = $observer->getEvent()->getResult(); $checkResult->setData('is_available', false); } } public function getProduct($productId) { return $product = $this->productRepository->getById($productId); } public function getCart() { return $this->_cart; } public function getCheckoutSession() { return $this->_checkoutSession; } }</pre><p>结论:</p><p>这样,您可以在Magento 2中显示特定类别的付款方式。</p><p><br/></p>
<h5 style="color:red;">系统学习magento二次开发,推荐小册:<a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank">《Magento中文全栈二次开发 》</a></h5> <div class="image-container"> <p> <a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank"> <img src="https://www.maxiaoke.com/uploads/images/20230218/bb9c82995c24d1105676e02f373755f5.jpg" alt="Magento中文全栈二次开发"> </a> </p> </div> <div class="text-container" style="font-size:14px; color:#888"> <p>本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。</p> </div> <hr><p>在Magento 2中将组产品单独添加到购物车的步骤:</p><p>第1步: 您需要覆盖主题中的grouped.phtml文件。为此,请转到以下文件路径。</p><p>app\design\frontend\Theme\Yourtheme\Magento_GroupedProduct\templates\product\view\type\grouped.phtml</p><p>并按如下方式添加代码。</p><pre class="brush:bash;toolbar:false"><?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ // @codingStandardsIgnoreFile /** * Grouped product data template * * @var $block \Magento\Catalog\Block\Product\View\BaseImage * @var $block \Magento\GroupedProduct\Block\Product\View\Type\Grouped */ ?> <?php $block->setPreconfiguredValue(); ?> <?php $_product = $block->getProduct(); ?> <?php $_associatedProducts = $block->getAssociatedProducts(); ?> <?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?> <?php $grouped = $_product->load($_product->getId()); ?> <?php $associatedProducts = $grouped->getTypeInstance()->getAssociatedProducts($grouped); ?> </form> <div class="table-wrapper grouped"> <table class="table data grouped" id="super-product-table"> <caption class="table-caption"><?= /* @escapeNotVerified */ __('Grouped product items') ?></caption> <thead> <tr> <th class="col item" scope="col"><?= /* @escapeNotVerified */ __('Product Name') ?></th> <?php if ($_product->isSaleable()): ?> <th class="col qty" scope="col"><?= /* @escapeNotVerified */ __('Qty') ?></th> <?php endif; ?> </tr> </thead> <?php if ($_hasAssociatedProducts): ?> <?php foreach ($associatedProducts as $_item): ?> <tbody> <tr> <td data-th="<?= $block->escapeHtml(__('Product Name')) ?>" class="col item"> <strong class="product-item-name"><?= $block->escapeHtml($_item->getName()) ?></strong> <?php if ($block->getCanShowProductPrice($_product)): ?> <?php if ($block->getCanShowProductPrice($_item)): ?> <?= /* @escapeNotVerified */ $block->getProductPrice($_item) ?> <?php endif; ?> <?php endif; ?> </td> <?php if ($_product->isSaleable()): ?> <td data-th="<?= $block->escapeHtml(__('Qty')) ?>" class="col qty"> <?php if ($_item->isSaleable()) : ?> <div class="control qty"> <form data-role="tocart-form" action="<?php echo $this->getAddToCartUrl($_item); ?>" method="post"> <input type="hidden" name="product" value="<?php echo $_item->getId(); ?>"> <input type="hidden" name="related_product" id="related-products-field" value=""> <input type="number" name="qty" value="<?= /* @escapeNotVerified */ $_item->getQty() * 1 ?>" title="<?= /* @escapeNotVerified */ __('Qty') ?>" class="input-text qty required" /> <?php echo $block->getBlockHtml('formkey')?> <button type="submit" title="Add to Cart" class="addtocart">Add to Cart</button> </form> </div> <?php else: ?> <div class="stock unavailable" title="<?= /* @escapeNotVerified */ __('Availability') ?>"> <span><?= /* @escapeNotVerified */ __('Out of stock') ?></span> </div> <?php endif; ?> </td> <td class="addtocart"> </td> <?php endif; ?> </tr> <?php if ($block->getCanShowProductPrice($_product) && $block->getCanShowProductPrice($_item) && trim($block->getProductPriceHtml( $_item, \Magento\Catalog\Pricing\Price\TierPrice::PRICE_CODE ))): ?> <tr class="row-tier-price"> <td colspan="2"> <?= $block->getProductPriceHtml( $_item, \Magento\Catalog\Pricing\Price\TierPrice::PRICE_CODE ) ?> </td> </tr> <?php endif; ?> </tbody> <?php endforeach; ?> <?php else: ?> <tbody> <tr> <td class="unavailable" colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"> <?= /* @escapeNotVerified */ __('No options of this product are available.') ?> </td> </tr> </tbody> <?php endif; ?> </table> </div> <div id="validation-message-box"></div> <form></pre><p>步骤2:之后,您需要运行以下命令。</p><p>sudo php bin/magento cache:flush</p><p>结论:</p><p>这样,您可以在Magento 2中将组产品单独添加到购物车中。</p><p><br/></p>
<h5 style="color:red;">系统学习magento二次开发,推荐小册:<a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank">《Magento中文全栈二次开发 》</a></h5> <div class="image-container"> <p> <a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank"> <img src="https://www.maxiaoke.com/uploads/images/20230218/bb9c82995c24d1105676e02f373755f5.jpg" alt="Magento中文全栈二次开发"> </a> </p> </div> <div class="text-container" style="font-size:14px; color:#888"> <p>本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。</p> </div> <hr><p>在Magento 2中按发票ID获取发票详细信息的步骤:</p><p>步骤1:在Magento根目录中创建一个文件,并添加代码,如下所示。</p><pre class="brush:bash;toolbar:false"><?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstraps = Bootstrap::create(BP, $_SERVER); $object_Manager = $bootstraps->getObjectManager(); $app_state = $object_Manager->get('\Magento\Framework\App\State'); $app_state->setAreaCode('frontend'); try { $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Here You Need To Give Invoice Id $invoiceId = 1; $invoiceRepository = $objectManager->get('\Magento\Sales\Api\InvoiceRepositoryInterface'); $invoiceData = $invoiceRepository->get($invoiceId); echo "<pre>"; print_r($invoiceData->getData()); echo "</pre>"; } catch(\Exception $e) { print_r($e->getMessage()); }</pre><p>使用此脚本,您可以获取特定的发票数据。</p><p>结论:</p><p>因此,您可以使用Magento 2中的发票ID检索发票信息。</p><p><br/></p>
<h5 style="color:red;">系统学习magento二次开发,推荐小册:<a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank">《Magento中文全栈二次开发 》</a></h5> <div class="image-container"> <p> <a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank"> <img src="https://www.maxiaoke.com/uploads/images/20230218/bb9c82995c24d1105676e02f373755f5.jpg" alt="Magento中文全栈二次开发"> </a> </p> </div> <div class="text-container" style="font-size:14px; color:#888"> <p>本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。</p> </div> <hr><p>在Magento 2中结帐的运输步骤中显示订单摘要的步骤:</p><p>步骤1:首先,在给定的以下路径的视图文件夹中创建一个requires-config.js文件</p><p>app\code\Vendor\Extension\view\frontend</p><p>现在添加代码,如下所示</p><p></p><pre class="brush:bash;toolbar:false">var config = { config: { mixins: { 'Magento_Checkout/js/view/summary/abstract-total': { 'Vendor_Extension/js/view/summary/abstract-total-mixins': true } } } };</pre><p>步骤2:在第二步中,在以下路径的Web文件夹中创建一个抽象的总混合.js文件</p><p>app\code\Vendor\Extension\view\frontend\web\js\view\summary </p><p>并嵌入以下代码片段</p><p></p><pre class="brush:bash;toolbar:false">define([], function () { 'use strict'; var mixin = { isFullMode: function () { if (!this.getTotals()) { return false; } return true; } }; return function (target) { return target.extend(mixin); }; });</pre><p>步骤3: 清除Magento缓存,之后,您可以在结帐发货页面的右侧看到订单摘要侧边栏。</p><p><img src="/uploads/images/20230829/a620894dfdefb9c35299d4f2b594de9d.png" title="1.png" alt="" width="829" height="424"/></p><p>结帐的运输步骤中的订单摘要</p><p>结论:</p><p>因此,使用上述方法,您可以在Magento 2中结帐的运输步骤中显示订单摘要。您还可以通过在Magento 2中添加自定义内容来自定义结帐订单摘要。</p><p><br/></p>
<h5 style="color:red;">系统学习magento二次开发,推荐小册:<a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank">《Magento中文全栈二次开发 》</a></h5> <div class="image-container"> <p> <a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank"> <img src="https://www.maxiaoke.com/uploads/images/20230218/bb9c82995c24d1105676e02f373755f5.jpg" alt="Magento中文全栈二次开发"> </a> </p> </div> <div class="text-container" style="font-size:14px; color:#888"> <p>本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。</p> </div> <hr><p>在Magento 2的结帐页面中将购物车总数移动到购物车项目下方的步骤:</p><p>步骤1: 您需要 根据需要覆盖模块或主题中的checkout_index_index.xml文件。为模块和主题创建文件的路径如下</p><p>在模块中:</p><p>app\code\Vendor\Extension\view\frontend\layout\checkout_index_index.xml</p><p>在主题中:</p><p>app\design\frontend\Themes\Yourtheme\Magento_Checkout\layout\checkout_index_index.xml</p><p>然后添加代码,如下所示:</p><pre class="brush:bash;toolbar:false"><?xml version="1.0" encoding="UTF-8"?> <page 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="sidebar" xsi:type="array"> <item name="children" xsi:type="array"> <item name="summary" xsi:type="array"> <item name="children" xsi:type="array"> <item name="totals" xsi:type="array"> <item name="sortOrder" xsi:type="string">99</item> </item> <item name="cart_items" xsi:type="array"> <item name="sortOrder" xsi:type="string">0</item> </item> </item> </item> </item> </item> </item> </item> </item> </argument> </arguments> </referenceBlock> </body> </page></pre><p>输出:</p><p><img src="/uploads/images/20230829/5c44222e6065864e9719842330430638.png" title="1.png" alt="" width="780" height="403"/></p><p>购物车项目下方的购物车总计</p><p>结论:</p><p>这样,您可以通过在结帐页面中的购物车项目下方移动购物车总数来自定义Magento 2中的结帐页面。</p><p><br/></p>
<h5 style="color:red;">系统学习magento二次开发,推荐小册:<a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank">《Magento中文全栈二次开发 》</a></h5> <div class="image-container"> <p> <a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank"> <img src="https://www.maxiaoke.com/uploads/images/20230218/bb9c82995c24d1105676e02f373755f5.jpg" alt="Magento中文全栈二次开发"> </a> </p> </div> <div class="text-container" style="font-size:14px; color:#888"> <p>本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。</p> </div> <hr><p>检查客户是否在Magento 2中登录的步骤:</p><p>我们可以使用以下方法检查客户是否已在Magento 2中登录。</p><p>让我们开始吧,</p><p>方法 1: 使用帮助程序文件</p><p>在以下路径处创建帮助程序文件。</p><p>app/code/Vendor/Extension/Helper/Data.php</p><p>然后添加代码,如下所示</p><pre class="brush:bash;toolbar:false"><?php namespace Vendor\Extension\Helper; class Data { public function __construct( \Magento\Framework\App\Http\Context $httpContext ) { $this->httpContext = $httpContext; } public function getLogin() { return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH); } ?></pre><p>注意 – 根据您的要求,您可以在 phtml、控制器等中使用 getLogin() 方法。</p><p>方法 2:使用对象管理器</p><p>在您的Magento根目录中创建customer.php。</p><p>{{magento_root}}/customer.php</p><p>现在,添加以下代码</p><pre class="brush:bash;toolbar:false"><?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; try { $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $appState = $objectManager->get('\Magento\Framework\App\State'); $appState->setAreaCode('frontend'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $userContext = $objectManager->get('Magento\Framework\App\Http\Context'); $loggedin = $userContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH); if($loggedin) { echo "Customer is Logged-In"; } } catch(\Exception $e) { print_r($e->getMessage()); }</pre><p>结论:</p><p>因此,使用上述方法,您可以轻松确定登录到Magento 2商店的客户。</p><p><br/></p>
<h5 style="color:red;">系统学习magento二次开发,推荐小册:<a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank">《Magento中文全栈二次开发 》</a></h5> <div class="image-container"> <p> <a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank"> <img src="https://www.maxiaoke.com/uploads/images/20230218/bb9c82995c24d1105676e02f373755f5.jpg" alt="Magento中文全栈二次开发"> </a> </p> </div> <div class="text-container" style="font-size:14px; color:#888"> <p>本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。</p> </div> <hr><p>在Magento 2中以编程方式按订单ID获取订单数据的步骤:</p><p>第 1 步:在以下路径的 Magento 根目录中创建一个文件</p><p>magento_root_directory\getorderdata.php</p><p>然后添加以下代码片段</p><pre class="brush:bash;toolbar:false"><?php use Magento\Framework\App\Bootstrap; ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); require __DIR__ . '/../app/bootstrap.php'; $params = $_SERVER; $bootstrap = Bootstrap::create(BP, $params); $objectManager = $bootstrap->getObjectManager(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $registry = $objectManager->get('Magento\Framework\Registry'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $orderId=1; //Your Order Id $order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get($orderId); echo "<br>-----Your Order Data-----<br>"; echo "<br> Entity Id : ".$order->getEntityId(); echo "<br> Increment Id : ".$order->getIncrementId(); echo "<br> State : ".$order->getState(); echo "<br> Status : ".$order->getStatus(); echo "<br> StoreId : ".$order->getStoreId(); echo "<br> Subtotal : ".$order->getSubtotal(); echo "<br> GrandTotal : ".$order->getGrandTotal(); echo "<br> TotalQtyOrdered : ".$order->getTotalQtyOrdered(); echo "<br> OrderCurrencyCode : ".$order->getOrderCurrencyCode(); echo "<br>-----Your Customer Data-----<br>"; echo "<br> Customer First Name : ".$order->getCustomerFirstname(); echo "<br> Customer Last Name : ".$order->getCustomerLastname(); echo "<br>-----Your Billing Address Data-----<br>"; echo "<pre>"; print_r($order->getBillingAddress()->getData());echo '<br>'; echo "</pre>"; echo "<br>-----Your Shipping Address Data-----<br>"; echo "<pre>"; print_r($order->getShippingAddress()->getData()); echo "</pre>"; ?></pre><p>结论:</p><p>因此,使用上述方法,您可以使用Magento 2中的订单ID检索订单信息。或者,当您需要Magento之外的订单信息时,您可以使用Magento 2中的SOAP API获取订单信息。</p><p><br/></p>
<h5 style="color:red;">系统学习magento二次开发,推荐小册:<a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank">《Magento中文全栈二次开发 》</a></h5> <div class="image-container"> <p> <a style="color:blue;" href="https://www.maxiaoke.com/manual/magento_cn_dev.html" target="_blank"> <img src="https://www.maxiaoke.com/uploads/images/20230218/bb9c82995c24d1105676e02f373755f5.jpg" alt="Magento中文全栈二次开发"> </a> </p> </div> <div class="text-container" style="font-size:14px; color:#888"> <p>本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。</p> </div> <hr><p>在Magento 2的结帐页面上预先选择默认付款方式的步骤:</p><p>步骤1: 首先,我们必须在扩展名中的以下路径中创建“requirejs-config.js”文件。</p><p>app\code\Vendor\Extension\view\frontend</p><p>然后编写下面的代码</p><pre class="brush:bash;toolbar:false">var config = { config: { mixins: { 'Magento_Checkout/js/model/checkout-data-resolver': { 'Vendor_Extension/js/model/checkout-data-resolver': true } } } };</pre><p>第2步: 之后,我们必须在扩展名中以以下路径创建一个“<span style="margin: 0px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-variant-alternates: inherit; font-weight: 600; font-stretch: inherit; font-size: 17px; line-height: inherit; font-family: Poppins, "Nunito Sans", Montserrat, sans-serif; font-optical-sizing: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; vertical-align: baseline; text-size-adjust: 100%; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(51, 51, 51); letter-spacing: 0.3px; text-wrap: wrap; background-color: rgb(255, 255, 255);">checkout-data-resolver.js</span>”文件。</p><p>app\code\Vendor\Extension\view\frontend\web\js\model</p><p>现在添加代码,如下所示</p><pre class="brush:bash;toolbar:false">define([ 'Magento_Checkout/js/model/payment-service', 'Magento_Checkout/js/checkout-data', 'Magento_Checkout/js/action/select-payment-method' ], function( paymentService, checkoutData, selectPaymentMethodAction ) { 'use strict'; return function(checkoutDataResolver) { checkoutDataResolver.resolvePaymentMethod = function() { var availablePaymentMethods = paymentService.getAvailablePaymentMethods(), selectedPaymentMethod = checkoutData.getSelectedPaymentMethod(), paymentMethod = selectedPaymentMethod ? selectedPaymentMethod : 'cashondelivery'; //set payment method as per your requirement(i.e cashondelivery replace with your payment method) if (availablePaymentMethods.length > 0) { availablePaymentMethods.some(function (payment) { if (payment.method == paymentMethod) { selectPaymentMethodAction(payment); } }); } }; return checkoutDataResolver; }; });</pre><p>在扩展中创建这两个文件后,运行Magento升级并在服务器中部署命令。</p><p>在店面中,您将看到在Magento 2的结帐页面上预先选择了默认付款方式。</p><p>预选默认付款方式</p><p><img src="/uploads/images/20230828/788074b262490a34b9e6b567c0d636a3.png" title="2.png" alt="" width="833" height="427"/></p><p>结论:</p><p>因此,使用上述步骤,您可以在Magento 2的结帐页面上轻松预先选择默认付款方式,并减少客户选择付款方式的工作量。</p><p>使用支付网关集成服务将您想要的付款方式集成到您的Magento 2商店中 ,并将其设置为默认付款方式,并使用上述方法在结帐页面上进行预选。</p><p><br/></p>