Exemplo n.º 1
1
 /**
  * @return \DVDoug\BoxPacker\PackedBoxList
  */
 public function getPackages()
 {
     $packer = new ClerkPacker();
     $boxes = StoreClerkPackage::getPackages();
     foreach ($boxes as $box) {
         $packer->addBox($box);
     }
     $cartItems = StoreCart::getCart();
     foreach ($cartItems as $cartItem) {
         $product = StoreProduct::getByID((int) $cartItem['product']['pID']);
         $description = $product->getProductName();
         $width = StoreCalculator::convertToMM($product->getDimensions('w'));
         $length = StoreCalculator::convertToMM($product->getDimensions('l'));
         $depth = StoreCalculator::convertToMM($product->getDimensions('h'));
         $weight = StoreCalculator::convertToGrams($product->getProductWeight());
         $packer->addItem(new StoreClerkItem($description, $width, $length, $depth, $weight));
         //TODO: If an item doesn't fit in any box, make it it's own box.
     }
     return $packer->pack();
 }
Exemplo n.º 2
0
 public function view()
 {
     if (StoreCart::getTotalItemsInCart() == 0) {
         $this->redirect("/cart/");
     }
     $this->set('customer', $this->customer);
     $this->set('form', Core::make("helper/form"));
     $this->set("states", Core::make('helper/lists/states_provinces')->getStates());
     $billingCountryArray = StoreCheckoutUtility::getCountryOptions();
     $shippingCountryArray = StoreCheckoutUtility::getCountryOptions('shipping');
     $this->set("billingCountries", $billingCountryArray['countries']);
     $this->set("shippingCountries", $shippingCountryArray['countries']);
     $this->set("defaultBillingCountry", $billingCountryArray['defaultCountry']);
     $this->set("defaultShippingCountry", $shippingCountryArray['defaultCountry']);
     $totals = StoreCalculator::getTotals();
     $this->set('subtotal', $totals['subTotal']);
     $this->set('taxes', $totals['taxes']);
     $this->set('taxtotal', $totals['taxTotal']);
     $this->set('shippingtotal', $totals['shippingTotal']);
     $this->set('total', $totals['total']);
     $this->set('shippingEnabled', StoreCart::isShippable());
     $this->getFooterAssets();
     $enabledMethods = StorePaymentMethod::getEnabledMethods();
     $availableMethods = array();
     foreach ($enabledMethods as $em) {
         $emmc = $em->getMethodController();
         if ($totals['total'] >= $emmc->getPaymentMinimum() && $totals['total'] <= $emmc->getPaymentMaximum()) {
             $availableMethods[] = $em;
         }
     }
     $this->set("enabledPaymentMethods", $availableMethods);
 }
Exemplo n.º 3
0
 public function view()
 {
     $codeerror = false;
     $codesuccess = false;
     if ($this->isPost()) {
         if ($this->post('action') == 'update') {
             $data = $this->post();
             $result = StoreCart::update($data);
             $added = $result['added'];
             $returndata = array('success' => true, 'quantity' => (int) $data['pQty'], 'action' => 'update', 'added' => $added);
         }
         if ($this->post('action') == 'clear') {
             StoreCart::clear();
             $returndata = array('success' => true, 'action' => 'clear');
         }
         if ($this->post('action') == 'remove') {
             $data = $this->post();
             $result = StoreCart::remove($data['instance']);
             $returndata = array('success' => true, 'action' => 'remove');
         }
     }
     $this->set('actiondata', $returndata);
     $this->set('cart', StoreCart::getCart());
     $this->set('total', StoreCalculator::getSubTotal());
     $this->requireAsset('javascript', 'jquery');
     $js = \Concrete\Package\VividStore\Controller::returnHeaderJS();
     $this->addFooterItem($js);
     $this->requireAsset('javascript', 'vivid-store');
     $this->requireAsset('css', 'vivid-store');
 }
Exemplo n.º 4
0
 public function getCartModal()
 {
     $cart = StoreCart::getCart();
     $total = StoreCalculator::getSubTotal();
     if (Filesystem::exists(DIR_BASE . '/application/elements/cart_modal.php')) {
         View::element('cart_modal', array('cart' => $cart, 'total' => $total, 'actiondata' => $this->post()));
     } else {
         View::element('cart_modal', array('cart' => $cart, 'total' => $total, 'actiondata' => $this->post()), 'vivid_store');
     }
 }
Exemplo n.º 5
0
 public function view()
 {
     $this->set("itemCount", StoreCart::getTotalItemsInCart());
     $this->set("total", StorePrice::format(StoreCalculator::getSubTotal()));
     $js = \Concrete\Package\VividStore\Controller::returnHeaderJS();
     $this->requireAsset('javascript', 'jquery');
     $this->addFooterItem($js);
     $this->requireAsset('javascript', 'vivid-store');
     $this->requireAsset('css', 'vivid-store');
 }
