标签: magento2

Magento2; 通过 REST API 更新库存

我已经使用示例数据设置了本地 Magento 2.1.2 环境。我正在尝试通过 REST api(catalogInventoryStockRegistryV1 - Put)找到更新股票的正确代码。

这是我到目前为止所得到的:

<?php

$adminUrl = 'http://www.localurl.pro/rest/V1/integration/admin/token/';
$ch = curl_init();
$data = array("username" => "admin", "password" => "66sRz97CZt7N[GdqFU");

$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string))
);
$token = curl_exec($ch);
$token=  json_decode($token);

$headers = array("Authorization: Bearer $token");

$requestUrl='http://www.localurl.pro/rest/V1/products/24-MB01/stockItems/1';
// Sample SKU

$sampleProductData = array(
        "qty" => 100
);
$productData = json_encode(array('stockItem' => $sampleProductData));
// Prints: {"stockItem":{"qty":100}}

$ch = …
Run Code Online (Sandbox Code Playgroud)

api rest stock magento2

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

Android:Magento 2电子商务网站不在android Webview中工作

当我试图在Android中加载Magento 2 电子商务网站时WebView,我收到以下错误消息:

"无法发送cookie.将超出最大cookie数量."

这个错误的原因是什么?我怎样才能解决这个问题.?任何人都可以帮助我吗?

Android代码

WebView webView=(WebView) findViewById(R.id.disp);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setAppCacheEnabled(false);
        webView.getSettings().setAllowContentAccess(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.setWebViewClient(new MyViewClient());
        try {
            webView.loadUrl("https://sweetroomksa.com/");
        }catch (Exception e){


        }
Run Code Online (Sandbox Code Playgroud)

android webview magento2

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

Magento 2 自定义模块和 Web 服务返回空白数组

我是 magento 2x 的新手。但是,我尝试创建一个自定义模块和一个网络服务来检查客户电子邮件是否存在。但结果我得到的只是一个空白数组。这是我到目前为止所做的:

1. app/code/Test/Customers/registration.php

\Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::MODULE,
        'Test_Customers',
        __DIR__
    );
Run Code Online (Sandbox Code Playgroud)

2. app/code/Test/Customers/etc/module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"><module name="Test_Customers" setup_version="1.0.0"></module></config>
Run Code Online (Sandbox Code Playgroud)

3. app/code/Test/Customers/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"><preference for="Test\Customers\Api\AccountInterface" type="Test\Customers\Model\Account"/></config>
Run Code Online (Sandbox Code Playgroud)

4. app/code/Test/Customers/etc/webapi.xml

<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd"><route url="/V1/customers/isEmailExist/" method="POST"><service class="Test\Customers\Api\AccountInterface" method="isEmailExist"/><resources><resource ref="anonymous"/></resources></route></routes>
Run Code Online (Sandbox Code Playgroud)

5. app/code/Test/Customers/Api/AccountInterface.php

    namespace Test\Customers\Api;
/**
 * Account interface.
 * @api
 */

