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 clear()
 {
     StoreCart::clear();
     $returndata = array('success' => true, 'action' => 'clear');
     echo json_encode($returndata);
     exit;
 }
Exemplo n.º 3
0
 public function submitPayment()
 {
     $dir = $this->getMethodDirectory();
     require_once $dir . 'anet_php_sdk/AuthorizeNet.php';
     $METHOD_TO_USE = "AIM";
     define("AUTHORIZENET_API_LOGIN_ID", Config::get('vividstore.authnetLoginID'));
     // Add your API LOGIN ID
     define("AUTHORIZENET_TRANSACTION_KEY", Config::get('vividstore.authnetTransactionKey'));
     // Add your API transaction key
     define("AUTHORIZENET_SANDBOX", Config::get('vividstore.authnetTestmode'));
     // Set to false to test against production
     define("TEST_REQUEST", "FALSE");
     // You may want to set to true if testing against production
     //define("AUTHORIZENET_MD5_SETTING","");                // Add your MD5 Setting.
     //$site_root = ""; // Add the URL to your site
     if (AUTHORIZENET_API_LOGIN_ID == "") {
         die('Enter your merchant credentials');
     }
     $transaction = new AuthorizeNetAIM();
     $transaction->setSandbox(AUTHORIZENET_SANDBOX);
     $transaction->setFields(array('amount' => Price::getFloat(VividCart::getTotal()), 'card_num' => $_POST['authnet-checkout-credit-card'], 'exp_date' => $_POST['authnet-checkout-exp-month'] . $_POST['authnet-checkout-exp-year']));
     $response = $transaction->authorizeAndCapture();
     if ($response->approved) {
         return true;
     } else {
         return array('error' => 1, 'errorMessage' => $response->error_message . " Error Code: " . $response->response_code . ". Message: " . $response->response_reason_text);
     }
 }
