惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Know Your Adversary
Know Your Adversary
D
Docker
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
V
V2EX
V
Visual Studio Blog
J
Java Code Geeks
博客园 - 【当耐特】
罗磊的独立博客
量子位
W
WeLiveSecurity
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
O
OpenAI News
PCI Perspectives
PCI Perspectives
The Last Watchdog
The Last Watchdog
S
Schneier on Security
博客园 - Franky
WordPress大学
WordPress大学
T
Tor Project blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Latest
Security Latest
Cisco Talos Blog
Cisco Talos Blog
腾讯CDC
美团技术团队
博客园 - 叶小钗
www.infosecurity-magazine.com
www.infosecurity-magazine.com
月光博客
月光博客
S
Secure Thoughts
Engineering at Meta
Engineering at Meta
T
Tailwind CSS Blog
TaoSecurity Blog
TaoSecurity Blog
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Last Week in AI
Last Week in AI
aimingoo的专栏
aimingoo的专栏
G
Google Developers Blog
D
DataBreaches.Net
Project Zero
Project Zero
S
SegmentFault 最新的问题
C
Cisco Blogs
H
Help Net Security
Google Online Security Blog
Google Online Security Blog
A
About on SuperTechFans
F
Fortinet All Blogs
博客园 - 司徒正美

博客园 - 天心PHP

去除文件夹下面所有xlsx的样式脚本 php 上传视频到阿里云OSS (不用SDK) 升级版本 断点续传 php 上传视频到阿里云OSS (不用SDK) SHEIN 开放平台授权 mercadolibre 美卡多 拉取listing Amazon SP API批量更新价格 JSON_LISTINGS_FEED Allegro API接口 Ozon API接口 Wildberries API接口 沃尔玛拉取listing和库存 Amazon SP API 拉取产品详情和修改产品属性 Amazon SP API拉取分类,五点,描述和关键字 Amazon SP API拉取日期范围报告和分类树 PHP 提取PDF文件内容 常用sql(1.分组取最新的 N 条数据; 2.删除重复数据 ) kaufland平台api mercadolibre 美卡多 本土授权(PKCE) go mod Amazon SP API拉取listing 和 批量调价
沃尔玛修改促销价格
天心PHP · 2023-11-15 · via 博客园 - 天心PHP

沃尔玛修改促销价格

2023-11-15 16:53  天心PHP  阅读(510)  评论()    收藏  举报

文档地址:Promotion - US - API Reference - Walmart Developer Portal

1.单个调价接口 Update a promotional price

us和mx 接口地址:https://marketplace.walmartapis.com/v3/price?promo=true

ca接口地址:https://marketplace.walmartapis.com/v3/ca/price?promo=true

2.批量促销调价

us和mx 接口地址:https://marketplace.walmartapis.com/v3/feeds?feedType=promo

ca接口地址:https://marketplace.walmartapis.com/v3/ca/feeds?feedType=promo

"priceDisplayCodes": "CART" 这个参数不能要  不然页面变成了  see price in cart

processMode = DELETE  删除活动 必须是当前活动的原始开始和结束时间

replaceAll 不填 可以吧非促销活动变成促销活动, replaceAll="true" 可以删除当前促销活动,重新设置促销活动

促销价格最好设置为 90%  如果设置少一分 两分的 不会成功  促销价格必须小于对比价格

//currency货币类型  $currencyarr = ['us'=>'USD','mx'=>'MXN','ca'=>'CAD'];

$walmartPostService = new WalmartListingData(30);
$effective_date = date('Y-m-d H:i:s', (strtotime(date('Y-m-d H:i:s')) - (3600*8)+300));//减去时差8个小时,也就是开始时间为当前时间+5分钟
$expiration_date = date('Y-m-d H:i:s', (strtotime('2023-11-20 08:00:00') - (3600*8)));//结束时间
$data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Price xmlns="http://walmart.com/">
    <itemIdentifier>
        <sku>Bling-WFS-3904-003009-12U0D</sku>
    </itemIdentifier>
    <pricingList replaceAll="true">
        <pricing effectiveDate="'.date('Y-m-d\TH:i:s.000\Z', strtotime($effective_date)).'" expirationDate="'.date('Y-m-d\TH:i:s.000\Z', strtotime($expiration_date)).'" processMode="UPSERT">
            <currentPrice>
                <value currency="USD" amount="21.58"/>
            </currentPrice>
            <currentPriceType>REDUCED</currentPriceType>
            <comparisonPrice>
                <value currency="USD" amount="23.99"/>
            </comparisonPrice>
        </pricing>
    </pricingList>
</Price>';
$res = $walmartPostService->updateproprice($data);//返回为xml类型
//xml转换为数组
$preg = "/(<|<\/)(?:\w+:)/is";
$newXmlStr = preg_replace($preg,"\\1",$res[1]);
$xmlstring = simplexml_load_string($newXmlStr);
$res[1] = json_decode(json_encode($xmlstring),true);


/**
 * 单个促销调价(new)
 */
