文章列表


如何在Magento 2中使用REST API获取所有订单状态

<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>流行的API类型之一是REST,旨在利用现有的HTTP协议。主要是,RESTful API是一个应用程序接口(API),它使用HTTP请求来获取,放置,发布和删除数据。此外,如果您想使用 REST API,则不需要安装任何插件或库。REST API的唯一主要优点是它提供了更好的灵活性,可以处理多种类型的调用,返回不同的数据格式,并且可以在结构上实现正确的超媒体。这意味着它允许开发人员通过接触新客户来构建满足所有业务需求的 API。</p><p>同样,Magento 2 API框架允许开发人员开发新的服务,用于使用CRUD操作同步Magento 2存储数据。</p><p>此外,如果您熟悉在 PHP 中调用 API 的流程,那么使用 Rest API 就像馅饼一样简单。如果您正在开发此类服务,您可能会遇到使用 REST API 获取订单数据的要求。因此,我们再次回到了另一个博客,它允许您使用Magento 2中的REST API获取所有订单状态。</p><p>首先,我们需要在此路径的扩展中创建“注册.php”文件。</p><p>app\code\VENDOR\EXTENSION</p><p>&lt;!--?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, <span style="color: #ce9178;">&#39;VENDOR_EXTENSION&#39;</span>, __DIR__ )<span style="color: #6a9955;">; &lt;/pre&gt; &lt;p&gt;After that, we need to create “&lt;strong&gt;Module.xml&lt;/strong&gt;” file inside extension etc folder&lt;br ?--&gt;</span></p><p>&lt;strong&gt;app\code\VENDOR\EXTENSION\etc&lt;/strong&gt;</p><p>&lt;!--?xml <span style="color: #569cd6;">version</span>=<span style="color: #ce9178;">&quot;1.0&quot;</span>?--&gt;</p><p>现在,我们必须在同一个 etc 文件夹中再创建一个文件“Webapi.xml”。</p><p>app\code\VENDOR\EXTENSION\etc</p><p>&lt;!--?xml <span style="color: #569cd6;">version</span>=<span style="color: #ce9178;">&quot;1.0&quot;</span>?--&gt;</p><p>之后,我们需要在同一等文件夹中创建“Di.xml”文件。</p><p>app\code\VENDOR\EXTENSION\etc</p><p>&lt;!--?xml <span style="color: #569cd6;">version</span>=<span style="color: #ce9178;">&quot;1.0&quot;</span>?--&gt;</p><p>之后,我们需要在扩展 API 文件夹中创建“Getorderstatus.php”文件来提供响应。</p><p>app\code\VENDOR\EXTENSION\Api\</p><pre class="brush:bash;toolbar:false">&lt;!--?php&nbsp;namespace&nbsp;VENDOR\EXTENSION\Api ;&nbsp;interface&nbsp;Getorderstatus&nbsp;{&nbsp;public&nbsp;function&nbsp;getorderstatusarray();&nbsp;}&nbsp;&lt;/pre&gt;&nbsp;&lt;p&gt;Lastly,&nbsp;Create&nbsp;&quot;&lt;strong&gt;GetorderstatusModel.php&lt;/strong&gt;&quot;&nbsp;file&nbsp;inside&nbsp;model&nbsp;folder&nbsp;of&nbsp;extension.&lt;br&nbsp;?--&gt;</pre><p>&lt;strong&gt;app\code\VENDOR\EXTENSION\Model&lt;/strong&gt;</p><pre class="brush:bash;toolbar:false">&lt;!--?php&nbsp;namespace&nbsp;VENDOR\EXTENSION\Model ;&nbsp;use&nbsp;VENDOR\EXTENSION\Api\Getorderstatus;&nbsp;class&nbsp;GetorderstatusModel&nbsp;implements&nbsp;Getorderstatus&nbsp;{&nbsp;protected&nbsp;$statusCollectionFactory;&nbsp;public&nbsp;function&nbsp;__construct(&nbsp;\Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory&nbsp;$statusCollectionFactory&nbsp;)&nbsp;{&nbsp;$this-&gt;statusCollectionFactory&nbsp;=&nbsp;$statusCollectionFactory;&nbsp;}&nbsp;public&nbsp;function&nbsp;getorderstatusarray()&nbsp;{&nbsp;$options&nbsp;=&nbsp;$this-&gt;statusCollectionFactory-&gt;create()-&gt;toOptionArray();&nbsp;return&nbsp;$options;&nbsp;}&nbsp;}&nbsp;&lt;/pre&gt;&nbsp;&lt;p&gt;Now,&nbsp;Go&nbsp;to&nbsp;&lt;strong&gt;Admin&nbsp;-&gt;&nbsp;System&nbsp;-&gt;&nbsp;Integrations&lt;/strong&gt;&nbsp;and&nbsp;Get&nbsp;Access&nbsp;Token&nbsp;value&nbsp;and&nbsp;set&nbsp;authorization&nbsp;value&nbsp;into&nbsp;postman&nbsp;application.&lt;br&nbsp;?--&gt;</pre><p>今天就讲到这里!您已成功添加获取Magento 2订单状态,您可以根据使用REST API获取数据的需要自由自定义此代码。</p><p><br/></p>

