public function actionUploadListImage() { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; $post = Yii::$app->request->post(); if (!isset($_FILES['pimages'])) { return ['error' => 'No File found for upload.']; } else { $image = $_FILES['pimages']; $url = []; foreach ($image['tmp_name'] as $key => $value) { try { $url[] = JHelper::uploadHelper($value); } catch (\Exception $e) { return ['error' => $e->getMessage()]; } } } $lstImages = ListingImages::findOne(['product_id' => $post['productID'], 'ebay_account_id' => $post['ebayID']]); if ($lstImages != null) { $lstImages->image_url = json_encode(array_merge(json_decode($lstImages->image_url), $url)); if ($lstImages->save()) { return true; } else { return ['error' => 'failed to save']; } } else { $lstImages = new ListingImages(); $lstImages->product_id = $post['productID']; $lstImages->ebay_account_id = $post['ebayID']; $lstImages->image_url = json_encode($url); if ($lstImages->save()) { return true; } else { return ['error' => 'failed to create and save']; } } //return ['url'=>$url]; //return var_dump($_FILES['pimages']['tmp_name']); } else { return false; } }
/** * Loop orders and get shipping label */ private function getShippingLabel($orders) { $label = ''; //return count($orders); $userSetting = UserSetting::findOne(Yii::$app->user->id); $orderIndex = 0; $eParcelHelper = new EparcelHelper(); foreach ($orders as $key => $order) { $packSign = ['eParcel' => false, 'fastway' => false, 'express' => false, 'buyerCount' => 1, 'checkoutMessage' => false, 'weight' => 0, 'totalCost' => 0]; $transLabel = ''; foreach ($order['ebayTransactions'] as $transaction) { if ($product = $transaction->getProduct()->one()) { $packSign['weight'] += $product['weight'] * $transaction['qty_purchased']; $packSign['totalCost'] += $product['cost'] * $transaction['qty_purchased']; } else { $transLabel .= "Error! Can't find the product " . $transaction['item_sku']; } $transLabel .= $this->renderPartial('_translabel', ['transaction' => $transaction]); } $packSign['weight'] = round($packSign['weight'] / 1000, 2); $packSign['fastway'] = $userSetting->fastway_indicator && JHelper::isFastwayAvailable($order['recipient_postcode']); if ($packSign['totalCost'] >= $userSetting->min_cost_tracking) { $packSign['eParcel'] = true; } if ($order['shipping_service'] == 'AU_ExpressDelivery' || $order['shipping_service'] == 'AU_Express' || $order['shipping_service'] == 'AU_ExpressWithInsurance') { $packSign['express'] = true; } if ($order->buyerCount > 1) { $packSign['buyerCount'] = $order->buyerCount; } if ($order['checkout_message'] != NULL) { $packSign['checkoutMessage'] = true; } $label .= $this->renderPartial('label', ['order' => $order, 'transLabel' => $transLabel, 'packSign' => $packSign, 'orderIndex' => $orderIndex]); $orderIndex++; $eParcelHelper->addExcelRow($order, $packSign['weight']); } return ['label' => $label, 'excelObj' => $eParcelHelper]; }