public function run($request) { $gp = ShopConfig::current()->CustomerGroup(); if (empty($gp)) { return false; } $allCombos = DB::query("SELECT \"ID\", \"MemberID\", \"GroupID\" FROM \"Group_Members\" WHERE \"Group_Members\".\"GroupID\" = " . $gp->ID . ";"); //make an array of all combos $alreadyAdded = array(); $alreadyAdded[-1] = -1; if ($allCombos) { foreach ($allCombos as $combo) { $alreadyAdded[$combo["MemberID"]] = $combo["MemberID"]; } } $unlistedMembers = DataObject::get("Member", $where = "\"Member\".\"ID\" NOT IN (" . implode(",", $alreadyAdded) . ")", $sort = null, $join = "INNER JOIN \"Order\" ON \"Order\".\"MemberID\" = \"Member\".\"ID\""); //add combos if ($unlistedMembers) { $existingMembers = $gp->Members(); foreach ($unlistedMembers as $member) { $existingMembers->add($member); echo "."; } } else { echo "no new members added"; } }
public function setData(Order $order, array $data) { if (!isset($data[$this->addresstype . 'ToSameAddress'])) { parent::setData($order, $data); } else { $order->{$this->addresstype . "AddressID"} = $order->{$this->useAddressType . "AddressID"}; if (!$order->BillingAddressID) { $order->BillingAddressID = $order->{$this->useAddressType . "AddressID"}; } } // FIX for missing name fields $fields = array_intersect_key($data, array_flip(['FirstName', 'Surname', 'Name', 'Email'])); $changed = false; foreach ($fields as $field => $value) { if (!$order->{$this->addresstype . "Address"}()->{$field}) { $order->{$this->addresstype . "Address"}()->{$field} = $value; $changed = true; } } if ($country = ShopConfig::current()->SingleCountry) { $order->{$this->addresstype . "Address"}()->Country = $country; } if ($changed || $order->{$this->addresstype . "Address"}()->isChanged()) { $order->{$this->addresstype . "Address"}()->write(); } }
public function run($request) { $zone = Zone::create(); $zone->Name = "International"; $zone->Description = "All countries"; $zone->write(); $countries = ShopConfig::current()->getCountriesList(); foreach ($countries as $code => $country) { $zoneregion = ZoneRegion::create(array('ZoneID' => $zone->ID, 'Country' => $code)); $zoneregion->write(); echo "."; } }
public function setData(Order $order, array $data) { if (!isset($data['Use'])) { parent::setData($order, $data); return; } $member = Member::currentUser() ?: $order->Member(); if (strpos($data['Use'], 'address-') === 0) { $address = Address::get()->byID(substr($data['Use'], 8)); if (!$address) { throw new ValidationException('That address does not exist'); } if (isset($data[$data['Use']]) && isset($data[$data['Use']]['saveAsNew']) && $data[$data['Use']]['saveAsNew']) { if (!$address->canCreate()) { throw new ValidationException('You do not have permission to add a new address'); } $address = $address->duplicate(); } else { if (isset($data[$data['Use']]) && !$address->canEdit() && $address->MemberID != $member->ID) { throw new ValidationException('You do not have permission to use this address'); } } } else { if (!singleton('Address')->canCreate()) { throw new ValidationException('You do not have permission to add a new address'); } $address = Address::create(); } if (isset($data[$data['Use']])) { $address->castedUpdate($data[$data['Use']]); // FIX for missing name fields $fields = array_intersect_key($data, array_flip(['FirstName', 'Surname', 'Name', 'Email'])); foreach ($fields as $field => $value) { if (!$address->{$field}) { $address->{$field} = $value; } } if ($country = ShopConfig::current()->SingleCountry) { $address->Country = $country; } if ($this->addtoaddressbook) { $address->MemberID = $member->ID; } $address->write(); if (isset($data[$data['Use']]['useAsDefaultShipping']) && $data[$data['Use']]['useAsDefaultShipping']) { $member->DefaultShippingAddressID = $address->ID; } if (isset($data[$data['Use']]['useAsDefaultBilling']) && $data[$data['Use']]['useAsDefaultBilling']) { $member->DefaultBillingAddressID = $address->ID; } if ($member->isChanged()) { $member->write(); } } if ($address->exists()) { if ($this->addresstype === 'Shipping') { ShopUserInfo::singleton()->setAddress($address); Zone::cache_zone_ids($address); } $order->{$this->addresstype . 'AddressID'} = $address->ID; if (!$order->BillingAddressID) { $order->BillingAddressID = $address->ID; } $order->write(); $order->extend('onSet' . $this->addresstype . 'Address', $address); } }
/** * Takes an order from being a cart to awaiting payment. * * @param Member $member - assign a member to the order * * @return boolean - success/failure */ public function placeOrder() { if (!$this->order) { $this->error(_t("OrderProcessor.NoOrderStarted", "A new order has not yet been started.")); return false; } if (!$this->canPlace($this->order)) { //final cart validation return false; } if ($this->order->Locale) { ShopTools::install_locale($this->order->Locale); } // recalculate order to be sure we have the correct total $this->order->calculate(); if (ShopTools::DBConn()->supportsTransactions()) { ShopTools::DBConn()->transactionStart(); } //update status if ($this->order->TotalOutstanding(false)) { $this->order->Status = 'Unpaid'; } else { $this->order->Status = 'Paid'; } if (!$this->order->Placed) { $this->order->Placed = SS_Datetime::now()->Rfc2822(); //record placed order datetime if ($request = Controller::curr()->getRequest()) { $this->order->IPAddress = $request->getIP(); //record client IP } } // Add an error handler that throws an exception upon error, so that we can catch errors as exceptions // in the following block. set_error_handler(function ($severity, $message, $file, $line) { throw new ErrorException($message, 0, $severity, $file, $line); }, E_ALL & ~(E_STRICT | E_NOTICE)); try { //re-write all attributes and modifiers to make sure they are up-to-date before they can't be changed again $items = $this->order->Items(); if ($items->exists()) { foreach ($items as $item) { $item->onPlacement(); $item->write(); } } $modifiers = $this->order->Modifiers(); if ($modifiers->exists()) { foreach ($modifiers as $modifier) { $modifier->write(); } } //add member to order & customers group if ($member = Member::currentUser()) { if (!$this->order->MemberID) { $this->order->MemberID = $member->ID; } $cgroup = ShopConfig::current()->CustomerGroup(); if ($cgroup->exists()) { $member->Groups()->add($cgroup); } } //allow decorators to do stuff when order is saved. $this->order->extend('onPlaceOrder'); $this->order->write(); } catch (Exception $ex) { // Rollback the transaction if an error occurred if (ShopTools::DBConn()->supportsTransactions()) { ShopTools::DBConn()->transactionRollback(); } $this->error($ex->getMessage()); return false; } finally { // restore the error handler, no matter what restore_error_handler(); } // Everything went through fine, complete the transaction if (ShopTools::DBConn()->supportsTransactions()) { ShopTools::DBConn()->transactionEnd(); } //remove from session $cart = ShoppingCart::curr(); if ($cart && $cart->ID == $this->order->ID) { // clear the cart, but don't write the order in the process (order is finalized and should NOT be overwritten) ShoppingCart::singleton()->clear(false); } //send confirmation if configured and receipt hasn't been sent if (self::config()->send_confirmation && !$this->order->ReceiptSent) { $this->notifier->sendConfirmation(); } //notify admin, if configured if (self::config()->send_admin_notification) { $this->notifier->sendAdminNotification(); } // Save order reference to session OrderManipulation::add_session_order($this->order); return true; //report success }
/** * Takes an order from being a cart to awaiting payment. * * @param Member $member - assign a member to the order * * @return boolean - success/failure */ public function placeOrder() { if (!$this->order) { $this->error(_t("OrderProcessor.NULL", "A new order has not yet been started.")); return false; } if (!$this->canPlace($this->order)) { //final cart validation return false; } if ($this->order->Locale) { ShopTools::install_locale($this->order->Locale); } //remove from session $cart = ShoppingCart::curr(); if ($cart && $cart->ID == $this->order->ID) { ShoppingCart::singleton()->clear(); } //update status if ($this->order->TotalOutstanding()) { $this->order->Status = 'Unpaid'; } else { $this->order->Status = 'Paid'; } if (!$this->order->Placed) { $this->order->Placed = SS_Datetime::now()->Rfc2822(); //record placed order datetime if ($request = Controller::curr()->getRequest()) { $this->order->IPAddress = $request->getIP(); //record client IP } } //re-write all attributes and modifiers to make sure they are up-to-date before they can't be changed again $items = $this->order->Items(); if ($items->exists()) { foreach ($items as $item) { $item->onPlacement(); $item->write(); } } $modifiers = $this->order->Modifiers(); if ($modifiers->exists()) { foreach ($modifiers as $modifier) { $modifier->write(); } } //add member to order & customers group if ($member = Member::currentUser()) { if (!$this->order->MemberID) { $this->order->MemberID = $member->ID; } $cgroup = ShopConfig::current()->CustomerGroup(); if ($cgroup->exists()) { $member->Groups()->add($cgroup); } } //allow decorators to do stuff when order is saved. $this->order->extend('onPlaceOrder'); $this->order->write(); //send confirmation if configured and receipt hasn't been sent if (self::config()->send_confirmation && !$this->order->ReceiptSent) { $this->notifier->sendConfirmation(); } //notify admin, if configured if (self::config()->send_admin_notification) { $this->notifier->sendAdminNotification(); } // Save order reference to session OrderManipulation::add_session_order($this->order); return true; //report success }