如何在Magento中将自定义字段从报价单项转换为订单项

<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将每个购物车存储在后端中称为持久购物车,所有添加的产品都绑定在一个报价项目字段中。但是,如果恢复此类购物车,则只会恢复选定的产品,而不会恢复其额外费用或运费。因此,每次您的客户在回来结账时都需要重新选择每个选项。</p><p>因此,要解决此类问题,您需要在后端创建自定义附加报价字段,该字段保存此类值并在购物车恢复时重新应用费用。要执行相同的操作,只需按照以下两个步骤将自定义字段从报价单项转换为Magento</p><p>中的订单项 首先,在以下路径创建“di.xml”文件。</p><p>app\code \Vendor \Extension\etc\</p><pre class="brush:bash;toolbar:false">&lt;pre&nbsp;class=&quot;lang:default&nbsp;decode:true&quot;&gt; &lt;?xml&nbsp;version=&quot;1.0&quot;?&gt; &lt;config&nbsp;xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&nbsp;xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:ObjectManager/etc/config.xsd&quot;&gt; &nbsp;&nbsp;&lt;type&nbsp;name=&quot;Magento\Quote\Model\Quote\Item\ToOrderItem&quot;&gt; &nbsp;&lt;plugin&nbsp;name=&quot;quote_item_to_order_item&quot;&nbsp;&nbsp;&nbsp;&nbsp;type=&quot;Vendor\Extension\Plugin\Quote\Convertquoteitemtoorder&quot;/&gt; &lt;/type&gt; &nbsp;&lt;/config&gt; &lt;/pre&gt;</pre><p>现在,我们需要再创建一个文件“转换报价项到订单.php”以在此路径上转换报价项。</p><p>app\code\Vendor\Extension\Plugin\Quote\</p><p><br/></p><pre class="brush:bash;toolbar:false">&lt;pre&nbsp;class=&quot;lang:default&nbsp;decode:true&quot;&gt; &lt;?php namespace&nbsp;Vendor\Extension\Plugin\Quote; class&nbsp;Convertquoteitemtoorder{ &nbsp;public&nbsp;function&nbsp;aroundConvert( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\Magento\Quote\Model\Quote\Item\ToOrderItem&nbsp;$subject, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\Closure&nbsp;$proceed, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\Magento\Quote\Model\Quote\Item\AbstractItem&nbsp;$item, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$additional&nbsp;=&nbsp;[] &nbsp;)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$orderItem&nbsp;=&nbsp;$proceed($item,&nbsp;$additional); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$orderItem-&gt;setCustomField1($item-&gt;getCustomField1()); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$orderItem-&gt;setCustomField2($item-&gt;getCustomField2()); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$orderItem-&gt;setCustomField3($item-&gt;getCustomField3()); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$orderItem; &nbsp;} } &lt;/pre&gt;</pre><p>就是这样,通过遵循这两个简单的步骤,您可以将报价字段中的所有附加自定义字段转移到客户的最终订单列表中。您可以自由添加上面的代码操作。</p><p><br/></p>

如何在Magento 2的结帐页面中预先打开“应用优惠券代码”