Exemplo n.º 4
0
 public function view()
 {
     $pkg = Package::getByHandle('vivid_store');
     $customer = new Customer();
     $this->set('customer', $customer);
     $guestCheckout = Config::get('vividstore.guestCheckout');
     $this->set('guestCheckout', $guestCheckout ? $guestCheckout : 'off');
     $this->set('requiresLogin', VividCart::requiresLogin());
     if (VividCart::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;
     }
     $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 = VividCart::getTotals();
     $this->set('subtotal', $totals['subTotal']);
     $this->set('taxes', $totals['taxes']);
     $taxBased = Config::get('vividstore.taxBased');
     $taxlabel = Config::get('vividstore.taxName');
     $this->set('taxtotal', $totals['taxTotal']);
     $this->set('shippingtotal', $totals['shippingTotal']);
     $this->set('total', $totals['total']);
     $this->set('shippingEnabled', VividCart::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        ");
     $packagePath = $pkg->getRelativePath();
     $this->addFooterItem(Core::make('helper/html')->javascript($packagePath . '/js/vivid-store.js', 'vivid-store'));
     $this->addHeaderItem(Core::make('helper/html')->css($packagePath . '/css/vivid-store.css', 'vivid-store'));
     $this->addFooterItem("\n            <script type=\"text/javascript\">\n                vividStore.loadViaHash();\n            </script>\n        ");
     $this->set("enabledPaymentMethods", PaymentMethod::getEnabledMethods());
 }
Exemplo n.º 5
0
 public function view()
 {
     $pkg = Package::getByHandle('vivid_store');
     $packagePath = $pkg->getRelativePath();
     $this->addFooterItem(Core::make('helper/html')->javascript($packagePath . '/js/vivid-store.js', 'vivid-store'));
     $this->addHeaderItem(Core::make('helper/html')->css($packagePath . '/css/vivid-store.css', 'vivid-store'));
     $this->set("itemCount", VividCart::getTotalItemsInCart());
     $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                var QTYMESSAGE = '" . t('Quantity must be greater than zero') . "';\n            </script>\n        ");
 }
 public function submitPayment()
 {
     $crypt = Loader::helper('encryption');
     $paypal = new \Concrete\Package\PaypalExpressVividStore\Src\VividStore\Payment\Methods\PaypalExpress\Helpers\PaypalExpressHelper();
     $totals = VividCart::getTotals();
     if (Config::get('vividstore.paypalExpressMode') == 'test') {
         $type = 'sandbox';
     } else {
         $type = 'live';
     }
     $invoice = Invoice::get();
     $conf = ['type' => $type, 'username' => Config::get('vividstore.paypalExpressUsername'), 'password' => Config::get('vividstore.paypalExpressPassword'), 'signature' => Config::get('vividstore.paypalExpressSignature'), 'notify_url' => (string) URL::to('/paypal_express_vivid_store/notify'), 'cancel_url' => (string) URL::to('/paypal_express_vivid_store/cancel'), 'return_url' => (string) URL::to('/paypal_express_vivid_store/return'), 'cart_total' => $totals['total'], 'cart_subtotal' => $totals['subTotal'], 'cart_tax' => $totals['taxTotal'], 'cart_shipping' => $totals['shippingTotal'], 'invoice' => $crypt->encrypt($invoice), 'description' => t(SITE), 'currency_code' => Config::get('vividstore.paypalExpressCurrencyCode'), 'payment_action' => Config::get('vividstore.paypalExpressTransactionType')];
     $paypal->setConfig($conf);
     if (isset($_GET['token']) && isset($_GET['PayerID'])) {
         $token = urldecode($_GET['token']);
         $payer_id = urldecode($_GET['PayerID']);
         $data_get = $paypal->getExpressCheckout($token, $payer_id);
         $response = $paypal->makeRequest($data_get, $type);
         if ($response['ACK'] == 'Success') {
             $data_do = $paypal->doExpressCheckout($token, $payer_id);
             $response = $paypal->makeRequest($data_do, $type);
             if ($response['ACK'] == 'Success') {
                 return true;
             }
         }
     } else {
         $items = [];
         $cart = Session::get('cart');
         if ($cart) {
             foreach ($cart as $cartItem) {
                 $pID = $cartItem['product']['pID'];
                 $qty = $cartItem['product']['qty'];
                 $product = VividProduct::getByID($pID);
                 if (is_object($product)) {
                     $tempItem = [];
                     $tempItem['name'] = $product->getProductName();
                     $tempItem['desc'] = strip_tags($product->getProductDesc());
                     $tempItem['price'] = $product->getFormattedPrice();
                     $tempItem['qty'] = $qty;
                     $items[] = $tempItem;
                 }
             }
         }
         $configData = [];
         $configData['items'] = $items;
         $configData['item_sum'] = $totals['total'];
         $data = $paypal->setExpressCheckout($configData);
         $response = $paypal->makeRequest($data, $type);
         if ($response['ACK'] == 'Success') {
             //Redirect to paypal payment page
             header('Location: ' . $paypal->getPaypalUrl($response['TOKEN']));
             exit;
         } else {
             return ['error' => 1, 'errorMessage' => print_r($response, true)];
         }
     }
 }
Exemplo n.º 7
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.º 8
0
 public function getCartModal()
 {
     $cart = VividCart::getCart();
     $total = VividCart::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');
     }
 }
 public function redirectForm()
 {
     $customer = new Customer();
     $totals = VividCart::getTotals();
     $paypalEmail = Config::get('vividstore.paypalEmail');
     $order = VividOrder::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'));
 }
Exemplo n.º 10
0
 public static function getSubTotal()
 {
     $cart = StoreCart::getCart();
     $subtotal = 0;
     if ($cart) {
         foreach ($cart as $cartItem) {
             $pID = $cartItem['product']['pID'];
             $qty = $cartItem['product']['qty'];
             $product = StoreProduct::getByID($pID);
             if ($cartItem['product']['variation']) {
                 $product->setVariation($cartItem['product']['variation']);
             }
             if (is_object($product)) {
                 $productSubTotal = $product->getActivePrice() * $qty;
                 $subtotal = $subtotal + $productSubTotal;
             }
         }
     }
     return max($subtotal, 0);
 }