Exemplo n.º 6
0
 public function submitPayment()
 {
     $gateway = Omnipay::create('AuthorizeNet_AIM');
     $gateway->setApiLoginId(Config::get('vividstore.authnetLoginID'));
     $gateway->setTransactionKey(Config::get('vividstore.authnetTransactionKey'));
     $gateway->setDeveloperMode(Config::get('vividstore.authnetTestmode'));
     $customer = new StoreCustomer();
     $formData = array('firstName' => $customer->getValue("billing_first_name"), 'lastName' => $customer->getValue("billing_last_name"), 'billingPhone' => $customer->getValue("billing_phone"), 'email' => $customer->getEmail(), 'number' => $_POST['authnet-checkout-credit-card'], 'expiryMonth' => $_POST['authnet-checkout-exp-month'], 'expiryYear' => $_POST['authnet-checkout-exp-year'], 'cvv' => $_POST['authnet-checkout-ccv']);
     $response = $gateway->purchase(array('amount' => StoreCalculator::getGrandTotal(), 'currency' => 'USD', 'card' => $formData))->send();
     if ($response->isSuccessful()) {
         return array('error' => 0, 'transactionReference' => $response->getTransactionReference());
     } else {
         // payment failed: display message to customer
         return array('error' => 1, 'errorMessage' => $response->getMessage());
     }
 }
Exemplo n.º 7
0
 public function edit($id)
 {
     $package = StoreClerkPackage::getByID($id);
     $this->set('reference', $package->getReference());
     $this->set('outerWidth', StoreCalculator::convertFromMM($package->getOuterWidth()));
     $this->set('outerLength', StoreCalculator::convertFromMM($package->getOuterLength()));
     $this->set('outerDepth', StoreCalculator::convertFromMM($package->getOuterDepth()));
     $this->set('innerDepth', StoreCalculator::convertFromMM($package->getInnerDepth()));
     $this->set('innerWidth', StoreCalculator::convertFromMM($package->getInnerWidth()));
     $this->set('innerLength', StoreCalculator::convertFromMM($package->getInnerLength()));
     $this->set('maxWeight', StoreCalculator::convertFromGrams($package->getMaxWeight()));
     $this->set('emptyWeight', StoreCalculator::convertFromGrams($package->getEmptyWeight()));
     $this->set('sizeUnit', Config::get('vividstore.sizeUnit'));
     $this->set('weightUnit', Config::get('vividstore.weightUnit'));
     $this->set('id', $id);
     $this->set('task', t("Update"));
 }
 public function redirectForm()
 {
     $customer = new StoreCustomer();
     $totals = StoreCalculator::getTotals();
     $paypalEmail = Config::get('vividstore.paypalEmail');
     $order = StoreOrder::getByID(Session::get('orderID'));
     $this->set('paypalEmail', $paypalEmail);
     $this->set('siteName', Config::get('concrete.site'));
     $this->set('customer', $customer);
     $this->set('total', $order->getTotal());
     $this->set('notifyURL', URL::to('/checkout/paypalresponse'));
     $this->set('orderID', $order->getOrderID());
     $this->set('returnURL', URL::to('/checkout/complete'));
     $currencyCode = Config::get('vividstore.paypalCurrency');
     if (!$currencyCode) {
         $currencyCode = "USD";
     }
     $this->set('currencyCode', $currencyCode);
 }