<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>在前端客户结账时,您的客户可以在下订单之前轻松应用优惠券代码。但是,如果您看到此功能,则可以将其用作折叠选项卡,有时不容易注意到。因此,即使拥有优惠券代码,您的客户也无法在结帐时找到申请选项并放弃购物车。相反,以编程方式将此折叠的选项卡保持打开状态,突出显示优惠券代码框,您的客户可以轻松查找和使用代码。</p><p>为此,您必须将折扣可折叠小部件设置为 true,并且需要通过创建自定义扩展来覆盖两个模板文件。</p><p>首先,我们需要使用以下代码在自定义扩展中创建一个“checkout_cart_index.xml”文件。</p><p>app/code/VENDOR/EXTENSION/view/frontend/layout/</p><pre class="brush:bash;toolbar:false">&lt;pre&nbsp;class=&quot;lang:default&nbsp;decode:true&quot;&gt; &lt;?xml&nbsp;version=&quot;1.0&quot;&nbsp;encoding=&quot;UTF-8&quot;?&gt; &lt;page&nbsp;xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&nbsp;xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:View/Layout/etc/page_configuration.xsd&quot;&gt; &nbsp;&lt;body&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;referenceContainer&nbsp;name=&quot;cart.summary&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;block&nbsp;class=&quot;Magento\Checkout\Block\Cart\Coupon&quot;&nbsp;name=&quot;checkout.cart.coupon&quot;&nbsp;as=&quot;coupon&quot;&nbsp;template=&quot;VENDOR_EXTENSION::cart/coupon.phtml&quot;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/referenceContainer&gt; &nbsp;&lt;/body&gt; &lt;/page&gt; &lt;/pre&gt;</pre><p>现在,您需要使用以下代码在此路径上再创建一个文件“coupon.phtml”。</p><p>app/code/VENDOR/EXTENSION/view/frontend/templates/cart/</p><pre class="brush:bash;toolbar:false">&lt;pre&nbsp;class=&quot;lang:default&nbsp;decode:true&quot;&gt; &lt;?php &nbsp; //&nbsp;@codingStandardsIgnoreFile ?&gt; &lt;div&nbsp;class=&quot;block&nbsp;discount&quot;&nbsp;id=&quot;block-discount&quot;&nbsp;data-mage-init=&#39;{&quot;collapsible&quot;:{&quot;openedState&quot;:&nbsp;&quot;active&quot;,&nbsp;&quot;active&quot;:&nbsp;true,&nbsp;&quot;saveState&quot;:&nbsp;false}}&#39;&gt; &nbsp;&lt;div&nbsp;class=&quot;title&quot;&nbsp;data-role=&quot;title&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;strong&nbsp;id=&quot;block-discount-heading&quot;&nbsp;role=&quot;heading&quot;&nbsp;aria-level=&quot;2&quot;&gt;&lt;?=&nbsp;/*&nbsp;@escapeNotVerified&nbsp;*/&nbsp;__(&#39;Apply&nbsp;Discount&nbsp;Code&#39;)&nbsp;?&gt;&lt;/strong&gt; &nbsp;&lt;/div&gt; &nbsp;&lt;div&nbsp;class=&quot;content&quot;&nbsp;data-role=&quot;content&quot;&nbsp;aria-labelledby=&quot;block-discount-heading&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;form&nbsp;id=&quot;discount-coupon-form&quot; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action=&quot;&lt;?=&nbsp;/*&nbsp;@escapeNotVerified&nbsp;*/&nbsp;$block-&gt;getUrl(&#39;checkout/cart/couponPost&#39;)&nbsp;?&gt;&quot; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method=&quot;post&quot; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data-mage-init=&#39;{&quot;discountCode&quot;:{&quot;couponCodeSelector&quot;:&nbsp;&quot;#coupon_code&quot;, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;removeCouponSelector&quot;:&nbsp;&quot;#remove-coupon&quot;, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;applyButton&quot;:&nbsp;&quot;button.action.apply&quot;, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;cancelButton&quot;:&nbsp;&quot;button.action.cancel&quot;}}&#39;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;class=&quot;fieldset&nbsp;coupon&lt;?=&nbsp;strlen($block-&gt;getCouponCode())&nbsp;?&nbsp;&#39;&nbsp;applied&#39;&nbsp;:&nbsp;&#39;&#39;&nbsp;?&gt;&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type=&quot;hidden&quot;&nbsp;name=&quot;remove&quot;&nbsp;id=&quot;remove-coupon&quot;&nbsp;value=&quot;0&quot;&nbsp;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;class=&quot;field&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label&nbsp;for=&quot;coupon_code&quot;&nbsp;class=&quot;label&quot;&gt;&lt;span&gt;&lt;?=&nbsp;/*&nbsp;@escapeNotVerified&nbsp;*/&nbsp;__(&#39;Enter&nbsp;discount&nbsp;code&#39;)&nbsp;?&gt;&lt;/span&gt;&lt;/label&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;class=&quot;control&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type=&quot;text&quot;&nbsp;class=&quot;input-text&quot;&nbsp;id=&quot;coupon_code&quot;&nbsp;name=&quot;coupon_code&quot;&nbsp;value=&quot;&lt;?=&nbsp;$block-&gt;escapeHtml($block-&gt;getCouponCode())&nbsp;?&gt;&quot;&nbsp;placeholder=&quot;&lt;?=&nbsp;$block-&gt;escapeHtml(__(&#39;Enter&nbsp;discount&nbsp;code&#39;))&nbsp;?&gt;&quot;&nbsp;&lt;?php&nbsp;if&nbsp;(strlen($block-&gt;getCouponCode())):&nbsp;?&gt;&nbsp;disabled=&quot;disabled&quot;&nbsp;&lt;?php&nbsp;endif;&nbsp;?&gt;&nbsp;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;class=&quot;actions-toolbar&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php&nbsp;if&nbsp;(!strlen($block-&gt;getCouponCode())):&nbsp;?&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;class=&quot;primary&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;button&nbsp;class=&quot;action&nbsp;apply&nbsp;primary&quot;&nbsp;type=&quot;button&quot;&nbsp;value=&quot;&lt;?=&nbsp;/*&nbsp;@escapeNotVerified&nbsp;*/&nbsp;__(&#39;Apply&nbsp;Discount&#39;)&nbsp;?&gt;&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;span&gt;&lt;?=&nbsp;/*&nbsp;@escapeNotVerified&nbsp;*/&nbsp;__(&#39;Apply&nbsp;Discount&#39;)&nbsp;?&gt;&lt;/span&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/button&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php&nbsp;else:&nbsp;?&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;class=&quot;primary&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;button&nbsp;&nbsp;type=&quot;button&quot;&nbsp;class=&quot;action&nbsp;cancel&nbsp;primary&quot;&nbsp;value=&quot;&lt;?=&nbsp;/*&nbsp;@escapeNotVerified&nbsp;*/&nbsp;__(&#39;Cancel&nbsp;Coupon&#39;)&nbsp;?&gt;&quot;&gt;&lt;span&gt;&lt;?=&nbsp;/*&nbsp;@escapeNotVerified&nbsp;*/&nbsp;__(&#39;Cancel&nbsp;Coupon&#39;)&nbsp;?&gt;&lt;/span&gt;&lt;/button&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php&nbsp;endif;&nbsp;?&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt; &nbsp;&lt;/div&gt; &lt;/div&gt; &lt;/pre&gt;</pre><p>就是这样。如果您看到上面的“coupon.phtml”模板文件,我们已经修改了以下</p><p>代码 执行此操作后,此自定义扩展将使您的优惠券代码框保持打开状态而不会折叠。</p><p>最后,如果您发现此博客有帮助,请不要忘记与您的同事和Magento朋友分享,如果您在实现此代码时遇到任何问题,请告诉我们。</p><p>祝您编码愉快!</p><pre class="brush:bash;toolbar:false">&lt;pre&nbsp;class=&quot;lang:default&nbsp;decode:true&quot;&gt; &lt;div&nbsp;class=&quot;block&nbsp;discount&quot;&nbsp;id=&quot;block-discount&quot;&nbsp;data-mage-init=&#39;{&quot;collapsible&quot;:{&quot;openedState&quot;:&nbsp;&quot;active&quot;,&nbsp;&quot;saveState&quot;:&nbsp;false}}&#39;&gt; &lt;/pre&gt; to &lt;pre&nbsp;class=&quot;lang:default&nbsp;decode:true&quot;&gt; &lt;div&nbsp;class=&quot;block&nbsp;discount&quot;&nbsp;id=&quot;block-discount&quot;&nbsp;data-mage-init=&#39;{&quot;collapsible&quot;:{&quot;openedState&quot;:&nbsp;&quot;active&quot;,&nbsp;&quot;active&quot;:&nbsp;true,&nbsp;&quot;saveState&quot;:&nbsp;false}}&#39;&gt; &lt;/pre&gt;</pre><p><br/></p>

