예제 #1
0
 /**
  * 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];
 }
예제 #2
0
 /**
  * Finds the UserSetting model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return UserSetting the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UserSetting::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }