예제 #1
0
 public function add_method()
 {
     $data = $this->post();
     $errors = $this->validate($data);
     $this->error = null;
     //clear errors
     $this->error = $errors;
     if (!$errors->has()) {
         if ($this->post('shippingMethodID')) {
             //update
             $shippingMethod = ShippingMethod::getByID($this->post('shippingMethodID'));
             $shippingMethodTypeMethod = $shippingMethod->getShippingMethodTypeMethod();
             $shippingMethodTypeMethod->update($this->post());
             $shippingMethod->update($this->post('methodName'), $this->post('methodEnabled'));
             $this->redirect('/dashboard/store/settings/shipping/updated');
         } else {
             //first we send the data to the shipping method type.
             $shippingMethodType = ShippingMethodType::getByID($this->post('shippingMethodTypeID'));
             $shippingMethodTypeMethod = $shippingMethodType->addMethod($this->post());
             //make a shipping method that correlates with it.
             ShippingMethod::add($shippingMethodTypeMethod, $shippingMethodType, $this->post('methodName'), true);
             $this->redirect('/dashboard/store/settings/shipping/success');
         }
     } else {
         $this->add($this->post('shippingMethodTypeID'));
         //$smt = ShippingMethodType::getByID($this->post('shippingMethodTypeID'));
         //$this->set('smt',$smt);
     }
 }