interface AccountInterface
{
    /**
     * Check if given email is associated with a customer account in given website.
     * @api
     * @param string $customerEmail
     * @return \Test\Customers\Api\AccountInterface
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function isEmailExist($customerEmail); …
Run Code Online (Sandbox Code Playgroud)

php xml web-services magento magento2

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

Magento 2:如何自定义管理销售订单网格集合?

我正在尝试自定义管理销售订单网格集合。我创建了一个自定义sale_order属性store_manager。这些商店经理是管理员用户,例如:'manager1'、'manager2'。

1)订单手动分配给'manager1'或'manager2'——这部分完成

2)现在我正在尝试对销售订单网格集合设置过滤器,因此当经理登录到那里的系统时,他们只能看到那里的订单。

在Magento 1,我们有sales_order_grid_collection_load_beforesales_order_grid_collection_load_after这一要求。

试图为 Magento 2 举办这样的活动,但没有取得任何成功。

我的查询:

sales_order_grid_collection_load_aftermagento 1 中是否有像 ( )这样的事件完全满足我的要求?

有没有其他方法可以将过滤器设置为销售订单网格集合?

注意:我已经在谷歌上搜索过这个,但没有得到任何完美的解决方案。

magento2

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

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 - 嵌套 json 文件中的 searchCriteria

我想过滤掉具有特定country_id.

这是来自json响应的示例:

{  
    "items": [{  
        "total_qty_ordered": 3,
        "updated_at": "2018-01-10 15:59:05",
        "weight": 0,
        "billing_address": {  
            "city": "Schaffhausen",
            "country_id": "CH"
        }
    }]
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的:

url = (
    "http://<host>/rest/V1/orders"
    "?searchCriteria[filter_groups][0][filters][0][field]=country_id"
    "&searchCriteria[filter_groups][0][filters][0][value]=CH" 
)
Run Code Online (Sandbox Code Playgroud)

它不起作用,因为country_id它在嵌套实体中。

所以我试图替换country_idbilling_address[country_id]但它也不起作用。

api rest magento magento2

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

Magento2 异常“没有这样的实体,cartId = ”在客户注销时结帐

我正在为基于 Luma 的 Magento2 开发自定义主题。

因此,当我在没有客户登录的情况下打开结帐页面时,我收到此异常。

Exception #0 (Magento\Framework\Exception\NoSuchEntityException): No such entity with cartId = 
...
Run Code Online (Sandbox Code Playgroud)

基于我在网上发现的其他类似问题,我尝试运行这个sql:

SET FOREIGN_KEY_CHECKS=0;
UPDATE `store` SET store_id = 0 WHERE code='admin';
UPDATE `store_group` SET group_id = 0 WHERE name='Default';
UPDATE `store_website` SET website_id = 0 WHERE code='admin';
UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';
SET FOREIGN_KEY_CHECKS=1;
Run Code Online (Sandbox Code Playgroud)

但没有成功。

我知道cartId 是空的,但我不知道如何解决这个问题。

checkout magento2

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

Magento 2 自定义地址属性未加载到结帐页面的地址簿中

我为 2.2.4 和 2.2.3 版本创建了一个 Magento 模块,在送货地址和客户地址中添加了一个自定义属性。在结帐页面中创建新地址时,该属性工作正常,显示我的自定义属性并保存在订单地址和报价地址中。

问题是当从地址簿加载地址时,我的自定义属性没有加载,并且在送货地址中是必需的,我不能去付款

在 Magento Admin 的客户 > 地址中编辑自定义属性时,不会保存。我将值手动设置到数据库中的客户地址中的自定义属性,但未在结帐页面中加载

因此,自定义属性仅在写入新地址时有效,而不是仅按顺序和地址引用保存在地址簿中,因此我在数据库中手动设置值但不起作用,并且我需要在进入结帐页面时将其加载到我保存的地址中。

结帐页面示例

在此处输入图片说明

请帮帮我。

DD\结帐地址\di.xml

<?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\Checkout\Block\Checkout\LayoutProcessor">
        <plugin name="add_custom_field_checkout_form" type="DD\Checkoutaddress\Model\Plugin\Checkout\LayoutProcessor" sortOrder="100"/>
    </type>

    <type name="Magento\Checkout\Model\ShippingInformationManagement">
        <plugin name="save_custom_field" type="DD\Checkoutaddress\Model\Plugin\Checkout\SaveAddressInformation" />
    </type>
</config>
Run Code Online (Sandbox Code Playgroud)

DD\Checkoutaddress\extension_attributes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="Magento\Quote\Api\Data\AddressInterface">
        <attribute code="mobilenumber" type="string" />
    </extension_attributes>

    <extension_attributes for="Magento\Checkout\Api\Data\ShippingInformationInterface">
        <attribute code="mobilenumber" type="string" />
    </extension_attributes>
</config>
Run Code Online (Sandbox Code Playgroud)

DD\Checkoutaddress\Model\Plugin\Checkout\LayoutProcessor.php

<?php
namespace DD\Checkoutaddress\Model\Plugin\Checkout;

class LayoutProcessor
{
    /**
     * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
     * @param array $jsLayout
     * @return array
     */
    public …
Run Code Online (Sandbox Code Playgroud)

php magento magento2 magento2.2.3

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

使用 magento/bin setup:di:compile 在 docker 中耗尽 PHP 内存大小

我跑了后,在日志文件中此错误php bin/magento setup:di:compile或者php bin/magento deploy:mode:set productionphp:7.1-fpm图像的容器。

[2019-02-04 12:15:26] main.ERROR: /usr/local/bin/php -f /var/www/html/m230/bin/magento setup:di:compile 2>&1 编译开始。%message% 0/7 [>---------------------------] 0% < 1 秒 72.0 MiB%message% 0/7 [ >----------------------------] 0% < 1 sec 72.0 MiBProxies 代码生成... 0/7 [>---- -----------------------] 0% < 1 sec 72.0 MiB 代理代码生成... 1/7 [====>---- -------------------] 14% 1 秒 76.0 MiB 存储库代码生成... 1/7 [====>--------- --------------] 14% 1 sec 76.0 MiB Fatal error: Allowed memory size of 134217728 bytes in /var/www/html/m230/setup/ src/Magento/Setup/Module/Di/Code/Reader/FileClassScanner.php 在第 81 行检查 …

php magento docker magento2

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

Magento 2空白页但不为空

我正在开发一个正在运行但已停止的 Magento 2.3 站点。当我尝试向上翻一页时,我看到一个空白屏幕。看似空洞的,其实包含了一点内容:

  <!doctype html>
<html lang="en">
    <head >
                <meta charset="utf-8"/>
<meta name="description" content="Blah Blah"/>
<meta name="keywords" content="More blah blah"/>
<meta name="robots" content="INDEX,FOLLOW"/>
<title></title>
<link  rel="icon" type="image/x-icon" href="http://www.magento2.domain/pub/media/favicon/stores/1/3-ladies-bg.jpg" />
<link  rel="shortcut icon" type="image/x-icon" href="http://www.magento2.domain/pub/media/favicon/stores/1/3-ladies-bg.jpg" />
<link href='https://fonts.googleapis.com/css?family=Prosto+One' rel='stylesheet' type='text/css' />
<!--xxxabb2c66c7681e8f658-->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxx-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-131267613-1');
</script>            </head>
    <body data-container="body" data-mage-init='{"loaderAjax": {}, "loader": { "icon": "http://www.magento2.domain/pub/static/version1551796553/frontend/_view/en_GB/images/loader-2.gif"}}' class="cms-index-index page-layout-1column">
            </body> …
Run Code Online (Sandbox Code Playgroud)

magento magento2

5
推荐指数
2
解决办法
3278
查看次数

标签 统计

magento2 ×10

magento ×5

php ×4

api ×3

rest ×2

android ×1

checkout ×1

docker ×1

magento2.2.3 ×1

stock ×1

web-services ×1

webview ×1

xml ×1