Questions tagged «magento2»

有关Magento 2的一般问题,不专门针对次要版本。使用此标签可以区分Magento1。如果您对特定版本有疑问,请改用相应的“ Magento-2.x”标签。Magento 2次要版本之间的功能可能有所不同。


1
覆盖.phtml文件的问题:Magento 2目录模块
问题:尝试覆盖默认的Magento phtml文件,即时消息出错 我需要获取这些信息:( 在页脚,分页器中分页) 我的自定义模块: 1) Vendor/TglsSearch --> Override from Magento CatalogSearch 2) Vendor/Tglcatalog ---> from Magento Catalo 在应用程序\设计\前端\供应商\标签中 更新的代码: 删除以下文件夹 在Magento_Catalog文件夹中: templates\product\list\toolbar.phtml templates\product\list\toolbar\amount.phtml templates\product\list\toolbar\limiter.phtml templates\product\list\toolbar\sorter.phtml templates\product\list\toolbar\viewmode.phtml 这是我在首页上没有结果的空白页: 在块文件中添加了上述代码: 供应商\模块\块\产品\ ListProduct.php class ListProduct extends \Magento\Catalog\Block\Product\ListProduct { public function __construct( /*passing all Constructors parameters to the parent class */ \Magento\Catalog\Block\Product\Context $context, …
8 magento2 

2
在Magento 2中将URL子文件夹用于多语言商店视图
我将Magento 2配置为具有两种商店视图,以便具有两种前端语言(英语和意大利语),并且我希望具有以下行为: http://example.com/ --> Store View "English" (code = "en") - Default http://example.com/it/ --> Store View "Italian" (code = "it") 也就是说,英语商店视图应在标准URL上可用,而意大利商店视图应在URL的“ it”子文件夹中可用。没什么奇怪的,这是多语言网站的通用配置。 我在这里发现了有关Magento 1.x的非常类似的问题:子文件夹中不同的storeview或网站。但是,由于可接受的答案并非易事(涉及的重写.htaccess和的修改index.php),我想问一下Magento 2是否有更简单的方法来完成此任务? 更新 前提:我不介意拥有多个网站,所以我不存在使用相同语言的多个网站的问题(以下解决方案会出现问题)。 因此,我Add Store Code to Urls从Configuration> Web> Url> Add Store Code to Urls中启用了该选项,它运行良好。但是现在我已经为默认语言(英语)重复了网址: http://example.com/ --> Store View "English" (code = "en") http://example.com/en/ --> Store …

2
Magento 2不支持在特征中进行依赖注入?
特质实际上与Magento中的依赖注入一起工作吗?考虑以下代码: 特质班 namespace Frame\Slick\Block; use Frame\Slider\Slick\Block\Data as Helper trait Slick { protected $_slickHelper; public function __construct(Helper $slickHelper) { $this->_slickHelper = $slickHelper; } } 使用特征类 namespace Frame\Slick\Block; class Product ListProduct implements BlockInterface { use Slick; public function testTrait() { return $this->_slickHelper->getHelloWorld(); } } 这似乎总是返回null,非常确定是否正确包含了所有内容。特质真的可以支持依赖注入吗? 编辑:例如,如果您在trait构造函数中执行di并将其分配给trait变量,然后在使用trait的类上对其进行调用,则它将始终返回null。其他都可以。
8 magento2  php  di 

1
关于Magento2后端表单按钮“保存”,“保存并继续”
要通过ui_component创建后端表单,我在配置文件中定义以下内容以显示按钮save和saveAndContinue Button <item name="buttons" xsi:type="array"> <item name="save" xsi:type="string">namespace\module\Block\Adminhtml\Edit\SaveButton</item> <item name="save_and_continue" xsi:type="string">namespace\module\Block\Adminhtml\Edit\SaveAndContinueButton</item> </item> 分别创建了两个文件SaveButton.php和SaveAndContinueButton.php,并且都实现了ButtonProviderInterface 据我所知,按钮主要是从getButtonData函数渲染的。看到SaveAndContinueButton.php public function getButtonData() { $TodoItemId = $this->getTodoItemId(); $data = []; if ($TodoItemId) { $data = [ 'label' => __('Save and Continue Edit'), 'class' => 'save', 'data_attribute' => [ 'mage-init' => [ 'button' => ['event' => 'saveAndContinueEdit'], …



1
adminhtml表单ui_component字段未填充
我创建了一个表单ui_component实例。字段已呈现但未填充。即使呈现的JSON包含数据,也不会显示。 我究竟做错了什么?什么是有效的调试步骤? 这就是我所拥有的。为了进行测试,我使实体变得非常小(两个字段:foo_id和name)。 ui_component XML: <?xml version="1.0" encoding="UTF-8"?> <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> <argument name="data" xsi:type="array"> <item name="js_config" xsi:type="array"> <item name="provider" xsi:type="string">example_foo_form.example_foo_form_data_source</item> <item name="deps" xsi:type="string">example_foo_form.example_foo_form_data_source</item> </item> <item name="config" xsi:type="array"> <item name="dataScope" xsi:type="string">data</item> <item name="namespace" xsi:type="string">example_foo_form</item> </item> <item name="label" xsi:type="string" translate="true">Foo Information</item> <item name="layout" xsi:type="array"> <item name="type" xsi:type="string">tabs</item> <item name="navContainerName" xsi:type="string">left</item> </item> <item …

2
Magento 2:虚拟类型插件
Magento 2关于插件的文档让我感到困惑: 首先要说的是: 插件不能与虚拟类型一起使用 但后来说: 您可以将类,接口或虚拟类型指定为插件观察到的类型名称 我是否缺少某些内容,或者文档是否相互矛盾?我们可以为虚拟类型创建插件吗?

6
尝试访问Magento 2中的“自定义”模块时出现“ 404页面未找到”错误
我在供应商文件夹中创建了2个自定义模块。这是我的布局结构: -app -code -Company -Blog -HelloWorld -Controller -Hello -World.php -registration.php -etc -module.xml -frontend -routes.xml 两者都启用。 这是我routes.xml的HelloWorld模块代码: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="standard"> <route id="helloworld" frontName="helloworld"> <module name="Company_HelloWorld"/> </route> </router> </config> 这是我的代码module.xml: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Company_HelloWorld" setup_version="1.0.0"> </module> </config> 这是我的registration.php文件: <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Company_HelloWorld', __DIR__ ); 这是我的控制器代码: …

2
如何模拟上下文对象
我正在尝试测试包含上下文对象的模块,如下所示: public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Catalog\Model\Product\ImageFactory $productImageFactory, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\View\ConfigInterface $viewConfig, ProductRepository $productRepo ) { parent::__construct($context, $productImageFactory, $assetRepo, $viewConfig); $this->productRepo = $productRepo; } 当我运行单元测试时,它会显示以下错误消息: PHPUnit_Framework_Error : Argument 1 passed to Magento\Catalog\Model\Product::__construct() must be an instance of Magento\Framework\Model\Context, none given, called in ... 如何模拟该对象或解决此错误?

1
ObjectManager工厂的区别是什么?
我看到Magento 2有3个工厂类(如果算上抽象的,则有4个工厂类)。 \ Magento \ Framework \ ObjectManager \ Factory \ Dynamic \ Developer \ Magento \ Framework \ ObjectManager \ Factory \ Dynamic \ Production \ Magento \ Framework \ ObjectManager \ Factory \ Compiled 以上所有扩展\Magento\Framework\ObjectManager\Factory\AbstractFactory。 我以为在开发人员模式下Developer将使用工厂,但有时会使用工厂,而Compiled我无法为此确定条件。 有人可以解释使用每个工厂的时间以及它们之间的区别吗?

1
什么时候schema_version和数据版本会不同?
例如,我的模块中没有安装脚本,我可以忽略文件中的setup_version标记吗module.xml? 在m1自动安装的模块中,现在首先抛出一个错误(如果我们不运行setup upgrade命令)。为什么我需要手动运行安装程序升级? 什么是场景schema_version和data_version会有所不同? 我观察到setup_module表中几乎所有记录都包含相同的值。


3
我的magento管理仪表板登录URL是什么
我最近在网络上安装了magento,不记得登录了 这些链接不起作用并抛出 糟糕,我们的问题... 找不到您要求的页面,我们很好地猜测原因。 如果您直接输入网址,请确保拼写正确。 如果单击链接以到达此处,则该链接已过期。 http:// localhost:8888 / Magento / admin http:// localhost:8888 / Magento / index.php / admin http:// localhost:8888 / Magento / administrator http:// localhost:8888 / Magento / index.php / administrator 我在Mac优胜美地上使用MAMP,并且在app / etc中没有local.xml,但是是的di.xml在那里。提前致谢

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.