예제 #2
0
        foreach ($methodTypes as $methodType) {
            ?>
			<table class="table table-striped">
				<thead>
					<th><?php 
            echo $methodType->getShippingMethodTypeName() . t(" Methods");
            ?>
</th>
					<th class="text-right"><?php 
            echo t("Actions");
            ?>
</th>
				</thead>
				<tbody>
					<?php 
            foreach (ShippingMethod::getAvailableMethods($methodType->getShippingMethodTypeID()) as $method) {
                ?>
					<tr>
						<td><?php 
                echo $method->getName();
                ?>
</td>
						<td class="text-right">
							<a href="<?php 
                echo URL::to('/dashboard/store/settings/shipping/edit', $method->getShippingMethodID());
                ?>
" class="btn btn-default"><?php 
                echo t("Edit");
                ?>
</a>
							<a href="<?php 
예제 #3
0
 public static function migrateOldShippingMethod(Package $pkg)
 {
     $shippingMethodEnabled = Config::get('vividstore.shippingenabled');
     //if it wasn't even enabled, then why bother.
     if ($shippingMethodEnabled) {
         $basePrice = Config::get('vividstore.shippingbase');
         $perItem = Config::get('vividstore.shippingitem');
         $data = array('baseRate' => $basePrice, 'rateType' => 'quantity', 'perItemRate' => $perItem, 'minimumAmount' => 0, 'maximumAmount' => 0, 'minimumWeight' => 0, 'maximumWeight' => 0, 'countries' => 'all');
         $shippingMethodType = ShippingMethodType::getByHandle('flat_rate');
         $shippingMethodTypeMethod = $shippingMethodType->addMethod($data);
         ShippingMethod::add($shippingMethodTypeMethod, $shippingMethodType, 'Flat Rate', true);
     }
 }
예제 #4
0
<?php

defined('C5_EXECUTE') or die("Access Denied.");
use Concrete\Package\VividStore\Src\VividStore\Shipping\Method as ShippingMethod;
use Concrete\Package\VividStore\Src\VividStore\Utilities\Price;
$eligibleMethods = ShippingMethod::getEligibleMethods();
$i = 1;
foreach ($eligibleMethods as $method) {
    $sessionShippingMethodID = Session::get('smID');
    if ($sessionShippingMethodID == $method->getShippingMethodID()) {
        $checked = true;
    } else {
        if ($i == 1) {
            $checked = true;
        } else {
            $checked = false;
        }
    }
    ?>
    <div class="radio">
        <label>
            <input type="radio" name="shippingMethod" value="<?php 
    echo $method->getShippingMethodID();
    ?>
"<?php 
    if ($checked) {
        echo " checked";
    }
    ?>
>
            <?php 
예제 #5
0
 public function delete()
 {
     $methods = ShippingMethod::getAvailableMethods($this->getShippingMethodTypeID());
     foreach ($methods as $method) {
         $method->delete();
     }
     $em = Database::get()->getEntityManager();
     $em->remove($this);
     $em->flush();
 }
예제 #6
0
 public function add($data, $pm, $status = null)
 {
     $db = Database::get();
     //get who ordered it
     $customer = new Customer();
     //what time is it?
     $dt = Core::make('helper/date');
     $now = $dt->getLocalDateTime();
     //get the price details
     $smID = \Session::get('smID');
     if ($smID > 0) {
         $sm = ShippingMethod::getByID($smID);
         $shippingMethodTypeName = $sm->getShippingMethodType()->getShippingMethodTypeName();
         $shippingMethodName = $sm->getName();
         $smName = $shippingMethodTypeName . ": " . $shippingMethodName;
     } else {
         $smName = "No Shipping Method";
     }
     $shipping = VividCart::getShippingTotal();
     $taxes = Tax::getTaxes();
     $totals = VividCart::getTotals();
     $total = $totals['total'];
     $taxCalc = Config::get('vividstore.calculation');
     $taxTotal = array();
     $taxIncludedTotal = array();
     $taxLabels = array();
     foreach ($taxes as $tax) {
         if ($taxCalc == 'extract') {
             $taxIncludedTotal[] = $tax['taxamount'];
         } else {
             $taxTotal[] = $tax['taxamount'];
         }
         $taxLabels[] = $tax['name'];
     }
     $taxTotal = implode(',', $taxTotal);
     $taxIncludedTotal = implode(',', $taxIncludedTotal);
     $taxLabels = implode(',', $taxLabels);
     //get payment method
     $pmName = $pm->getPaymentMethodName();
     //add the order
     $vals = array($customer->getUserID(), $now, $pmName, $smName, $shipping, $taxTotal, $taxIncludedTotal, $taxLabels, $total);
     $db->Execute("INSERT INTO VividStoreOrders(cID,oDate,pmName,smName,oShippingTotal,oTax,oTaxIncluded,oTaxName,oTotal) VALUES (?,?,?,?,?,?,?,?,?)", $vals);
     $oID = $db->lastInsertId();
     $order = Order::getByID($oID);
     if ($status) {
         $order->updateStatus($status);
     } else {
         $order->updateStatus(OrderStatus::getStartingStatus()->getHandle());
     }
     $email = $customer->getEmail();
     $billing_first_name = $customer->getValue("billing_first_name");
     $billing_last_name = $customer->getValue("billing_last_name");
     $billing_address = $customer->getValueArray("billing_address");
     $billing_phone = $customer->getValue("billing_phone");
     $shipping_first_name = $customer->getValue("shipping_first_name");
     $shipping_last_name = $customer->getValue("shipping_last_name");
     $shipping_address = $customer->getValueArray("shipping_address");
     $order->setAttribute("email", $email);
     $order->setAttribute("billing_first_name", $billing_first_name);
     $order->setAttribute("billing_last_name", $billing_last_name);
     $order->setAttribute("billing_address", $billing_address);
     $order->setAttribute("billing_phone", $billing_phone);
     if ($smID) {
         $order->setAttribute("shipping_first_name", $shipping_first_name);
         $order->setAttribute("shipping_last_name", $shipping_last_name);
         $order->setAttribute("shipping_address", $shipping_address);
     }
     $customer->setLastOrderID($oID);
     //add the order items
     $cart = VividCart::getCart();
     foreach ($cart as $cartItem) {
         $taxes = Tax::getTaxForProduct($cartItem);
         $taxProductTotal = array();
         $taxProductIncludedTotal = array();
         $taxProductLabels = array();
         foreach ($taxes as $tax) {
             if ($taxCalc == 'extract') {
                 $taxProductIncludedTotal[] = $tax['taxamount'];
             } else {
                 $taxProductTotal[] = $tax['taxamount'];
             }
             $taxProductLabels[] = $tax['name'];
         }
         $taxProductTotal = implode(',', $taxProductTotal);
         $taxProductIncludedTotal = implode(',', $taxProductIncludedTotal);
         $taxProductLabels = implode(',', $taxProductLabels);
         OrderItem::add($cartItem, $oID, $taxProductTotal, $taxProductIncludedTotal, $taxProductLabels);
     }
     $discounts = VividCart::getDiscounts();
     if ($discounts) {
         foreach ($discounts as $discount) {
             $order->addDiscount($discount, VividCart::getCode());
         }
     }
     //if the payment method is not external, go ahead and complete the order.
     if (!$pm->external) {
         $order->completeOrder();
     }
     return $order;
 }
예제 #7
0
 public function getShippingTotal($smID = null)
 {
     if ($smID) {
         $shippingMethod = ShippingMethod::getByID($smID);
         Session::set('smID', $smID);
     } else {
         $sessionShippingMethodID = Session::get('smID');
         if (!empty($sessionShippingMethodID)) {
             $shippingMethod = ShippingMethod::getByID($sessionShippingMethodID);
         }
     }
     if (is_object($shippingMethod)) {
         $shippingTotal = $shippingMethod->getShippingMethodTypeMethod()->getRate();
         $discounts = self::getDiscounts();
         foreach ($discounts as $discount) {
             if ($discount->drDeductFrom == 'shipping') {
                 if ($discount->drDeductType == 'value') {
                     $shippingTotal -= $discount->drValue;
                 }
                 if ($discount->drDeductType == 'percentage') {
                     $shippingTotal -= $discount->drPercentage / 100 * $shippingTotal;
                 }
             }
         }
     }
     return $shippingTotal;
 }