<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中通过配置设置cron时间的步骤:</p><p>步骤1:首先您需要在 以下路径中添加crontab.xml</p><p>app\code\Vendor\Extension\etc\crontab.xml</p><pre class="brush:bash;toolbar:false"><?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd"> <group id="default"> <job instance="Vendor\Extension\Cron\Cronfile" method="execute" name="my_cron_job"> <config_path>crontab/default/jobs/my_cron_job/schedule/cron_expr</ </job> </group> </config></pre><p>步骤2: 需要在系统上添加新组.xml路径如下</p><p>app\code\Vendor\Extension\etc\adminhtml\system.xml</p><pre class="brush:bash;toolbar:false"><group id="configurable_cron" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Cron Settings</label> <field id="frequency" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0"> <label>Frequency</label> <source_model>Magento\Cron\Model\Config\Source\Frequency</source_model> <backend_model>Vendor\Extension\Model\Config\Cronconfig</backend_model> </field> <field id="time" translate="label comment" sortOrder="2" type="time" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Start Time</label> </field> </group></pre><p>第 3 步:现在在 以下路径中添加 Cronconfig.php</p><p>app\code\Vendor\Extension\Model\Config\Cronconfig.php</p><pre class="brush:bash;toolbar:false"><?php namespace Vendor\Extension\Model\Config; class Cronconfig extends \Magento\Framework\App\Config\Value { const CRON_STRING_PATH = 'crontab/default/jobs/my_cron_job/schedule/cron_expr'; const CRON_MODEL_PATH = 'crontab/default/jobs/my_cron_job/run/model'; /** * @var \Magento\Framework\App\Config\ValueFactory */ protected $_configValueFactory; /** * @var mixed|string */ protected $_runModelPath = ''; /** * CronConfig1 constructor. * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList * @param \Magento\Framework\App\Config\ValueFactory $configValueFactory * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param string $runModelPath * @param array $data */ public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\App\Config\ValueFactory $configValueFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, $runModelPath = '', array $data = []) { $this->_runModelPath = $runModelPath; $this->_configValueFactory = $configValueFactory; parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); } /** * @return CronConfig1 * @throws \Exception */ public function afterSave() { $time = $this->getData('groups/configurable_cron/fields/time/value'); $frequency = $this->getData('groups/configurable_cron/fields/frequency/value'); $cronExprArray = [ intval($time[1]), intval($time[0]), $frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY ? '1' : '*', '*', $frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY ? '1' : '*', ]; $cronExprString = join(' ', $cronExprArray); try { $this->_configValueFactory->create()->load( self::CRON_STRING_PATH, 'path' )->setValue( $cronExprString )->setPath( self::CRON_STRING_PATH )->save(); $this->_configValueFactory->create()->load( self::CRON_MODEL_PATH, 'path' )->setValue( $this->_runModelPath )->setPath( self::CRON_MODEL_PATH )->save(); } catch (\Exception $e) { throw new \Exception(__('Some Thing Want Wrong , We can\'t save the cron expression.')); } return parent::afterSave(); } }</pre><p>步骤4:现在在 以下路径中添加Cronfile.php</p><p>app\code\Vendor\Extension\Cron\Cronfile.php</p><pre class="brush:bash;toolbar:false"><?php namespace Vendor\Extension\Cron; class Cronfile { public function execute() { //Add your cron code. } }</pre><p>结论:</p><p>因此,现在所有人都可以通过Magento 2中的配置设置Cron Time。</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:首先,我们需要在扩展名中创建一个sales_order_grid.xml文件,路径如下</p><p>app\code\Vendor\Extension\view\adminhtml\ui_component\</p><p>并添加如下所述的代码</p><pre class="brush:bash;toolbar:false"><?xml version="1.0" encoding="UTF-8"?> <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> <columns name="sales_order_columns"> <settings> <childDefaults> <param name="fieldAction" xsi:type="array"> <item name="provider" xsi:type="string">false</item> </param> </childDefaults> </settings> <column name="street"> <settings> <filter>text</filter> <label translate="true">Street</label> <bodyTmpl>ui/grid/cells/html</bodyTmpl> <visible>true</visible> </settings> </column> <column name="postcode"> <settings> <filter>text</filter> <label translate="true">Zip</label> <bodyTmpl>ui/grid/cells/html</bodyTmpl> <visible>true</visible> </settings> </column> <column name="city"> <settings> <filter>text</filter> <label translate="true">City</label> <bodyTmpl>ui/grid/cells/html</bodyTmpl> <visible>true</visible> </settings> </column> <column name="telephone"> <settings> <filter>text</filter> <label translate="true">Phone</label> <bodyTmpl>ui/grid/cells/html</bodyTmpl> <visible>true</visible> </settings> </column> </columns> </listing></pre><p>步骤2: 之后,我们需要在扩展文件夹中的以下给定路径中创建一个di.xml文件:</p><p>app\code\Vendor\Extension\etc\</p><p>现在,添加以下代码</p><pre class="brush:bash;toolbar:false"><?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory"> <plugin name="custom_orders_grid" type="Vendor\Extension\Plugin\OrdersGrid" sortOrder="10"/> </type> </config></pre><p>步骤3:之后,我们需要在下面的路径文件夹中创建OrdersGrid.php文件,以将文件添加到模块中。</p><p>app\code\Vendor\Extension\Plugin\</p><p>现在,添加以下代码</p><pre class="brush:bash;toolbar:false"><?php namespace Vendor\Extension\Plugin; class OrdersGrid { public function afterGetReport($subject, $collection, $requestName) { if ($requestName !== 'sales_order_grid_data_source') { return $collection; } if ($collection->getMainTable() === $collection->getResource()->getTable('sales_order_grid')) { $orderAddressTable = $collection->getResource()->getTable('sales_order_address'); $collection->getSelect()->joinLeft( ['oat' => $orderAddressTable], 'oat.parent_id = main_table.entity_id AND oat.address_type = \'shipping\'', ['telephone', 'city', 'postcode', 'street'] ); } return $collection; } }</pre><p>完成上述步骤后,请在Magento 2商店后端中检查结果。送货地址详细信息列,如街道,邮政编码,城市,电话已添加到Magento 2的订单网格中。</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>步骤1:首先,您需要从Magento管理面板添加自定义变量值</p><p>在“管理”边栏上,转到“系统>其他设置”>“自定义变量”。</p><p>单击添加新变量并填写详细信息。</p><p>步骤2:现在您需要在我们的代码中访问或获取自定义变量值,因此我们需要在以下路径中添加一个帮助程序文件。</p><p>app\code\Vendor\Extension\Helper\Data.php</p><pre class="brush:bash;toolbar:false"><?php namespace Vendor\Extension\Helper; class Data extends \Magento\Framework\App\Helper\AbstractHelper { protected $variable public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Variable\Model\Variable $variable ) { $this->variable = $variable; parent::__construct($context); } public function getCustomVarible() { $variableData = $this->variable->loadByCode('test', 'base'); // Here first parameter is custom-variable-code and second one is store-code return $variableData->getPlainValue(); } }</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:您可以在媒体库所在的 phtml 文件中编写此代码。在这里,我们在以下路径中添加了代码。</p><p>app\design\frontend\Themes\Yourtheme\Vendor_Extension\templates\test.phtml</p><p>并添加以下代码</p><pre class="brush:bash;toolbar:false"><div class="gallery-placeholder _block-content-loading whatwedo-image" data-gallery-role="gallery-placeholder"> <img alt="main product photo" class="gallery-placeholder__image" src=”<image-path>” /> </div> <script type="text/x-magento-init"> { ".whatwedo-image": { "mage/gallery/gallery": { "data": [{ "thumb": "<media_url>/1.png", "img": "<media_url>/2.png", "full": "<media_url>/3.png", "caption": "Media Check", "isMain": "false" }], "mixins": ["magnifier/magnify"], "magnifierOpts": { "enabled": true, "eventType": "hover", // you can use Either click or hover "width": 10, // You can write anything "height": 20, // You can write anything "top": 10, // You can write anything "left": 20, // You can write anything "fullscreenzoom": 50, // You can write anything "mode": "outside" // You can write inside / outside } } } } </script></pre><p>步骤2:从视图中启用放大镜.xml,移动到下面的路径</p><p>app\design\frontend\themees\yourtheme\etc\view.xml</p><p>并添加以下代码</p><pre class="brush:bash;toolbar:false"><var name="magnifier"> <var name="enabled">true</var> <!-- Turn on/off magnifier (true/false) --> </var></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步: 首先,我们需要在扩展名中以以下路径创建一个“默认.xml”文件。</p><p>app\code\Vendor\Extension\view\frontend\layout\</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> <referenceContainer name="header-wrapper"> <referenceBlock name="minicart"> <arguments> <argument name="jsLayout" xsi:type="array"> <item name="components" xsi:type="array"> <item name="minicart_content" xsi:type="array"> <item name="config" xsi:type="array"> <item name="template" xsi:type="string">Vendor_Extension/minicart/content</item> </item> </item> </item> </argument> </arguments> </referenceBlock> </referenceContainer> </body> </page></pre><p>第2步:之后,我们需要在扩展名中在以下路径创建一个“requirejs-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/minicart': { 'Vendor_Extension/js/view/minicart-mixin': true } } } };</pre><p>第 3 步:之后,我们需要 在下面的路径中创建一个“minicart-mixin.js”文件</p><p>app\code\Vendor\Extension\view\frontend\web\js\view\</p><p>然后,添加下面提到的代码</p><p></p><pre class="brush:bash;toolbar:false">define([ 'uiComponent', 'Magento_Customer/js/customer-data', 'jquery', 'ko', 'underscore', 'sidebar', 'mage/translate', 'mage/dropdown' ], function (Component, customerData, $, ko, _) { 'use strict'; var mixin = { isButtonEnable: function () { /* you need to add your custom code here */ return true; } }; return function (target) { return target.extend(mixin); }; });</pre><p>步骤4:之后,我们需要 在以下路径内创建一个“content.html”文件</p><p>app\code\Vendor\Extension\view\frontend\web\template\minicart\</p><p>之后,包括如下代码</p><pre class="brush:bash;toolbar:false"><div class="block-title"> <strong> <span class="text" translate="'My Cart'"/> <span class="qty empty" text="getCartParam('summary_count')" data-bind="css: { empty: !!getCartParam('summary_count') == false }, attr: { title: $t('Items in Cart') }"> </span> </strong> </div> <div class="block-content"> <button type="button" id="btn-minicart-close" class="action close" data-action="close" data-bind="attr: { title: $t('Close') }"> <span translate="'Close'"/> </button> <if args="getCartParam('summary_count')"> <div class="items-total"> <span class="count" if="maxItemsToDisplay < getCartLineItemsCount()" text="maxItemsToDisplay"/> <translate args="'of'" if="maxItemsToDisplay < getCartLineItemsCount()"/> <span class="count" text="getCartParam('summary_count')"/> <!-- ko if: (getCartLineItemsCount() === 1) --> <span translate="'Item in Cart'"/> <!--/ko--> <!-- ko if: (getCartLineItemsCount() > 1) --> <span translate="'Items in Cart'"/> <!--/ko--> </div> <each args="getRegion('subtotalContainer')" render=""/> <each args="getRegion('extraInfo')" render=""/> <if args="isButtonEnable()"> <div class="actions"> <div class="primary"> <button type="button" class="action primary checkout custombutton" data-action="close" translate="'Send Quote'"/> </div> </div> </if> <div class="actions" if="getCartParam('possible_onepage_checkout')"> <div class="primary"> <button id="top-cart-btn-checkout" type="button" class="action primary checkout" data-action="close" data-bind=" attr: { title: $t('Proceed to Checkout') }, click: closeMinicart() " translate="'Proceed to Checkout'" /> <div data-bind="html: getCartParam('extra_actions')"></div> </div> </div> </if> <if args="getCartParam('summary_count')"> <strong class="subtitle" translate="'Recently added item(s)'"/> <div data-action="scroll" class="minicart-items-wrapper"> <ol id="mini-cart" class="minicart-items" data-bind="foreach: { data: getCartItems(), as: 'item' }"> <each args="$parent.getRegion($parent.getItemRenderer(item.product_type))" render="{name: getTemplate(), data: item, afterRender: function() {$parents[1].initSidebar()}}" /> </ol> </div> </if> <ifnot args="getCartParam('summary_count')"> <strong class="subtitle empty" data-bind="visible: closeSidebar()" translate="'You have no items in your shopping cart.'" /> <if args="getCartParam('cart_empty_message')"> <p class="minicart empty text" text="getCartParam('cart_empty_message')"/> <div class="actions"> <div class="secondary"> <a class="action viewcart" data-bind="attr: {href: shoppingCartUrl}"> <span translate="'View and Edit Cart'"/> </a> </div> </div> </if> </ifnot> <div class="actions" if="getCartParam('summary_count')"> <div class="secondary"> <a class="action viewcart" data-bind="attr: {href: shoppingCartUrl}"> <span translate="'View and Edit Cart'"/> </a> </div> </div> <div id="minicart-widgets" class="minicart-widgets" if="getRegion('promotion').length"> <each args="getRegion('promotion')" render=""/> </div> </div> <each args="getRegion('sign-in-popup')" render=""/></pre><p>步骤5:最后,添加代码后,您需要运行Magento升级和部署命令。</p><p>实施上述步骤后,您的自定义按钮将成功添加到Magento 2商店的迷你购物车中。</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>步骤 1:移动到以下路径</p><p>app\code\Vendor\Extension\Controller\Index\Custom.php</p><p>并且,添加此代码</p><pre class="brush:bash;toolbar:false"><?php namespace Vendor\Extension\Controller\Index; class Custom extends \Magento\Framework\App\Action\Action { protected $_customerSession; protected $_customerUrl; public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Customer\Model\Url $customerUrl ) { $this->_customerSession = $customerSession; $this->_customerUrl = $customerUrl; parent::__construct($context); } public function isCustomerLogin() { return $this->_customerSession->isLoggedIn(); } public function getCustomerLoginUrl() { return $this->_customerUrl->getLoginUrl(); } }</pre><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><span style="color: #6a9955;">### 什么是Magento 2缓存?</span></p><p>收集,合并和保存所有模块配置的过程由Magento 2在缓存中完成。存储在文件和数据库中的特定于存储的设置包含在Magento 2缓存中。</p><p>为了从缓存中清除过时的元素,您可以清理或刷新缓存,如下所述:</p><p><span style="color: #6a9955;">### Magento 2缓存清理和缓存刷新</span></p><p>Magento缓存清理会删除所有已启用的Magento相关缓存。干净的缓存不会清理服务器中与Magento无关的其他部分。</p><p>Magento缓存刷新清理缓存存储。它将影响存储的其他部分,这些部分是同一存储的一部分。</p><p>Magento 2缓存清理和缓存刷新之间的区别</p><p>缓存清理不会删除存储在缓存中没有正确标记的项目。</p><p>如果缓存清理未反映前端的更改,请刷新缓存。</p><p>刷新缓存会从同一缓存存储中清除每个项目。因此,如果多个Magento实例使用相同的缓存存储,或者如果与缓存相同的数据库用于存储会话,则也会被删除。</p><p><span style="color: #6a9955;">### 用于缓存清理和缓存刷新的命令</span></p><p>对于缓存清理,请运行以下命令:</p><p>php bin/magento cache:clean</p><p>对于缓存刷新,请运行以下命令:</p><p>php bin/magento cache:flush</p><p><span style="color: #6a9955;">### 从Magento 2管理员缓存清理和缓存刷新</span></p><p>步骤1:登录到Magento 2管理面板,然后转到系统>缓存管理。</p><p>步骤2: 然后,对于缓存清理,单击刷新Magento缓存。同样,对于缓存刷新,请单击刷新缓存存储。</p><p>因此,Magento 2中的缓存清理和缓存刷新之间的主要区别在于,cache:clean将擦除所有与Magento相关的已启用项目,而cache:flush将清除缓存存储。</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 步:InstallData.php在给定的以下路径</p><p>app\code\Vendor\Extension\Setup\InstallData.php</p><p>添加以下代码</p><pre class="brush:bash;toolbar:false"><?php namespace Vendor\Extension\Setup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Catalog\Model\Product; use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface; class InstallData implements InstallDataInterface { private $eavSetupFactory; public function __construct(EavSetupFactory $eavSetupFactory) { $this->eavSetupFactory = $eavSetupFactory; } public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); $eavSetup->addAttribute( Product::ENTITY, 'attribute_code', [ 'type' => 'text', 'backend' => '', 'frontend' => '', 'group' => 'General', 'label' => 'Attribute Label', 'input' => 'text', 'frontend_class' => 'validate-greater-than-zero validate-digits', 'class' => '', 'source' => '', 'sort_order' => 100, 'global' => ScopedAttributeInterface::SCOPE_STORE, 'visible' => true, 'required' => false, 'user_defined' => false, 'default' => '', 'searchable' => false, 'adminhtml_only' => true, 'filterable' => true, 'comparable' => true, 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true, 'visible_on_front' => false, 'used_in_product_listing' => true, 'unique' => false, 'apply_to' => '' ] ); } }</pre><p>第 2 步: 在以下路径创建 di.xml</p><p>app\code\Vendor\Extension\etc\di.xml</p><p>现在,添加以下代码</p><pre class="brush:bash;toolbar:false"><?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\Ui\DataProvider\CatalogEavValidationRules"> <plugin name="vendor_custom_validation_for_extension_product_attribute" type="Vendor\Extension\Plugin\Product\Validationrules"/> </type> </config></pre><p>步骤 3:创建验证规则.php路径如下</p><p>app\code\Vendor\Extension\Plugin\Product\Validationrules.php</p><p>并且,按如下方式添加代码</p><pre class="brush:bash;toolbar:false"><?php namespace Vendor\Extension\Plugin\Product; use Magento\Catalog\Ui\DataProvider\CatalogEavValidationRules; use Closure; use Magento\Catalog\Api\Data\ProductAttributeInterface; class Validationrules { public function aroundBuild( CatalogEavValidationRules $rulesObject, Closure $proceed, ProductAttributeInterface $attribute, array $data ){ $rules = $proceed($attribute,$data); if($attribute->getAttributeCode() == 'attribute_code'){ //custom filter $validationClasses = explode(' ', $attribute->getFrontendClass()); foreach ($validationClasses as $class) { $rules[$class] = true; } } return $rules; } }</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中订单PDF中的订单总块添加新字段的步骤:</p><p>让我们举个例子,我添加了ABC TAX。</p><p>步骤 1:移动到以下路径</p><p>app\code\Vendor\Extension\etc\pdf.xml</p><p>现在添加代码,如下所示</p><pre class="brush:bash;toolbar:false"><?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/pdf_file.xsd"> <totals> <total name="abc"> <title translate="true">ABC TAX</title> <source_field>abc_tax</source_field> // it’s Your Database Field Name <display_zero>false</display_zero> // If your column has 0 Value then it will not display in Frontend <sort_order>550</sort_order> // it will decide where you want to display your field in total block , for e.g after sub total, before grand total etc. <font_size>7</font_size> // to give font size. <model>Class_Name</model> // to customize the value you can use model class. </total> <amount_prefix>hello</amount_prefix> // you cann add profiex before amount </totals> </config></pre><p>不过,如果你想了解更多的理解和定制,你需要了解Magento核心文件。这是路径,</p><p>vendor\Magento\Sales\Model\Order\Pdf\Config\Converter.php</p><p>要查看更多标签,您需要查看以下文件</p><p>vendor\magento\module-sales\etc\pdf_files.xsd</p><p>结论:</p><p>因此,通过这种方式,您可以在Magento 2中的订单PDF中的订单总块处添加新字段。</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中使用ViewModels的步骤:</p><p>步骤 1:移动到以下路径</p><p>app\code\Vendor\Extension\view\frontend\layout\custom_layout.xml</p><p>并添加代码如下</p><pre class="brush:bash;toolbar:false"><block name="custom.block" template="Vendor_Module::custom.phtml"> <arguments> <argument name="viewModel" xsi:type="object">Vendor\Extension\ViewModel\Custom</argument> </arguments> </block></pre><p>步骤2:现在,导航到以下路径</p><p>app\code\Vendor\Extension\ViewModel\Custom.php</p><p>并添加下面提到的代码</p><pre class="brush:bash;toolbar:false"><?php namespace Vendor\Extension\ViewModel; use Magento\Framework\View\Element\Block\ArgumentInterface; class Custom implements ArgumentInterface { public function getSomething() { return "Hello World"; } }</pre><p>步骤3:最后,移至以下路径</p><p>app\code\Vendor\Extension\view\frontend\templates\Custom.phtml</p><p>并添加以下代码</p><pre class="brush:bash;toolbar:false"><?php $viewModel = $block->getViewModel(); echo $viewModel->getSomething(); ?></pre><p>结论:</p><p>通过这种方式,您可以在Magento 2中使用ViewModels。</p><p><br/></p>