Exemplo n.º 9
0
 public function view()
 {
     $codeerror = false;
     $codesuccess = false;
     if ($this->isPost()) {
         if ($this->post('action') == 'code' && $this->post('code')) {
             $codesuccess = StoreCart::storeCode($this->post('code'));
             $codeerror = !$codesuccess;
         }
         if ($this->post('action') == 'update') {
             $data = $this->post();
             $result = StoreCart::update($data);
             $added = $result['added'];
             $returndata = array('success' => true, 'quantity' => (int) $data['pQty'], 'action' => 'update', 'added' => $added);
         }
         if ($this->post('action') == 'clear') {
             StoreCart::clear();
             $returndata = array('success' => true, 'action' => 'clear');
         }
         if ($this->post('action') == 'remove') {
             $data = $this->post();
             $result = StoreCart::remove($data['instance']);
             $returndata = array('success' => true, 'action' => 'remove');
         }
     }
     $this->set('actiondata', $returndata);
     $this->set('codeerror', $codeerror);
     $this->set('codesuccess', $codesuccess);
     $this->set('cart', StoreCart::getCart());
     $this->set('discounts', StoreCart::getDiscounts());
     $this->set('total', StoreCalculator::getSubTotal());
     $this->addHeaderItem("\n            <script type=\"text/javascript\">\n                var PRODUCTMODAL = '" . View::url('/productmodal') . "';\n                var CARTURL = '" . View::url('/cart') . "';\n                var CHECKOUTURL = '" . View::url('/checkout') . "';\n            </script>\n        ");
     $this->requireAsset('javascript', 'vivid-store');
     $this->requireAsset('css', 'vivid-store');
     $discountsWithCodesExist = StoreDiscountRule::discountsWithCodesExist();
     $this->set("discountsWithCodesExist", $discountsWithCodesExist);
 }
 public function isWithinRange()
 {
     $subtotal = StoreCalculator::getSubTotal();
     $max = $this->getMaximumAmount();
     if ($max != 0) {
         if ($subtotal >= $this->getMinimumAmount() && $subtotal <= $this->getMaximumAmount()) {
             return true;
         } else {
             return false;
         }
     } elseif ($subtotal >= $this->getMinimumAmount()) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 11
0
 public function view()
 {
     $this->set("itemCount", StoreCart::getTotalItemsInCart());
     $this->set("total", StorePrice::format(StoreCalculator::getSubTotal()));
 }
Exemplo n.º 12
0
 public function getShippingTotal()
 {
     $smID = $_POST['smID'];
     echo StorePrice::format(StoreCalculator::getShippingTotal($smID));
 }
Exemplo n.º 13
0
 public function calculateProduct($productObj, $qty)
 {
     if (is_object($productObj)) {
         if ($productObj->isTaxable()) {
             //if this tax rate is in the tax class associated with this product
             if ($productObj->getTaxClass()->taxClassContainsTaxRate($this)) {
                 $taxCalc = $taxCalc = Config::get('vividstore.calculation');
                 if ($taxCalc == 'extract') {
                     $taxrate = 10 / ($this->getTaxRate() + 100);
                 } else {
                     $taxrate = $this->getTaxRate() / 100;
                 }
                 switch ($this->getTaxBasedOn()) {
                     case "subtotal":
                         $productSubTotal = $productObj->getActivePrice() * $qty;
                         $tax = $taxrate * $productSubTotal;
                         $taxtotal = $taxtotal + $tax;
                         break;
                     case "grandtotal":
                         $productSubTotal = $productObj->getActivePrice() * $qty;
                         $shippingTotal = StorePrice::getFloat(StoreCalculator::getShippingTotal());
                         $taxableTotal = $productSubTotal + $shippingTotal;
                         $tax = $taxrate * $taxableTotal;
                         $taxtotal = $taxtotal + $tax;
                         break;
                 }
             }
             //if in products tax class
         }
         //if product is taxable
     }
     //if obj
     return $taxtotal;
 }
Exemplo n.º 14
0
 public function view()
 {
     $pkg = Package::getByHandle('vivid_store');
     $customer = new StoreCustomer();
     $this->set('customer', $customer);
     $guestCheckout = Config::get('vividstore.guestCheckout');
     $this->set('guestCheckout', $guestCheckout ? $guestCheckout : 'off');
     $this->set('requiresLogin', StoreCart::requiresLogin());
     if (StoreCart::getTotalItemsInCart() == 0) {
         $this->redirect("/cart/");
     }
     $this->set('form', Core::make("helper/form"));
     $allcountries = Core::make('helper/lists/countries')->getCountries();
     $db = Loader::db();
     $ak = UserAttributeKey::getByHandle('billing_address');
     $row = $db->GetRow('select akHasCustomCountries, akDefaultCountry from atAddressSettings where akID = ?', array($ak->getAttributeKeyID()));
     $defaultBillingCountry = $row['akDefaultCountry'];
     if ($row['akHasCustomCountries'] == 1) {
         $availableBillingCountries = $db->GetCol('select country from atAddressCustomCountries where akID = ?', array($ak->getAttributeKeyID()));
         $billingCountries = array();
         foreach ($availableBillingCountries as $countrycode) {
             $billingCountries[$countrycode] = $allcountries[$countrycode];
         }
     } else {
         $billingCountries = $allcountries;
     }
     $ak = UserAttributeKey::getByHandle('shipping_address');
     $row = $db->GetRow('select akHasCustomCountries, akDefaultCountry from atAddressSettings where akID = ?', array($ak->getAttributeKeyID()));
     $defaultShippingCountry = $row['akDefaultCountry'];
     if ($row['akHasCustomCountries'] == 1) {
         $availableShippingCountries = $db->GetCol('select country from atAddressCustomCountries where akID = ?', array($ak->getAttributeKeyID()));
         $shippingCountries = array();
         foreach ($availableShippingCountries as $countrycode) {
             $shippingCountries[$countrycode] = $allcountries[$countrycode];
         }
     } else {
         $shippingCountries = $allcountries;
     }
     $discountsWithCodesExist = StoreDiscountRule::discountsWithCodesExist();
     $this->set("discountsWithCodesExist", $discountsWithCodesExist);
     $this->set('cart', StoreCart::getCart());
     $this->set('discounts', StoreCart::getDiscounts());
     $this->set('hasCode', StoreCart::hasCode());
     $this->set("billingCountries", $billingCountries);
     $this->set("shippingCountries", $shippingCountries);
     $this->set("defaultBillingCountry", $defaultBillingCountry);
     $this->set("defaultShippingCountry", $defaultShippingCountry);
     $this->set("states", Core::make('helper/lists/states_provinces')->getStates());
     $totals = StoreCalculator::getTotals();
     $this->set('subtotal', $totals['subTotal']);
     $this->set('taxes', $totals['taxes']);
     $this->set('taxtotal', $totals['taxTotal']);
     $this->set('shippingtotal', $totals['shippingTotal']);
     $this->set('total', $totals['total']);
     $this->set('shippingEnabled', StoreCart::isShippable());
     $this->addHeaderItem("\n            <script type=\"text/javascript\">\n                var PRODUCTMODAL = '" . View::url('/productmodal') . "';\n                var CARTURL = '" . View::url('/cart') . "';\n                var CHECKOUTURL = '" . View::url('/checkout') . "';\n            </script>\n        ");
     $this->requireAsset('javascript', 'vivid-store');
     $this->requireAsset('css', 'vivid-store');
     $this->addFooterItem("\n            <script type=\"text/javascript\">\n                \$(function() {\n                    vividStore.loadViaHash();\n                });\n            </script>\n        ");
     $enabledMethods = StorePaymentMethod::getEnabledMethods();
     $availableMethods = array();
     foreach ($enabledMethods as $em) {
         $emmc = $em->getMethodController();
         if ($totals['total'] >= $emmc->getPaymentMinimum() && $totals['total'] <= $emmc->getPaymentMaximum()) {
             $availableMethods[] = $em;
         }
     }
     $this->set("enabledPaymentMethods", $availableMethods);
 }
Exemplo n.º 15
0
 public function getTotal()
 {
     return StoreCalculator::getGrandTotal();
 }
Exemplo n.º 16
0
 /**
  * @param array $data
  * @param StorePaymentMethod $pm
  * @param string $transactionReference
  * @param boolean $status
  * @return Order
  */
 public function add($data, $pm, $transactionReference = '', $status = null)
 {
     $customer = new StoreCustomer();
     $now = new \DateTime();
     $smName = StoreShippingMethod::getActiveShippingMethodName();
     $shippingTotal = StoreCalculator::getShippingTotal();
     $taxes = StoreTax::getConcatenatedTaxStrings();
     $totals = StoreCalculator::getTotals();
     $total = $totals['total'];
     $pmName = $pm->getPaymentMethodName();
     $order = new Order();
     $order->setCustomerID($customer->getUserID());
     $order->setOrderDate($now);
     $order->setPaymentMethodName($pmName);
     $order->setShippingMethodName($smName);
     $order->setShippingTotal($shippingTotal);
     $order->setTaxTotals($taxes['taxTotals']);
     $order->setTaxIncluded($taxes['taxIncludedTotal']);
     $order->setTaxLabels($taxes['taxLabels']);
     $order->setOrderTotal($total);
     $order->save();
     $customer->setLastOrderID($order->getOrderID());
     $order->updateStatus($status);
     $order->addCustomerAddress($customer, $order->isShippable());
     $order->addOrderItems(StoreCart::getCart());
     $order->createNeededAccounts();
     $order->assignFilePermissions();
     if (!$pm->getMethodController()->external) {
         $order->completeOrder($transactionReference);
     }
     return $order;
 }
Exemplo n.º 17
0
 public function addOrUpdate($data, $package)
 {
     $package->setReference($data['reference']);
     $package->setOuterWidth(StoreCalculator::convertToMM($data['outerWidth']));
     $package->setOuterLength(StoreCalculator::convertToMM($data['outerLength']));
     $package->setOuterDepth(StoreCalculator::convertToMM($data['outerDepth']));
     $package->setEmptyWeight(StoreCalculator::convertToGrams($data['emptyWeight']));
     $package->setInnerWidth(StoreCalculator::convertToMM($data['innerWidth']));
     $package->setInnerLength(StoreCalculator::convertToMM($data['innerLength']));
     $package->setInnerDepth(StoreCalculator::convertToMM($data['innerDepth']));
     $innerVolume = $data['innerWidth'] * $data['innerLength'] * $data['innerDepth'];
     $package->setInnerVolume(StoreCalculator::convertToMM($innerVolume));
     $package->setMaxWeight(StoreCalculator::convertToGrams($data['maxWeight']));
     $package->save();
     return $package;
 }