Exemplo n.º 11
0
 public function calculate()
 {
     $cart = StoreCart::getCart();
     $taxtotal = 0;
     if ($cart) {
         foreach ($cart as $cartItem) {
             $pID = $cartItem['product']['pID'];
             $qty = $cartItem['product']['qty'];
             $product = StoreProduct::getByID($pID);
             if (is_object($product)) {
                 if ($product->isTaxable()) {
                     //if this tax rate is in the tax class associated with this product
                     if (is_object($product->getTaxClass())) {
                         if ($product->getTaxClass()->taxClassContainsTaxRate($this)) {
                             $taxCalc = Config::get('vividstore.calculation');
                             if ($taxCalc == 'extract') {
                                 $taxrate = 10 / ($this->getTaxRate() + 100);
                             } else {
                                 $taxrate = $this->getTaxRate() / 100;
                             }
                             switch ($this->getTaxBasedOn()) {
                                 case "subtotal":
                                     $productSubTotal = $product->getActivePrice() * $qty;
                                     $tax = $taxrate * $productSubTotal;
                                     $taxtotal = $taxtotal + $tax;
                                     break;
                                 case "grandtotal":
                                     $productSubTotal = $product->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
         }
         //foreach
     }
     //if cart
     return $taxtotal;
 }
Exemplo n.º 12
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.º 13
0
 public function add($data, $pm, $status = null)
 {
     $taxBased = Config::get('vividstore.taxBased');
     $taxlabel = Config::get('vividstore.taxName');
     $this->set('taxlabel', $taxlabel);
     $taxCalc = Config::get('vividstore.calculation');
     $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
     $shipping = VividCart::getShippingTotal();
     $shipping = Price::formatFloat($shipping);
     $taxvalue = VividCart::getTaxTotal();
     $taxName = Config::get('vividstore.taxName');
     $total = VividCart::getTotal();
     $total = Price::formatFloat($total);
     $tax = 0;
     $taxIncluded = 0;
     if ($taxCalc == 'extract') {
         $taxIncluded = $taxvalue;
     } else {
         $tax = $taxvalue;
     }
     $tax = Price::formatFloat($tax);
     //get payment method
     $pmID = $pm->getPaymentMethodID();
     //add the order
     $vals = array($customer->getUserID(), $now, $pmID, $shipping, $tax, $taxIncluded, $taxName, $total);
     $db->Execute("INSERT INTO VividStoreOrders(cID,oDate,pmID,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());
     }
     $order->setAttribute("email", $customer->getEmail());
     $order->setAttribute("billing_first_name", $customer->getValue("billing_first_name"));
     $order->setAttribute("billing_last_name", $customer->getValue("billing_last_name"));
     $order->setAttribute("billing_address", $customer->getValueArray("billing_address"));
     $order->setAttribute("billing_phone", $customer->getValue("billing_phone"));
     $order->setAttribute("shipping_first_name", $customer->getValue("shipping_first_name"));
     $order->setAttribute("shipping_last_name", $customer->getValue("shipping_last_name"));
     $order->setAttribute("shipping_address", $customer->getValueArray("shipping_address"));
     $customer->setLastOrderID($oID);
     //add the order items
     $cart = VividCart::getCart();
     foreach ($cart as $cartItem) {
         $taxvalue = VividCart::getTaxProduct($cartItem['product']['pID']);
         $tax = 0;
         $taxIncluded = 0;
         if ($taxCalc == 'extract') {
             $taxIncluded = $taxvalue;
         } else {
             $tax = $taxvalue;
         }
         $productTaxName = $taxName;
         if ($taxvalue == 0) {
             $productTaxName = '';
         }
         OrderItem::add($cartItem, $oID, $tax, $taxIncluded, $productTaxName);
         $product = VividProduct::getByID($cartItem['product']['pID']);
         if ($product && $product->hasUserGroups()) {
             $usergroupstoadd = $product->getProductUserGroups();
             foreach ($usergroupstoadd as $id) {
                 $g = Group::getByID($id);
                 if ($g) {
                     $customer->getUserInfo()->enterGroup($g);
                 }
             }
         }
     }
     if (!$customer->isGuest()) {
         //add user to Store Customers group
         $group = \Group::getByName('Store Customer');
         if (is_object($group) || $group->getGroupID() < 1) {
             $customer->getUserInfo()->enterGroup($group);
         }
     }
     // create order event and dispatch
     $event = new OrderEvent($order);
     Events::dispatch('on_vividstore_order', $event);
     //send out the alerts
     $mh = new MailService();
     $pkg = Package::getByHandle('vivid_store');
     $fromEmail = Config::get('vividstore.emailalerts');
     if (!$fromEmail) {
         $fromEmail = "store@" . $_SERVER['SERVER_NAME'];
     }
     $alertEmails = explode(",", Config::get('vividstore.notificationemails'));
     $alertEmails = array_map('trim', $alertEmails);
     //receipt
     $mh->from($fromEmail);
     $mh->to($customer->getEmail());
     $mh->addParameter("order", $order);
     $mh->addParameter("taxbased", $taxBased);
     $mh->addParameter("taxlabel", $taxlabel);
     $mh->load("order_receipt", "vivid_store");
     $mh->sendMail();
     //order notification
     $mh->from($fromEmail);
     foreach ($alertEmails as $alertEmail) {
         $mh->to($alertEmail);
     }
     $mh->addParameter("order", $order);
     $mh->addParameter("taxbased", $taxBased);
     $mh->addParameter("taxlabel", $taxlabel);
     $mh->load("new_order_notification", "vivid_store");
     $mh->sendMail();
     VividCart::clear();
     return $order;
 }
Exemplo n.º 14
0
 public function getTotalItems()
 {
     echo VividCart::getTotalItemsInCart();
 }
Exemplo n.º 15
0
 public function getRate()
 {
     $shippableItems = VividCart::getShippableItems();
     if (count($shippableItems) > 0) {
         if ($this->getRateType() == 'quantity') {
             $shippingTotal = $this->getQuantityBasedRate($shippableItems);
         } elseif ($this->getRateType() == 'weight') {
             $shippingTotal = $this->getWeightBasedRate($shippableItems);
         }
     } else {
         $shippingTotal = 0;
     }
     return $shippingTotal;
 }
 public function isWithinWeight()
 {
     $totalWeight = StoreCart::getCartWeight();
     $maxWeight = $this->getMaximumWeight();
     if ($max != 0) {
         if ($totalWeight >= $this->getMinimumWeight() && $totalWeight <= $this->getMaximumWeight()) {
             return true;
         } else {
             return false;
         }
     } elseif ($totalWeight >= $this->getMinimumWeight()) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 17
0
 public function getTotals()
 {
     $subTotal = Price::getFloat(Cart::getSubTotal());
     $taxes = self::getTaxes();
     $addedTaxTotal = 0;
     $includedTaxTotal = 0;
     if ($taxes) {
         foreach ($taxes as $tax) {
             if ($tax['calculation'] != 'extract') {
                 $addedTaxTotal += $tax['taxamount'];
             } else {
                 $includedTaxTotal += $tax['taxamount'];
             }
         }
     }
     $shippingTotal = Price::getFloat(Cart::getShippingTotal());
     $total = $subTotal + $addedTaxTotal + $shippingTotal;
     return array('subTotal' => $subTotal, 'taxes' => $taxes, 'taxTotal' => $addedTaxTotal + $includedTaxTotal, 'shippingTotal' => $shippingTotal, 'total' => $total);
 }
Exemplo n.º 18
0
 public function view()
 {
     $this->set("itemCount", VividCart::getTotalItemsInCart());
     $this->set("total", Price::format(VividCart::getSubTotal()));
 }
Exemplo n.º 19
0
 public function updater()
 {
     if (isset($_POST)) {
         $data = $_POST;
         $billing = false;
         if ($data['adrType'] == 'billing') {
             $billing = true;
             $u = new User();
             $guest = !$u->isLoggedIn();
             $requiresLoginOrDifferentEmail = false;
             if ($guest) {
                 $emailexists = $this->validateAccountEmail($data['email']);
             }
             $orderRequiresLogin = StoreCart::requiresLogin();
             if ($orderRequiresLogin && $emailexists) {
                 $requiresLoginOrDifferentEmail = true;
             }
         }
         $e = $this->validateAddress($data, $billing);
         if ($requiresLoginOrDifferentEmail) {
             $e->add(t('The email address you have entered has already been used to create an account. Please login first or enter a different email address.'));
         }
         if ($e->has()) {
             echo $e->outputJSON();
         } else {
             $customer = new StoreCustomer();
             $address = new AttributeValue();
             if ($data['adrType'] == 'billing') {
                 $this->updateBilling($data);
                 $addressraw = $customer->getValue('billing_address');
                 $phone = $customer->getValue('billing_phone');
                 $first_name = $customer->getValue('billing_first_name');
                 $last_name = $customer->getValue('billing_last_name');
                 $company_name = $customer->getValue('billing_company_name');
                 $email = $customer->getEmail();
             }
             if ($data['adrType'] == 'shipping') {
                 $this->updateShipping($data);
                 $addressraw = $customer->getValue('shipping_address');
                 $phone = '';
                 $email = '';
                 $first_name = $customer->getValue('shipping_first_name');
                 $last_name = $customer->getValue('shipping_last_name');
                 $company_name = $customer->getValue('shipping_company_name');
             }
             // use concrete5's built in address class for formatting
             $address->address1 = $addressraw->address1;
             $address->address2 = $addressraw->address2;
             $address->city = $addressraw->city;
             $address->state_province = $addressraw->state_province;
             $address->postal_code = $addressraw->postal_code;
             $address->city = $addressraw->city;
             $address->country = $addressraw->country;
             $address = nl2br($address . '');
             // force to string
             echo json_encode(array('first_name' => $first_name, 'last_name' => $last_name, 'company_name' => $company_name, 'phone' => $phone, 'email' => $email, 'address' => $address, "error" => false));
         }
     } else {
         echo "An error occured";
     }
 }
Exemplo n.º 20
0
 public function completeOrder($transactionReference = null)
 {
     if ($transactionReference) {
         $this->setTransactionReference($transactionReference);
         $this->save();
     }
     //in case of external payment hitting, update the status.
     //otherwise nothing should really happen.
     $this->updateStatus();
     $this->dispatchEmailNotifications();
     StoreCustomer::addCustomerToUserGroupsByOrder($this);
     $event = new StoreOrderEvent($this);
     Events::dispatch('on_vividstore_order', $event);
     // unset the shipping type, as next order might be unshippable
     \Session::set('smID', '');
     StoreCart::clear();
     return $this;
 }
Exemplo n.º 21
0
 public function getCartListElement()
 {
     $fileSystem = new \Illuminate\Filesystem\Filesystem();
     if ($fileSystem->exists(DIR_BASE . '/application/elements/cart_list.php')) {
         View::element('cart_list', array('cart' => StoreCart::getCart()));
     } else {
         View::element('cart_list', array('cart' => StoreCart::getCart()), 'vivid_store');
     }
 }
Exemplo n.º 22
0
 public function clear()
 {
     VividCart::clear();
     $this->view();
 }
Exemplo n.º 23
0
 public function view()
 {
     $this->set("itemCount", StoreCart::getTotalItemsInCart());
     $this->set("total", StorePrice::format(StoreCalculator::getSubTotal()));
 }
Exemplo n.º 24
0
 public function getTotalItems()
 {
     echo StoreCart::getTotalItemsInCart();
 }
Exemplo n.º 25
0
 public static function getTotals()
 {
     $subTotal = self::getSubTotal();
     $taxes = StoreTax::getTaxes();
     $addedTaxTotal = 0;
     $includedTaxTotal = 0;
     $taxCalc = Config::get('vividstore.calculation');
     if ($taxes) {
         foreach ($taxes as $tax) {
             if ($taxCalc != 'extract') {
                 $addedTaxTotal += $tax['taxamount'];
             } else {
                 $includedTaxTotal += $tax['taxamount'];
             }
         }
     }
     $shippingTotal = self::getShippingTotal();
     $discountedSubtotal = $subTotal;
     $discounts = StoreCart::getDiscounts();
     foreach ($discounts as $discount) {
         if ($discount->drDeductFrom == 'subtotal') {
             if ($discount->drDeductType == 'value') {
                 $discountedSubtotal -= $discount->drValue;
             }
             if ($discount->drDeductType == 'percentage') {
                 $discountedSubtotal -= $discount->drPercentage / 100 * $discountedSubtotal;
             }
         }
     }
     $total = $discountedSubtotal + $addedTaxTotal + $shippingTotal;
     foreach ($discounts as $discount) {
         if ($discount->drDeductFrom == 'total') {
             if ($discount->drDeductType == 'value') {
                 $total -= $discount->drValue;
             }
             if ($discount->drDeductType == 'percentage') {
                 $total -= $discount->drPercentage / 100 * $total;
             }
         }
     }
     return array('subTotal' => $subTotal, 'taxes' => $taxes, 'taxTotal' => $addedTaxTotal + $includedTaxTotal, 'shippingTotal' => $shippingTotal, 'total' => $total);
 }
Exemplo n.º 26
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(StoreCart::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.º 27
0
 public function completeOrder($transactionReference = null)
 {
     if ($transactionReference) {
         $this->setTransactionReference($transactionReference);
     }
     $smID = \Session::get('smID');
     $groupstoadd = array();
     $createlogin = false;
     $orderItems = $this->getOrderItems();
     $customer = new StoreCustomer();
     foreach ($orderItems as $orderItem) {
         $product = $orderItem->getProductObject();
         if ($product && $product->hasUserGroups()) {
             $productusergroups = $product->getProductUserGroups();
             foreach ($productusergroups as $pug) {
                 $groupstoadd[] = $pug->getUserGroupID();
             }
         }
         if ($product && $product->createsLogin()) {
             $createlogin = true;
         }
     }
     if ($createlogin && $customer->isGuest()) {
         $email = $customer->getEmail();
         $user = UserInfo::getByEmail($email);
         if (!$user) {
             $password = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 10);
             $mh = Loader::helper('mail');
             $mh->addParameter('siteName', Config::get('concrete.site'));
             $navhelper = Core::make('helper/navigation');
             $target = Page::getByPath('/login');
             if ($target) {
                 $link = $navhelper->getLinkToCollection($target, true);
                 if ($link) {
                     $mh->addParameter('link', $link);
                 }
             } else {
                 $mh->addParameter('link', '');
             }
             $valc = Loader::helper('concrete/validation');
             $min = Config::get('concrete.user.username.minimum');
             $max = Config::get('concrete.user.username.maximum');
             $newusername = preg_replace("/[^A-Za-z0-9_]/", '', strstr($email, '@', true));
             while (!$valc->isUniqueUsername($newusername) || strlen($newusername) < $min) {
                 if (strlen($newusername) >= $max) {
                     $newusername = substr($newusername, 0, $max - 5);
                 }
                 $newusername .= rand(0, 9);
             }
             $user = UserInfo::add(array('uName' => $newusername, 'uEmail' => trim($email), 'uPassword' => $password));
             if (Config::get('concrete.user.registration.email_registration')) {
                 $mh->addParameter('username', trim($email));
             } else {
                 $mh->addParameter('username', $newusername);
             }
             $mh->addParameter('password', $password);
             $email = trim($email);
             $mh->load('new_user', 'vivid_store');
             // login the newly created user
             User::loginByUserID($user->getUserID());
         } else {
             // we're attempting to create a new user with an email that has already been used
             // earlier validation must have failed at this point, don't fetch the user
             $user = null;
         }
         $mh->to($email);
         $mh->sendMail();
     } elseif ($createlogin) {
         // or if we found a user (because they are logged in) and need to use it to create logins
         $user = $customer->getUserInfo();
     }
     if ($user) {
         // $user is going to either be the new one, or the user of the currently logged in customer
         // update the order created with the user from the newly created user
         $this->associateUser($user->getUserID());
         $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");
         // update the  user's attributes
         $customer = new StoreCustomer($user->getUserID());
         $customer->setValue('billing_first_name', $billing_first_name);
         $customer->setValue('billing_last_name', $billing_last_name);
         $customer->setValue('billing_address', $billing_address);
         $customer->setValue('billing_phone', $billing_phone);
         if ($smID) {
             $customer->setValue('shipping_first_name', $shipping_first_name);
             $customer->setValue('shipping_last_name', $shipping_last_name);
             $customer->setValue('shipping_address', $shipping_address);
         }
         //add user to Store Customers group
         $group = \Group::getByName('Store Customer');
         if (is_object($group) || $group->getGroupID() < 1) {
             $user->enterGroup($group);
         }
         foreach ($groupstoadd as $id) {
             $g = Group::getByID($id);
             if ($g) {
                 $user->getUserObject()->enterGroup($g);
             }
         }
         $u = new \User();
         $u->refreshUserGroups();
     }
     StoreCart::clearCode();
     // create order event and dispatch
     $event = new StoreOrderEvent($this);
     Events::dispatch('on_vividstore_order', $event);
     //send out the alerts
     $mh = new MailService();
     $pkg = Package::getByHandle('vivid_store');
     $fromEmail = Config::get('vividstore.emailalerts');
     if (!$fromEmail) {
         $fromEmail = "store@" . $_SERVER['SERVER_NAME'];
     }
     $alertEmails = explode(",", Config::get('vividstore.notificationemails'));
     $alertEmails = array_map('trim', $alertEmails);
     //receipt
     $mh->from($fromEmail);
     $mh->to($customer->getEmail());
     $mh->addParameter("order", $this);
     $mh->load("order_receipt", "vivid_store");
     $mh->sendMail();
     $validNotification = false;
     //order notification
     $mh->from($fromEmail);
     foreach ($alertEmails as $alertEmail) {
         if ($alertEmail) {
             $mh->to($alertEmail);
             $validNotification = true;
         }
     }
     if ($validNotification) {
         $mh->addParameter("order", $this);
         $mh->load("new_order_notification", "vivid_store");
         $mh->sendMail();
     }
     // unset the shipping type, as next order might be unshippable
     \Session::set('smID', '');
     StoreCart::clear();
     return $this;
 }