如何在Magento 2中使用标准方式编写删除SQL查询而不使用模型文件

<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>这是我执行删除SQL查询以向您展示一个演示,该演示如何在不使用Magento 2中的模型文件的情况下删除特定数量的行/记录。</p><p>为此,我使用以下代码在此路径的扩展文件夹中创建了“Index.php”文件。</p><p>app\code\Vendor\Extension\Controller\Deletequery\</p><pre class="brush:bash;toolbar:false">&lt;pre&nbsp;class=&quot;lang:default&nbsp;decode:true&quot;&gt; &lt;?php namespace&nbsp;Vendor\Extension\Controller\Deletequery; use&nbsp;Magento\Framework\App\ResourceConnection; use&nbsp;Magento\Framework\App\Action\Context; class&nbsp;Index&nbsp;extends&nbsp;\Magento\Framework\App\Action\Action { &nbsp;const&nbsp;QUOTE_TABLE&nbsp;=&nbsp;&#39;quote&#39;; &nbsp;private&nbsp;$resourceConnection; &nbsp;public&nbsp;function&nbsp;__construct( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Context&nbsp;$context, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ResourceConnection&nbsp;$resourceConnection) &nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;resourceConnection&nbsp;=&nbsp;$resourceConnection; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;parent::__construct($context); &nbsp;} &nbsp;public&nbsp;function&nbsp;execute() &nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$connection&nbsp;&nbsp;=&nbsp;$this-&gt;resourceConnection-&gt;getConnection(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tableName&nbsp;=&nbsp;$connection-&gt;getTableName(self::QUOTE_TABLE); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$quoteId&nbsp;=&nbsp;191; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$whereConditions&nbsp;=&nbsp;[ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$connection-&gt;quoteInto(&#39;entity_id&nbsp;=&nbsp;?&#39;,&nbsp;$quoteId), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$deleteRows&nbsp;=&nbsp;$connection-&gt;delete($tableName,&nbsp;$whereConditions); &nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&quot;Deleted&nbsp;Rows&nbsp;:&nbsp;&quot;.$deleteRows; &nbsp;} } &lt;/pre&gt;</pre><p>就是这样。使用此代码,您可以执行类似的不同SQL操作,而无需创建标准的Magento 2模型文件。</p><p><br/></p>

如何解决安装Magento 2.x后的空白页问题

<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.x后遇到相同的空白页问题,这是一个解决方案。</p><p>要先执行相同的操作,您需要打开位于以下路径的“验证器.php”文件。</p><p>vendor\magento\framework\View\Element\Template\File\Validator.php</p><p>大约在第 133 行左右,你会发现这个函数。</p><p>protected function isPathInDirectories($path, $directories)</p><p>现在在这个函数中找到这个代码。</p><p>$<span style="color: #569cd6;">realPath</span> = $this-&gt;fileDriver-&gt;getRealPath($path)<span style="color: #6a9955;">;</span></p><p>并将其替换为以下代码。</p><p>$<span style="color: #569cd6;">realPath</span> = str_replace(<span style="color: #ce9178;">&#39;</span><span style="color: #d7ba7d;">\\</span><span style="color: #ce9178;">&#39;</span>, <span style="color: #ce9178;">&#39;/&#39;</span>, $this-&gt;fileDriver-&gt;getRealPath($path))<span style="color: #6a9955;">;</span></p><p>就是这样,现在打开命令行界面 (CLI) 并运行以下命令。</p><pre class="brush:bash;toolbar:false">php&nbsp;bin/magento&nbsp;cache:clean php&nbsp;bin/magento&nbsp;cache:flush php&nbsp;bin/magento&nbsp;indexer:reindex php&nbsp;bin/magento&nbsp;setup:upgrade php&nbsp;bin/magento&nbsp;setup:static-content:deploy&nbsp;-f</pre><p>就是这样。现在导航到管理页面,它将开始工作,您的空白页问题现已解决。</p><p><br/></p>

如何在Magento 2中以编程方式更改客户密码

<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是为电子商务CMS打造的之一,以其功能,灵活的代码结构和性能而闻名。它使用 MySQL 作为存储后端,以表格格式存储和检索数据。它存储所有有用信息的位置,例如客户数据,订单数据和配置。</p><p>但是很多时候,您的客户无法在商店前端登录,或者他们忘记了重置详细信息或商店电子邮件不起作用,在这种情况下如何重置客户帐户的密码?如果您是新手,则解决客户的登录问题变得更加困难。但是,如果您是Magento专家,则可以轻松重置密码并恢复其登录的一些技巧。因此,我们再次使用了一个小型PHP脚本,您可以使用该脚本快速重置客户帐户密码。</p><p>只需使用以下代码在Magento根目录中创建一个“change_password.php”文件。不要忘记指定要在代码中设置的客户 ID 和密码。</p><pre class="brush:bash;toolbar:false">&lt;?php use&nbsp;Magento\Framework\AppInterface; try&nbsp;{ &nbsp;require_once&nbsp;__DIR__&nbsp;.&nbsp;&#39;/app/bootstrap.php&#39;; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(\Exception&nbsp;$e)&nbsp;{ &nbsp;echo&nbsp;&#39;Autoload&nbsp;error:&nbsp;&#39;&nbsp;.&nbsp;$e-&gt;getMessage(); &nbsp;exit(1); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try{ &nbsp;$bootstrap&nbsp;=&nbsp;\Magento\Framework\App\Bootstrap::create(BP,&nbsp;$_SERVER); &nbsp;$objectManager&nbsp;=&nbsp;$bootstrap-&gt;getObjectManager(); &nbsp;$appState&nbsp;=&nbsp;$objectManager-&gt;get(&#39;\Magento\Framework\App\State&#39;); &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$customerRepositoryInterface&nbsp;=&nbsp;$objectManager-&gt;get(&#39;\Magento\Customer\Api\CustomerRepositoryInterface&#39;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$customerRegistry&nbsp;=&nbsp;$objectManager-&gt;get(&#39;\Magento\Customer\Model\CustomerRegistry&#39;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$encryptor&nbsp;=&nbsp;$objectManager-&gt;get(&#39;\Magento\Framework\Encryption\EncryptorInterface&#39;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$appState-&gt;setAreaCode(&#39;frontend&#39;); &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$customerId&nbsp;=&nbsp;1;&nbsp;//&nbsp;here&nbsp;assign&nbsp;your&nbsp;customer&nbsp;id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$password&nbsp;=&nbsp;&quot;custom_password&quot;;&nbsp;//&nbsp;set&nbsp;your&nbsp;custom&nbsp;password &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$customer&nbsp;=&nbsp;$customerRepositoryInterface-&gt;getById($customerId);&nbsp;//&nbsp;_customerRepositoryInterface&nbsp;is&nbsp;an&nbsp;instance&nbsp;of&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\Magento\Customer\Api\CustomerRepositoryInterface &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$customerSecure&nbsp;=&nbsp;$customerRegistry-&gt;retrieveSecureData($customerId);&nbsp;//&nbsp;_customerRegistry&nbsp;is&nbsp;an&nbsp;instance&nbsp;of&nbsp;\Magento\Customer\Model\CustomerRegistry &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$customerSecure-&gt;setRpToken(null); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$customerSecure-&gt;setRpTokenCreatedAt(null); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$customerSecure-&gt;setPasswordHash($encryptor-&gt;getHash($password,&nbsp;true));&nbsp;//&nbsp;here&nbsp;_encryptor&nbsp;is&nbsp;an&nbsp;instance&nbsp;of&nbsp;\Magento\Framework\Encryption\EncryptorInterface &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$customerRepositoryInterface-&gt;save($customer); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&#39;Successfully&nbsp;Changes&nbsp;Your&nbsp;Password.&#39;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catch(\Exception&nbsp;$e){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print_r($e-&gt;getMessage()); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</pre><p>就是这样。成功执行脚本后,您的客户将能够使用定义的密码登录其帐户。在这种紧急情况下,使用PHP脚本重置密码成为开发人员的救星。</p><p><br/></p>

如何在不使用Magento 2中的模型文件的情况下创建更新查询

<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中有一定的编码标准。根据这些标准,开发人员必须创建一个模型文件才能执行任何SQL查询。对于电子商务商店来说,这是一个近乎完美的平台中的一个忙碌的困境。</p><p>但是,如果可以在不使用模型文件的情况下执行这些SQL查询,该怎么办?相信我,这是可能的。今天的博客也是关于同样的。在这里,我将向您展示如何执行更新查询。在下面的代码中显示了更新,它显示了如何在不使用模态文件的情况下执行任意次数的更新。那么,让我们开始吧...??</p><p>最初,为了执行它,您需要在我的扩展文件夹中创建一个“Index.php”文件,该文件位于下面定义的路径中。</p><p>app\code\Vendor\Extension\Controller\Deletequery\</p><p>创建文件夹后,您需要应用以下代码才能执行更新操作。</p><pre class="brush:bash;toolbar:false">&lt;?php namespace&nbsp;Vendor\Extension\Controller\Updatequery;&nbsp; use&nbsp;Magento\Framework\App\ResourceConnection;&nbsp; use&nbsp;Magento\Framework\App\Action\Context;&nbsp; class&nbsp;Index&nbsp;extends&nbsp;\Magento\Framework\App\Action\Action&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;QUOTE_TABLE&nbsp;=&nbsp;&#39;[TABLE_NAME]&#39;; &nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;$resourceConnection; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;__construct(&nbsp;Context&nbsp;$context,&nbsp;ResourceConnection&nbsp;$resourceConnection)&nbsp;{&nbsp;$this-&gt;resourceConnection&nbsp;=&nbsp;$resourceConnection; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;parent::__construct($context); &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;execute() &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$connection&nbsp;&nbsp;=&nbsp;$this-&gt;resourceConnection-&gt;getConnection(); &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$data&nbsp;=&nbsp;[&quot;field1&quot;=&gt;3,&quot;field2&quot;=&gt;15];&nbsp;//&nbsp;you&nbsp;can&nbsp;use&nbsp;as&nbsp;per&nbsp;your&nbsp;requirement &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$id&nbsp;=&nbsp;1; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$where&nbsp;=&nbsp;[&#39;entity_id&nbsp;=&nbsp;?&#39;&nbsp;=&gt;&nbsp;(int)$id]; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tableName&nbsp;=&nbsp;$connection-&gt;getTableName(self::QUOTE_TABLE); &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$updatedRows=$connection-&gt;update($tableName,&nbsp;$data,&nbsp;$where); &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&quot;Updated&nbsp;Rows&nbsp;:&nbsp;&quot;.$updatedRows; &nbsp;&nbsp;&nbsp;&nbsp;} }</pre><p>就是这样。借助此代码,您可以执行多个 SQL 更新操作,而无需创建模型文件。不创建标准的Magento 2模型文件在您的开发阶段会非常有用。</p><p><br/></p>

如何在Magento 2中创建自定义销售规则条件

<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>但是,如果要创建自定义购物车规则以触发特定代码以响应该事件。要执行相同的操作,您必须创建自定义扩展以满足您的业务需求,因为我们从未建议修改核心文件。让我们以设置购物车页面的城市字段的自定义销售规则为例。您还可以为不同的事件创建自定义购物车规则。</p><p>首先要做同样的事情,我们需要在 etc 文件夹中创建“events.xml”文件,并在该文件中添加粘贴下面的代码。</p><p>app\code\Vendor\Extension\etc\events.xml</p><pre class="brush:bash;toolbar:false">&lt;?xml&nbsp;version=&quot;1.0&quot;?&gt; &nbsp; &lt;config&nbsp;xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&nbsp; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Event/etc/events.xsd&quot;&gt; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&lt;event&nbsp;name=&quot;salesrule_rule_condition_combine&quot;&gt; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&lt;observer&nbsp;name=&quot;customer_rule&quot;&nbsp; instance=&quot;Vendor\Extension\Observer\Shippingcityconditionobserver&quot;&nbsp;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;/event&gt; &lt;/config&gt;</pre><p>现在,我们在观察者文件夹中创建“Shippingcityconditionobserver.php”。</p><p>app\code\Vendor\Extension\Observer\Shippingcityconditionobserver.php</p><pre class="brush:bash;toolbar:false">&lt;?php namespace&nbsp;Vendor\Extension\Observer; &nbsp; class&nbsp;Shippingcityconditionobserver&nbsp;implements&nbsp;\Magento\Framework\Event\ObserverInterface { &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;execute(\Magento\Framework\Event\Observer&nbsp;$observer) &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$additional&nbsp;=&nbsp;$observer-&gt;getAdditional(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$conditions&nbsp;=&nbsp;(array)&nbsp;$additional-&gt;getConditions(); &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$conditions&nbsp;=&nbsp;array_merge_recursive($conditions,&nbsp;[ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;getCustomerFirstOrderCondition() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]); &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$additional-&gt;setConditions($conditions); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$this; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;function&nbsp;getCustomerFirstOrderCondition() &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;[ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;label&#39;=&gt;&nbsp;__(&#39;Shipping&nbsp;city&#39;), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;value&#39;=&gt;&nbsp;\Vendor\Extension\Model\Rule\Condition\Shippingcity::class &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]; &nbsp;&nbsp;&nbsp;&nbsp;} }</pre><p>在以下路径再创建一个文件“di.xml”文件。</p><p>app\code\Vendor\Extension\etc\di.xml</p><pre class="brush:bash;toolbar:false">&lt;?xml&nbsp;version=&quot;1.0&quot;?&gt; &lt;config&nbsp;xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&nbsp; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:ObjectManager/etc/config.xsd&quot;&gt; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&lt;type&nbsp;name=&quot;Vendor\Extension\Model\Rule\Condition\Shippingcity&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;arguments&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;argument&nbsp;name=&quot;data&quot;&nbsp;xsi:type=&quot;array&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;item&nbsp;name=&quot;form_name&quot;&nbsp;xsi:type=&quot;string&quot;&gt;sales_rule_form&lt;/item&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/argument&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/arguments&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;/type&gt; &lt;/config&gt;</pre><p>最后,在此位置再创建一个名为“Shippingcity.php”的文件。</p><p>app\code\Vendor\Extension\Model\Rule\Condition\Shippingcity.php</p><pre class="brush:bash;toolbar:false">&lt;?php namespace&nbsp;Vendor\Extension\Model\Rule\Condition; class&nbsp;Shippingcity&nbsp;extends&nbsp;\Magento\Rule\Model\Condition\AbstractCondition { &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;$_checkoutSession; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;__construct( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\Magento\Rule\Model\Condition\Context&nbsp;$context, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\Magento\Checkout\Model\Session&nbsp;$checkoutSession, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array&nbsp;$data&nbsp;=&nbsp;[] &nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parent::__construct($context,&nbsp;$data); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;_checkoutSession&nbsp;=&nbsp;$checkoutSession; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; public&nbsp;function&nbsp;loadAttributeOptions() &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;setAttributeOption([ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;shipping_city&#39;&nbsp;=&gt;&nbsp;__(&#39;Shipping&nbsp;city&#39;) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$this; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;getInputType() &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&#39;select&#39;;&nbsp;&nbsp;//&nbsp;input&nbsp;type&nbsp;for&nbsp;admin&nbsp;condition &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;getValueElementType() &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&#39;text&#39;; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;validate(\Magento\Framework\Model\AbstractModel&nbsp;$model) &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$city&nbsp;=&nbsp;$this-&gt;_checkoutSession-&gt;getQuote()-&gt;getShippingAddress()-&gt;getCity(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$model-&gt;setData(&#39;shipping_city&#39;,&nbsp;$city);&nbsp;&nbsp;//&nbsp;validation&nbsp;value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;parent::validate($model); &nbsp;&nbsp;&nbsp;&nbsp;} }</pre><p>只需清除缓存,您将在管理后端找到一个选项。您还可以使用上面的代码来创建不同类型的自定义运输规则。</p><p><br/></p>

如何在Magento 2中创建自定义页面布局

<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商店的自定义要求创建自定义页面布局,以获得更好的前端视图。但是,Magento默认提供1列,2列-左,2列-右,3列。</p><p>但在某些情况下,您需要开发自定义页面布局,而不是使用默认页面布局来满足自定义要求。对于主页或您希望的任何特定页面,您可以更改页面设计以满足您的要求并提高页面性能。</p><p>我们可以通过一些编码知识在Magento本身中实现这一目标。您需要按照下面描述的步骤使用编码创建自定义页面布局。</p><p>例如,如果要创建custom_column布局,则需要关注两个基本文件,</p><p>layout.xml</p><p>page_layout/custom_column.xml</p><p>让我们从第一步开始,找到布局.xml文件,</p><p>app\code\Vendor\Extension\view\layout.xml</p><p>使用下面描述的代码创建自定义布局:</p><pre class="brush:bash;toolbar:false">&lt;?xml&nbsp;version=&quot;1.0&quot;&nbsp;encoding=&quot;UTF-8&quot;?&gt; &nbsp; &lt;page_layouts&nbsp;xmlns:xsi=&quot;http://&nbsp;www.w3.org/2001/XMLSchema-instance&quot;&nbsp;xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:View/&nbsp;PageLayout/etc/layouts.xsd&quot;&gt; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&lt;layout&nbsp;id=&quot;&nbsp;custom_column&quot;&gt; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label&nbsp;translate=&quot;true&quot;&gt;Custom&nbsp;layout&lt;/label&gt; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&lt;/layout&gt; &nbsp; &lt;/page_layouts&gt;</pre><p>使用此代码,将在管理面板中创建自定义布局文件。</p><p>page_layout/custom_column.xml</p><p>在以下位置找到page_layout/custom_column.xml文件,</p><p>app\code\Vendor\Extension\view\page_layout\custom_column.xml</p><p>使用以下代码创建文件,以管理使用上述代码创建的页面布局设计:</p><pre class="brush:bash;toolbar:false">&lt;?xml&nbsp;version=&quot;1.0&quot;?&gt; &nbsp; &lt;layout&nbsp;xmlns:xsi=&quot;http://www.&nbsp;w3.org/2001/XMLSchema-instance&quot;&nbsp;xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:View/&nbsp;Layout/etc/page_layout.xsd&quot;&gt; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;update&nbsp;handle=&quot;1column&quot;/&gt; &nbsp; &nbsp;&nbsp;&nbsp;&lt;referenceContainer&nbsp;name=&quot;page.wrapper&quot;&nbsp;htmlClass=&quot;page-wrapper&nbsp;page-layout-1column&nbsp;layout-custom-column&quot;/&gt; &nbsp; &lt;/layout&gt;</pre><p>使用这些代码创建自定义页面布局文件后,您需要做的第一件事就是清除缓存。您的自定义页面布局将自动添加到页面布局列表中。</p><p>因此,在这篇文章中,我们了解到使用这些代码,您将能够为您的自定义主题或要求创建新的自定义页面布局,以便您可以获得更好的前端视图。此外,您还可以自定义布局以帮助提高页面性能。按照上述步骤操作,您就可以开始了。</p><p><br/></p>

如何在Magento 2中创建新产品时设置自定义默认数量

<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>按照下面描述的步骤在Magento2.3中创建新产品时设置自定义默认数量。</p><p>您要做的第一件事是创建一个文件app\code\Vendor\Extension\etc\adminhtml\di.xml</p><p>创建文件后,使用以下代码修改默认数量</p><pre class="brush:bash;toolbar:false">&lt;?xml&nbsp;version=&quot;1.0&quot;?&gt; &nbsp; &lt;config&nbsp;xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&nbsp;xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:ObjectManager/etc/config.xsd&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;virtualType&nbsp;name=&quot;Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;arguments&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;argument&nbsp;name=&quot;modifiers&quot;&nbsp;xsi:type=&quot;array&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;item&nbsp;name=&quot;defaultQtyModifier&quot;&nbsp;xsi:type=&quot;array&quot;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;item&nbsp;name=&quot;class&quot;&nbsp;xsi:type=&quot;string&quot;&gt;VENDOR\EXTENSION\Ui\DataProvider\Product\Form\Modifier\DefaultQtyModifier&lt;/item&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;item&nbsp;name=&quot;sortOrder&quot;&nbsp;xsi:type=&quot;number&quot;&gt;200&lt;/item&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/item&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/argument&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/arguments&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;/virtualType&gt; &lt;/config&gt;</pre><p>如果您的商店有多个供应商,请为每个供应商执行上述步骤。</p><p>现在,当上述步骤完成后,创建一个文件,app\code\Vendor\Extension\Ui\DataProvider\Product\Form\Modifier\DefaultQtyModifier.php</p><p>现在,创建文件后,使用以下代码将新产品的自定义默认数量设置为您喜欢的任何数字</p><pre class="brush:bash;toolbar:false">&lt;?php &nbsp; namespace&nbsp;Vendor\Extension\Ui\DataProvider\Product\Form\Modifier; &nbsp; use&nbsp;Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; use&nbsp;Magento\Catalog\Model\Locator\LocatorInterface; &nbsp; class&nbsp;DefaultQtyModifier&nbsp;extends&nbsp;AbstractModifier { &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;__construct( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LocatorInterface&nbsp;$locator &nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;locator&nbsp;=&nbsp;$locator; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;modifyData(array&nbsp;$data) &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$model&nbsp;=&nbsp;$this-&gt;locator-&gt;getProduct(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$modelId&nbsp;=&nbsp;$model-&gt;getId(); &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!isset($data[$modelId][self::DATA_SOURCE_DEFAULT][&#39;quantity_and_stock_status&#39;][&#39;qty&#39;]))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$data[$modelId][self::DATA_SOURCE_DEFAULT][&#39;quantity_and_stock_status&#39;][&#39;qty&#39;]&nbsp;=&nbsp;25; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$data; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;modifyMeta(array&nbsp;$meta) &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$meta; &nbsp;&nbsp;&nbsp;&nbsp;} }</pre><p>在这里,您可以定义自定义数量编号,而不是 25,并且可以为不同的用户组设置不同的自定义数量。对于批发用户,数量可以设置为 50 或 100。</p><p>因此,在本文中,您已经学习了在默认Magento 2.3中创建新产品时如何设置自定义默认数量。使用所描述的代码,您可以将数量设置为您喜欢的任何数字。</p><p><br/></p>