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()); }
public function __construct() { parent::__construct(Page::getByPath('/checkout/')); $this->requiresLogin = StoreCart::requiresLogin(); $this->customer = new StoreCustomer(); $guestCheckout = Config::get('vividstore.guestCheckout'); $this->guestCheckout = $guestCheckout ? $guestCheckout : 'off'; $this->showLoginScreen = $this->showLoginScreen(); }
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"; } }
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); }