Untitled
raw download clone
TEXT
views 34
,
size 1326 b
try {
            for ($i = $start; $i < $stop; $i++) {
                $opt['resource'] = 'stock_availables';
                $opt['limit'] = ($i*100).',100';
               // $opt['display'] = 'full';
                $opt['sort'] = 'id_ASC';
                $xml = $this->prestashopService->get($opt);

                foreach ($xml as $stocks) {
                    foreach ($stocks as $stock) {
                        try {
                            if (isset($stock->stock_availables->stock_available->quantity[0])) {
                                $quantity = (int)$stock->stock_availables->stock_available->quantity[0];
                            } else {
                                $quantity = 0;
                            }
                            $data = [];
                            $data['quantity'] = $quantity;

                            Product::where(['sku' => $product->ean13])->update($data);
                        } catch (\Exception $ex) {
                            echo $ex->getMessage();
                            echo 'Line: '.$ex->getLine();
                        }
                    }
                }
            }
        } catch (\Exception $ex) {
            echo $ex->getMessage();
            echo 'Line: '.$ex->getLine();
        }
close fullscreen
Login or Register to edit or fork this paste. It's free.