Magento

Magento电子商务平台用户的问答



3
如何在Magento 2中以编程方式添加CMS块?
我需要通过安装/升级脚本添加CMS块。我已经弄清楚了如何添加“普通” CMS页面,如下面的脚本所示。但是,由于我找不到在Magento 2的代码中添加CMS块的任何方法,因此无论是在Google还是在这里,我都很困惑。 namespace [Vendor]\[Module]\Setup; use Magento\Cms\Model\Page; use Magento\Cms\Model\PageFactory; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\UpgradeDataInterface; class UpgradeData implements UpgradeDataInterface { /** * Page factory. * * @var PageFactory */ private $pageFactory; /** * Init. * * @param PageFactory $pageFactory */ public function __construct(PageFactory $pageFactory) { $this->pageFactory = $pageFactory; } /** …

1
Magento2:添加自定义付款方式字段的最佳方法是什么?
我在Magento 2中使用自定义付款方式字段(例如magento / offline-payment-methods中的 “ po_number”)设置了新的付款方式。前端工作得很好(现场显示,验证等)。 但是,如果我要下订单Magento,则WebAPI请求将引发以下错误: “属性\“ CustomField \”在类\“ Magento \ Quote \ Api \ Data \ PaymentInterface \”中没有相应的设置器。 Magento似乎根据定义了诸如getPoNumber和setPoNumber之类的方法的核心支付接口来验证自定义字段。 我已经尝试通过扩展属性添加自定义字段: <extension_attributes for="Magento\Quote\Api\Data\PaymentInterface"> <attribute code="custom_field" type="Vendor\Module\Api\Data\MethodInterface[]" /> </extension_attributes> 并使用以下特定方法创建了接口: <?php namespace Vendor\Module\Api\Data; use Magento\Framework\Api\ExtensibleDataInterface; interface MethodInterface extends ExtensibleDataInterface { public function setCustomField($customField); public function getCustomField(); } 但这是行不通的。Magento仍会根据核心付款界面进行验证。 现在的问题是,如何使Magento接受自定义付款方式字段?任何指针都非常感谢:)


3
Magento 2管理面板将永久挂起,直到页面刷新
自从与Magento 2合作以来,我反复遇到这个烦人的问题: 我登录到管理面板或切换到管理面板中的其他页面 该页面开始加载,有时会部分显示,但随后会永远挂起(至少几分钟),有时会完全显示,但浏览器仍然显示“正在加载”,并且导航无法正常工作,但我看不到失败或正在运行浏览器控制台中的请求。 如果F5在挂起时按下,则页面几乎立即加载(至少在大多数情况下) 它似乎与任何事件都没有关系,因为即使没有在管理面板或代码中进行任何更改,我也只是在导航时得到了此行为。但是,我观察到了与无效缓存的可能关联。 任何想法可能导致此问题吗?我不认为这是权限或Cookie的典型问题,因为通常来说,管理面板是有效的。 Magento在Linux上以开发人员模式运行。

4
取消layout.xml中的块删除过程
我想撤消删除块。 块被删除 vendor/magento/theme-frontend-blank/Magento_Checkout/layout/checkout_index_index.xml <referenceBlock name="minicart" remove="true"/> <referenceContainer name="header.panel" remove="true"/> <referenceBlock name="top.search" remove="true"/> <referenceBlock name="catalog.compare.link" remove="true"/> <referenceBlock name="catalog.topnav" remove="true"/> <referenceContainer name="footer-container" remove="true"/> 根据文档,一个罐头可以用remove=false。 所以我在主题中创建了一个文件 Magento_Checkout/layout/checkout_index_index.xml <referenceBlock name="minicart" remove="false"/> <referenceContainer name="header.panel" remove="false"/> <referenceBlock name="top.search" remove="false"/> <referenceBlock name="catalog.compare.link" remove="false"/> <referenceBlock name="catalog.topnav" remove="false"/> <referenceContainer name="footer-container" remove="false"/> 但这是行不通的。根据这个github问题,这不是错误 编辑: 这也是相关的论坛帖子
13 magento2  layout 

2
如何在magento2中添加bootstrap.js
我想在我的magento2主题中包含bootstrap js。但是问题是当我在主题中包含bootstrap js时。那个时间控制台发出引导需要jQuery的错误。 那我该怎么办呢?谁能帮帮我吗?
13 magento2  jquery 

4
Magento 2:删除块取决于配置设置
我试图从某个页面(前端或后端)中删除一个块,但前提是某个配置标志设置为true。 让我们举个例子。 我想dashboard从管理控制台中删除名称相同的块。 该块adminhtml_dashboard_index.xml在Magento_Backend模块的文件中定义: <referenceContainer name="content"> <block class="Magento\Backend\Block\Dashboard" name="dashboard"/> </referenceContainer> 感谢亚当的回答,我可以在adminhtml_dashboard_index.xml <body> <referenceBlock name="dashboard" remove="true" /> </body> 但是我只想保留一个缺口,并仅在路径的配置设置具有dashboard/settings/remove值的情况下删除此块1。 布局xml方法很棒,但是我也将采用观察者方法。


1
违反完整性约束:1062键“ UNQ_SALES_FLAT_INVOICE_INCREMENT_ID”的重复条目
我正在帮助商家追踪某些付款交易失败(在繁重的订单日期间)的根本原因,该交易失败并出现以下错误 SQLSTATE [23000]:违反完整性约束:1062键“ UNQ_SALES_FLAT_INVOICE_INCREMENT_ID”的条目“ 51986”重复 该UNQ_SALES_FLAT_INVOICE_INCREMENT_ID指数是在一个独特的密钥increment_id在列sales_flat_invoice表。当我在该表中查找increment_id错误(51986)中提到的内容时,我发现其中已经有一张发票increment_id,并且该发票是由另一位客户下的订单。 我与此有关的2个问题 通常在Magento CE 1.9.0.1中的哪个位置创建发票ID? Magento CE 1.9.0.1库存中是否存在已知问题,且几乎同时发生的订单具有冲突的发票ID? 我认识到51986手段的增量ID 商店具有某种扩展名,用于更改已安装的增量ID,但是我想确保在沿这条路径走得太远之前没有已知的科学。

1
Magento 2卸载模块
显然,现在Magento 2支持卸载脚本,该脚本允许在卸载模块时修改数据库架构(敬请期待!)。 如此处所述,这仅适用于通过composer安装的模块。 (我希望将来所有模块都可以使用,但这是一个不同的问题)。 假设我有一个名为的模块Testing_Demo。 该模块执行3件事,我希望在卸载时将其删除。 添加一个名为的表testing_demo。所以我需要删除它。 添加名为的产品属性demo。所以这需要删除 的某些设置system->configuration可能会或可能不会存储在表中core_config_data。所有这些设置都有路径testing_demo/...。因此,这些也需要删除。 我的模块卸载脚本应如何显示?


1
Magento 2的getTable行为
TL; DR: Magento 2中有什么方法可以使getTable资源收集模型中的方法返回两个不同参数的相同表名? 详细说明 我将从Magento 1的示例开始。 假设我有一个名为的表module_entiti1_entity2。 我需要在我宣布这个表config.xml像这样 <module_resource> <class>....</class> <entities> <entity1_entity2> <table>module_entiti1_entity2</table> </entity1_entity2> </entities> </module_resource> 然后,我可以从资源收集模型中获取表名,例如: $collection->getTable('module/entity1_entity2'); 但是,如果我愿意,我可以为同一张表使用多个别名。 如果我的config.xml部分成为 <module_resource> <class>....</class> <entities> <entity1_entity2> <table>module_entiti1_entity2</table> </entity1_entity2> <entity2_entity1> <table>module_entiti1_entity2</table> </entity2_entity1> </entities> </module_resource> 我可以通过两种方式检索表: $collection->getTable('module/entity1_entity2'); $collection->getTable('module/entity2_entity1'); 在Magento 2中,不再像上面那样声明表。 我可以这样获得表名$collection->getTable('module_entity1_entity2')。 有没有办法告诉magento,该参数module_entity2_entity1返回与该参数相同的表名module_entity1_entity2?

4
如何在Magento 2中以编程方式添加客户?
我需要在Magento 2中以编程方式创建一个客户,但是我并没有发现太多文档。基本上,我需要做的就是将以下代码转换为“ Magento 2”: $websiteId = Mage::app()->getWebsite()->getId(); $store = Mage::app()->getStore(); $customer = Mage::getModel("customer/customer"); $customer ->setWebsiteId($websiteId) ->setStore($store) ->setFirstname('John') ->setLastname('Doe') ->setEmail('jd1@ex.com') ->setPassword('somepassword'); try{ $customer->save(); }

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.