标签: magento2

如何从magento 2中的文件夹和子文件夹中获取所有文件

我制作了一个用于在前端上传图像的模块。Magento 2 以一种特殊的方式保存文件。例如:

  • 上传文件- file.png,
  • 文件路径- pub/media/[module_folder]/f/i/file.png.

如何获取所有文件[module_folder]

在此输入图像描述

filesystems getfiles magento2

5
推荐指数
1
解决办法
5942
查看次数

Magento 2 - 将产品添加到购物车时直接进入结帐页面

我正在编写一个扩展,当单击产品页面上的“添加到购物车”按钮时,可以直接进入结帐页面。我在这里找到了 Magento 1 的解决方案,并尝试将其适应 Magento 2。这是我的文件:

文件etc/frontend/events.xml:

<?xml version="1.0" encoding="utf-8" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_cart_add_product_complete">
        <observer
            name="mycompany_go_to_checkout"
            instance="MyCompany\GoToCheckout\Observer\GoToCheckout" />
    </event>
</config>
Run Code Online (Sandbox Code Playgroud)

文件观察者/GoToCheckout.php:

namespace MyCompany\GoToCheckout\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class GoToCheckout implements ObserverInterface
{
    protected $_url;

    public function execute(Observer $observer)
    {
        $urlInterface = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\UrlInterface');
        $url = $urlInterface->getUrl('checkout');
        $observer->getControllerAction()->getResponse()->setRedirect($url);
    }
}
Run Code Online (Sandbox Code Playgroud)

我应该更改或添加什么才能使其正常工作?

任何指导将不胜感激。

magento magento2 magento-2.0

5
推荐指数
1
解决办法
8777
查看次数

Magento 2:Less :extend() 不添加 mixin

我遇到了一个问题,我试图.lib-clearfix()通过使用扩展来申请一个类。问题是扩展本身确实有效,但扩展不会应用混入。相关文件和css如下:

{主题路径}/web/css/source/ _sources.less

@import '_variables.less';
@import (reference) '_extends.less';
@import '_typography.less';
@import '_layout.less';
Run Code Online (Sandbox Code Playgroud)

{主题路径}/web/css/source/ _extends.less

@abs-add-clearfix: {
    .lib-clearfix();
};

.abs-add-clearfix {
    @abs-add-clearfix();
}
Run Code Online (Sandbox Code Playgroud)

lib/web/css/source/lib/ _utilities.less

.lib-clearfix() {
    &:before,
    &:after {
        content: '';
        display: table;
    }
    &:after {
        clear: both;
    }
}
Run Code Online (Sandbox Code Playgroud)

{theme-path}/{Module}/web/css/source/ _module.css

