Ejemplo 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();
 }
Ejemplo n.º 2
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');
 }
Ejemplo n.º 3
0
 public function view()
 {
     $this->set('cart', VividCart::getCart());
     $this->set('total', VividCart::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->addFooterItem(Core::make('helper/html')->javascript('vivid-store.js', 'vivid_store'));
     $this->addHeaderItem(Core::make('helper/html')->css('vivid-store.css', 'vivid_store'));
 }
Ejemplo n.º 4
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');
     }
 }
Ejemplo n.º 5
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 (is_object($product)) {
                 $productSubTotal = $product->getActivePrice() * $qty;
                 $subtotal = $subtotal + $productSubTotal;
             }
         }
     }
     return max($subtotal, 0);
 }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
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');
     }
 }
Ejemplo n.º 11
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;
 }
Ejemplo 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);
 }