public function updatepropricenew($data){
    $accountInfo = array();
    $url = 'https://marketplace.walmartapis.com/v3/price?promo=true';
    $extra = [
        "Accept"=>"application/xml",
        "Content-Type"=>"application/xml",
    ];
    if($this->site=='ca'){
        $url = 'https://marketplace.walmartapis.com/v3/ca/price?promo=true';
    }
    $headers = $this->getHeaders($url, 'PUT', $accountInfo, $extra);
    $result = $this->cur_request($url,'PUT',$data,$headers);
    return $result;
}

public function cur_request($URL, $type, $params, $headers)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $URL);
    if ($headers != "") {
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    } else {
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
    }
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch,CURLOPT_ENCODING,""); // 返回数据支持所有编码,不乱码 ;如果为空字符串"",会发送所有支持的编码类型。
    switch ($type) {
        case "GET" :
            curl_setopt($ch, CURLOPT_HTTPGET, true);
            break;
        case "POST":
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            break;
        case "PUT" :
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            break;
        case "PATCH":
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            break;
        case "DELETE":
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            break;
    }
    $file_contents = curl_exec($ch);//获得返回值
    $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return [$responseCode, $file_contents];
}

 2.批量调促销价格

$xmlus = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PriceFeed xmlns="http://walmart.com/">
    <PriceHeader>
        <version>1.5.1</version>
    </PriceHeader>
    <Price xmlns="http://walmart.com/">
        <itemIdentifier>
            <sku>Bling-xuni-3901-007012-07U0A</sku>
        </itemIdentifier>
        <pricingList replaceAll="true">
            <pricing effectiveDate="'.date('Y-m-d\TH:i:s.000\Z', strtotime($effective_date)).'" expirationDate="'.date('Y-m-d\TH:i:s.000\Z', strtotime($expiration_date)).'" processMode="UPSERT">
                <currentPrice>
                    <value currency="USD" amount="38.99"/>
                </currentPrice>
                <currentPriceType>REDUCED</currentPriceType>
                <comparisonPrice>
                    <value currency="USD" amount="43.99"/>
                </comparisonPrice>
            </pricing>
        </pricingList>
    </Price>
    <Price xmlns="http://walmart.com/">
        <itemIdentifier>
            <sku>CY-HWC-3701-010416-06W0A</sku>
        </itemIdentifier>
        <pricingList replaceAll="true">
            <pricing effectiveDate="'.date('Y-m-d\TH:i:s.000\Z', strtotime($effective_date)).'" expirationDate="'.date('Y-m-d\TH:i:s.000\Z', strtotime($expiration_date)).'" processMode="UPSERT">
                <currentPrice>
                    <value currency="USD" amount="25.99"/>
                </currentPrice>
                <currentPriceType>REDUCED</currentPriceType>
                <comparisonPrice>
                    <value currency="USD" amount="26.99"/>
                </comparisonPrice>
            </pricing>
        </pricingList>
    </Price>
    <Price xmlns="http://walmart.com/">
        <itemIdentifier>
            <sku>CY-HWC-3009-010018-06U0A</sku>
        </itemIdentifier>
        <pricingList replaceAll="true">
            <pricing effectiveDate="'.date('Y-m-d\TH:i:s.000\Z', strtotime($effective_date)).'" expirationDate="'.date('Y-m-d\TH:i:s.000\Z', strtotime($expiration_date)).'" processMode="UPSERT">
                <currentPrice>
                    <value currency="USD" amount="45.99"/>
                </currentPrice>
                <currentPriceType>REDUCED</currentPriceType>
                <comparisonPrice>
                    <value currency="USD" amount="49.99"/>
                </comparisonPrice>
            </pricing>
        </pricingList>
    </Price>
    <Price xmlns="http://walmart.com/">
        <itemIdentifier>
            <sku>Bling-xuni-2008-002326-01W0A</sku>
        </itemIdentifier>
        <pricingList replaceAll="true">
            <pricing effectiveDate="'.date('Y-m-d\TH:i:s.000\Z', strtotime($effective_date)).'" expirationDate="'.date('Y-m-d\TH:i:s.000\Z', strtotime($expiration_date)).'" processMode="UPSERT">
                <currentPrice>
                    <value currency="USD" amount="39.99"/>
                </currentPrice>
                <currentPriceType>REDUCED</currentPriceType>
                <comparisonPrice>
                    <value currency="USD" amount="45.99"/>
                </comparisonPrice>
            </pricing>
        </pricingList>
    </Price>
</PriceFeed>';
$res = $walmartPostService->updatebulkprice($xml,'promo');

/**
 * 批量调价
 */
public function updatebulkprice($data,$feedtype){
    $accountInfo = array();
    if($this->site=='ca'){
        $url = 'https://marketplace.walmartapis.com/v3/ca/feeds?feedType='.$feedtype;
    }else{
        $url = 'https://marketplace.walmartapis.com/v3/feeds?feedType='.$feedtype;
    }
    $extra = [
        "Accept"=>"application/xml",
        "Content-Type"=>"multipart/form-data",
    ];
    $body = ['file'=>($data)];
    $headers = $this->getHeaders($url, 'POST', $accountInfo, $extra);
    $res = $this->cur_request($url,'POST',$body,$headers);
    return $res;
}

