コード例 #1
0
 protected function orderTax_45()
 {
     $explanation = "\r\n\t\t\t<h1>45. Order Added Tax</h1>\r\n\t\t\t<p>Move the tax in the order to its own modifier.</p>\r\n\t\t";
     if ($this->retrieveInfoOnly) {
         return $explanation;
     } else {
         echo $explanation;
     }
     if ($this->hasTableAndField("Order", "AddedTax")) {
         $this->DBAlterationMessageNow("Moving Order.AddedTax to Modifier.", "created");
         $orders = Order::get()->where("\"AddedTax\" > 0")->limit($this->limit, $this->start);
         if ($orders->count()) {
             foreach ($orders as $order) {
                 $id = $order->ID;
                 $hasShippingCost = DB::query("SELECT \"AddedTax\" FROM \"Order\" WHERE \"ID\" = '{$id}'")->value();
                 $addedTax = DB::query("SELECT \"AddedTax\" FROM \"Order\" WHERE \"ID\" = '{$id}'")->value();
                 if ($addedTax != null && $addedTax > 0) {
                     $modifier1 = new FlatTaxModifier();
                     $modifier1->CalculatedTotal = $addedTax < 0 ? abs($addedTax) : $addedTax;
                     $modifier1->TableValue = $addedTax < 0 ? abs($addedTax) : $addedTax;
                     $modifier1->OrderID = $id;
                     $modifier1->TableTitle = 'Tax';
                     $modifier1->write();
                     $this->DBAlterationMessageNow(" ------------- Added tax.", "created");
                 } else {
                     $this->DBAlterationMessageNow(" ------------- No need to add tax even though field is present");
                 }
             }
             return $this->start + $this->limit;
         } else {
             $this->DBAlterationMessageNow("There are no orders with a AddedTax field greater than zero.");
         }
         $this->makeFieldObsolete("Order", "AddedTax");
     } else {
         $this->DBAlterationMessageNow("No need to update taxes.");
     }
     return 0;
 }