& when (@media-common = true) {
  .header.panel:extend(.abs-add-clearfix) {
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

.header.panel,正如所写的那样不呈现.lib-clearfix()样式。但是,如果在_module.less我更改header.panel为-

.header.panel {
  .lib-clearfix();
}
Run Code Online (Sandbox Code Playgroud)

-- 它按预期工作;应用了 clearfix 样式。为了测试扩展是否被解析,我更改@abs-add-clearfix并恢复了.header.panelcss。

较少的

@abs-add-clearfix: {
  color: blue; …
Run Code Online (Sandbox Code Playgroud)

css magento less magento2

5
推荐指数
0
解决办法
1453
查看次数

Magento 2 - 管理网格向集合添加过滤器

我通过 XML UI 组件在 admin 中创建了一个网格。

我需要通过 URL 参数过滤集合,但我不知道如何实现。我尝试将 RequestInterface 注入集合,但过滤器不起作用。

di.xml

<virtualType name="SlideListingDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
    <arguments>
        <argument name="collection" xsi:type="object" shared="false">xxx\xxx\Model\ResourceModel\Grid\Slide\Collection</argument>
        <argument name="filterPool" xsi:type="object" shared="false">SlideListingFilterPool</argument> <!-- Define new object for filters -->
    </arguments>
</virtualType>
<virtualType name="SlideListingFilterPool" type="Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool">
    <arguments>
        <argument name="appliers" xsi:type="array">
            <item name="regular" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter</item>
            <item name="fulltext" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter</item>
        </argument>
    </arguments>
</virtualType>
<virtualType name="xxx\xxx\Model\ResourceModel\Grid\Slide\Collection" type="xxx\xxx\Ui\Component\DataProvider\SearchResult\Slide">
    <arguments>
        <argument name="mainTable" xsi:type="string">advox_sliders_slide</argument>
        <argument name="resourceModel" xsi:type="string">xxx\xxx\Model\ResourceModel\Slide</argument>
    </arguments>
</virtualType>
Run Code Online (Sandbox Code Playgroud)

collections filter magento2

5
推荐指数
1
解决办法
3018
查看次数

Magento 2:主页上评价最高的产品

如何在主页 magento 2 中获得最受好评的产品?

我们必须在 Magento 2 的主页中显示评分最高的产品列表。

magento2

5
推荐指数
1
解决办法
563
查看次数

如何设置 Magento 2 网站切换器?

我想使用网站 URL 为多个网站 magento2 商店设置网站功能。还想从网站切换器下拉列表中选择当前网站 ID。

magento2

5
推荐指数
1
解决办法
6540
查看次数

无法获取“frontend/Magento/blank/en_US/css/source/lib/_lib.less”的内容

当我使用 编译 static 时php bin/magento setup:static-content:deploy,出现以下错误:

无法获取“frontend/Magento/blank/en_US/css/source/lib/_lib.less”的内容

无法获取“frontend/Magento/luma/en_US/css/source/lib/_lib.less”的内容

magento2

5
推荐指数
1
解决办法
5684
查看次数

在商店视图中设置允许的国家/地区

在 Magento 1.4 中,我能够设置allowed countries级别Store View,因此我可以为每个国家/地区 设置Website一个 1Store和多个:Store Views在此输入图像描述

现在在 Magento 2 中,我只能Allowed Countries在 上设置Website,而不能在 上设置Store ViewStore View设置如下: 在此输入图像描述

我为什么要改变这一点?我需要能够设置不同的store contact address为每个设置不同的Store View地址,因为我有一个 Argentinien 和一个 Bulgarian Store View,所以我想设置不同的地址但使用相同的Website/ Store

不幸的是,我也无法改变Store Contact Addressper Store View,这也仅适用于Website关卡。

我错过了什么吗?从 1.X 到 2.X 是否存在逻辑变化Store Views

online-store magento2

5
推荐指数
1
解决办法
2250
查看次数

Stream_context_create 的 https

我是这样尝试的新手,我试图在 magento2 中使用 https 获取令牌,它在这里不起作用我的代码

<?php
$base_url="https://myurl.com/";
$domain="myurl.com";
$url = $base_url.'index.php/rest/V1/integration/admin/token';
$body = '{"username":"ApiUser", "password":"ApiPass"}';

$context_options = array (
        'https' => array (
            'method' => 'POST',
            'header'=> "Content-type: application/json"
            'content' => $body
            ),
        'ssl' => array('SNI_enabled'=>true,'SNI_server_name'=> $domain)
        );

$context = stream_context_create($context_options);
$token = json_decode(file_get_contents($url, false, $context));
echo $token; echo "<br/>";
?>
Run Code Online (Sandbox Code Playgroud)

请帮忙,提前致谢。

php api magento2

5
推荐指数
1
解决办法
1万
查看次数

使用客户令牌获取订单列表 - Magento 2 Rest Api

我正在尝试使用以下网址获取订单列表,

GET METHOD - http://magento.local/index.php/rest/V1/orders?searchCriteria
Header: Authorization: Bearer TOKEN(Customer Token)
Run Code Online (Sandbox Code Playgroud)

但它给出了以下响应,

{
    "message": "Consumer is not authorized to access %resources",
    "parameters": {
        "resources": "Magento_Sales::sales"
    }
}
Run Code Online (Sandbox Code Playgroud)

使用客户令牌获取订单列表需要做什么?

php magento magento2

5
推荐指数
1
解决办法
4424
查看次数