//2026-04-15
最近发现按上面的方法MX批量促销调价总是提交不成功(经过修改终于MX也可以批量促销调价了) 改成文件形式提交而且不能一次10000,修改为一次5000个SKU
/**
 * 批量调价
 */
public function updatebulkprice($data,$feedtype){
    $path = Yii::getPathOfAlias('webroot')."/upload/amazoncsv";
    if (!file_exists($path)){
        mkdir($path, 0777);
    }
    $accountInfo = array();
    if($this->site=='ca'){
        $url = 'https://marketplace.walmartapis.com/v3/ca/feeds?feedType='.$feedtype;
        $pathfile = $path."/ca_promo.xml";
    }elseif($this->site=='mx'){
        $url = 'https://marketplace.walmartapis.com/v3/feeds?feedType='.$feedtype;
        $pathfile = $path."/mx_promo.xml";
    }elseif($this->site=='us'){
        $url = 'https://marketplace.walmartapis.com/v3/feeds?feedType='.$feedtype;
        $pathfile = $path."/us_promo.xml";
    }
    file_put_contents($pathfile,$data);//把xml先写到文件 CA可以10000个 MX一次5000个
    $extra = [
        "Accept"=>"application/xml",
        "Content-Type"=>"multipart/form-data",
    ];
    $body = ['file'=>new CURLFILE($pathfile)];//提交文件 
    $headers = $this->getHeaders($url, 'POST', $accountInfo, $extra);
    $res = $this->cur_request($url,'POST',$body,$headers);
    return $res;
}

获取调价结果

public function feedStatusNew($feedId, $accountId)
{
    $accountInfo = array();
    $offset = 0;
    $preg = "/(<|<\/)(?:\w+:)/is";
    $info = $itemDetails = [];
    for($i=1;$i<=10;$i++){
        $url = "https://marketplace.walmartapis.com/v3/feeds/{$feedId}?includeDetails=true&limit=1000&offset=".$offset;
        if($this->site=='ca'){
            $url = "https://marketplace.walmartapis.com/v3/ca/feeds/{$feedId}?includeDetails=true&limit=1000&offset=".$offset;
        }
        $extra = [
            "Accept"=>"application/xml",
            "Content-Type"=>"application/xml",
        ];
        $headers = $this->getHeaders($url, 'GET', $accountInfo, $extra);
        $result  = $this->getResult($url, $headers);
        $newXmlStr = preg_replace($preg,"\\1",$result);
        $xmlstring = simplexml_load_string($newXmlStr);
        $xmlarr = json_decode(json_encode($xmlstring),true);
        if(isset($xmlarr['error']) || isset($xmlarr['errors'])){
            if(isset($info['itemDetails'])){
                return $info;
            }else{
                return $xmlarr;
            }
        }
        if($offset==0){
            $itemDetails = $xmlarr['itemDetails']['itemIngestionStatus'];
            unset($xmlarr['itemDetails']);
            $info = $xmlarr;
        }else{
            $info['offset'] = $offset;
            $itemDetails = array_merge($itemDetails,$xmlarr['itemDetails']['itemIngestionStatus']);
        }
        $info['itemDetails'] = $itemDetails;
        $offset = $offset+1000;
    }
    return $info;
}

结果数据

Array
(
    [feedId] => F87332655E3845DE86B61E23AD52C7C0@ARMBBgA
    [feedStatus] => PROCESSED
    [feedSubmissionDate] => 2023-11-18T03:57:01.704Z
    [itemsReceived] => 3
    [itemsSucceeded] => 3
    [itemsFailed] => 0
    [itemsProcessing] => 0
    [offset] => 0
    [limit] => 1000
    [itemDetails] => Array
        (
            [0] => Array
                (
                    [martId] => 7
                    [sku] => NikouMX-haiXD12487
                    [wpid] => 6638ERWI19MO
                    [index] => 0
                    [itemid] => 5188303865
                    [productIdentifiers] => Array
                        (
                        )

                    [ingestionStatus] => SUCCESS
                )

            [1] => Array
                (
                    [martId] => 7
                    [sku] => NikouMX-haiXD05332-04
                    [wpid] => 3S3G629YPAQG
                    [index] => 1
                    [itemid] => 5157989450
                    [productIdentifiers] => Array
                        (
                        )

                    [ingestionStatus] => SUCCESS
                )

            [2] => Array
                (
                    [martId] => 7
                    [sku] => NikouMX-hai2411210184611
                    [wpid] => 7K8GQ28FZOSK
                    [index] => 2
                    [itemid] => 5188270257
                    [productIdentifiers] => Array
                        (
                        )

                    [ingestionStatus] => SUCCESS
                )

        )

)