簡體   English   中英

PrestaShop Web服務返回意外的HTTP狀態503

[英]PrestaShop webService returns unexpected HTTP status 503

我正在將倉庫管理系統(基於PHP)與PrestaShop1.6集成在一起,並且正在使用PrestaShop Web服務進行集成。

我必須使新產品(在倉庫管理系統中創建)在PrestaShop 1.6在線商店中顯示。 倉庫管理系統要求PrestaShop Web服務在PrestaShop在線商店上創建新產品。

我編寫了如下所示的函數。 它在我的本地主機上運行良好,但是在測試服務器上,嘗試更新庫存可用性后,它收到HTTP狀態503。 在所有WebService實體上啟用了所有WebService方法(GET,PUT,DELETE等)。 我不知道如何調試此問題,您能幫我嗎?

順便說一下,我以以下代碼為例: https : //github.com/xabikip/PrestaShopWebService/blob/master/examples/createProduct.php

private function saveProduct($update, $webService, $root_path, $n_id, $n_id_category_default, $n_id_category, $n_price, $n_active, $n_avail4order, $n_show_price, $n_l_id, $n_name, $n_desc, $n_desc_short, $n_link_rewrite, $n_meta_title, $n_meta_description, $n_meta_keywords, $n_available_now, $n_available_later, $idtaglist, $cod, $quantity) {

        $webService = new PrestaShopWebservice($this->ps_shop_path, $this->ps_ws_auth_key, $this->ps_ws_debug);

        $xml = $webService->get(array('url' => $root_path . '/api/products?schema=blank'));
        $resources = $xml->children()->children();

        /*
        many values of attributes of XML object $resources are assigned here, instead of this comment
        */

        $id = "";
        try {
            $opt = array('resource' => 'products');
            if(!$update){
                $opt['postXml'] = $xml -> asXML();
                $xml = $webService -> add($opt);
                $id = $xml->product->id;
            }
            else{
                $opt['putXml'] = $xml -> asXML();
                $opt['id'] = $n_id;
                $xml = $webService -> edit($opt);
                $id = $n_id;
            }
        }
        catch (PrestaShopWebserviceException $ex) {
            echo '<b>Error : '.$ex->getMessage().'</b>';
        }

        $resources = $xml->children()->children();
        $stock_available_id = $resources->associations->stock_availables->stock_available[0]->id;
        /*
        Here we get the sotck available with were product id
        */
        try
        {
            $opt = array('resource' => 'stock_availables');
            $opt['id'] = $stock_available_id;
            $xml = $webService->get($opt);
        }
        catch (PrestaShopWebserviceException $e)
        {
            $trace = $e->getTrace();
            if ($trace[0]['args'][0] == 404) die('1:Bad ID');
            else if ($trace[0]['args'][0] == 401) die('1:Bad auth key');
            else die('1:Other error '.$e->getMessage());
        }
        $resources = $xml->children()->children();
        $resources->quantity = $quantity;
        /*
        There we call to save our stock quantity.
        */
        try
        {
            $opt = array('resource' => 'stock_availables');
            $opt['putXml'] = $xml->asXML();
            $opt['id'] = $stock_available_id;
            $xml = $webService->edit($opt);
            echo "Successfully updated.";
        }
        catch (PrestaShopWebserviceException $e)
        {
            $trace = $e->getTrace();
            if ($trace[0]['args'][0] == 404) die('2:Bad ID');
            else if ($trace[0]['args'][0] == 401) die('2:Bad auth key');
            else echo('Other error: '.$e->getMessage()); // function echoes this PrestaShopWebServiceException: "Other error: This call to PrestaShop Web Services returned an unexpected HTTP status of:503"
        }

    }

默認情況下,大多數托管都關閉PUT請求。 您是否與托管經理確認了這一點? 無論如何,您必須激活Prestashop DEBUG MODE才能知道錯誤的確切原因(當然,在解決此問題之后)。

祝好運。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM