protected function import_User($instance, $record, CsvImportProfile $profile) { $user = $this->getImporterInstance('User')->getInstance($record, $profile); if (!$user->email->get()) { return; } $id = $this->importRelatedRecord('User', $user, $record, $profile); $instance->user->set(User::getInstanceByID($id, true)); $instance->save(); }
public function testPreferences() { $user = User::getNewInstance('*****@*****.**', 'tester', $this->group); $user->setPreference('test', 'value'); $user->save(); $this->assertEqual($user->getPreference('test'), 'value'); // update preferences $user->setPreference('another', 'check'); $user->save(); ActiveRecordModel::clearPool(); $reloaded = User::getInstanceByID($user->getID(), true); $this->assertNotSame($user, $reloaded); $this->assertEqual($reloaded->getPreference('test'), 'value'); $this->assertEqual($reloaded->getPreference('another'), 'check'); }
protected function getInstance($record, CsvImportProfile $profile) { $fields = $profile->getSortedFields(); if (isset($fields['User']['ID'])) { $instance = User::getInstanceByID($record[$fields['User']['ID']], true); } else { if (isset($fields['User']['email'])) { $instance = User::getInstanceByEmail($record[$fields['User']['email']]); } } if (empty($instance)) { $instance = User::getNewInstance(''); $instance->isEnabled->set(true); } $this->setLastImportedRecordName($instance->email->get()); return $instance; }
protected function getInstance($record, CsvImportProfile $profile) { pp('User address import get instance'); $fields = $profile->getSortedFields(); if (isset($fields['UserAddress']['ID'])) { $instance = ActiveRecordModel::getInstanceByID('UserAddress', $record[$fields['UserAddress']['ID']], true); } else { if (isset($fields['AddressUser']['ID'])) { $owner = User::getInstanceByID($record[$fields['AddressUser']['ID']], true); } else { if (isset($fields['AddressUser']['email'])) { $owner = User::getInstanceByEmail($record[$fields['AddressUser']['email']]); } } } if (isset($owner)) { if ($profile->isColumnSet('AddressUser.isShipping')) { $type = $this->evalBool(strtolower($record[$profile->getColumnIndex('AddressUser.isShipping')])) ? 'ShippingAddress' : 'BillingAddress'; } else { $type = 'BillingAddress'; } $owner->loadAddresses(); } if (empty($instance)) { if (empty($owner)) { return; } $isDefault = $profile->isColumnSet('AddressUser.isDefault') && $this->evalBool(strtolower($record[$profile->getColumnIndex('AddressUser.isDefault')])); if ($isDefault) { $field = 'default' . $type; $addressType = $owner->{$field}->get(); $instance = $addressType->userAddress->get(); } if (empty($addressType)) { $instance = UserAddress::getNewInstance(); $addressType = call_user_func_array(array($type, 'getNewInstance'), array($owner, $instance)); if ($isDefault) { $owner->{$field}->set($addressType); } } $addressType->userAddress->set($instance); $instance->addressType = $addressType; } return $instance; }
/** * @role update */ public function update() { $user = User::getInstanceByID((int) $this->request->get('id'), true); $user->loadAddresses(); return $this->save($user); }
public function update() { $userID = $this->getApplication()->getRequest()->get('userID'); $orderID = $this->getApplication()->getRequest()->get('ID'); if (intval($userID) == 0 || intval($orderID) == 0) { throw new Exception("User and Order ID not set"); } $user = User::getInstanceByID($userID); $order = CustomerOrder::getInstanceById($orderID); $user->load(); $user->loadAddresses(); $order->loadAll(); return $this->apiActionGetOrdersBySelectFilter(select(eq(f('CustomerOrder.ID'), $this->getApplication()->getRequest()->get('ID')))); }
public function generateTestInvoices() { return; ClassLoader::import('application.model.category.*'); ClassLoader::import('application.model.product.*'); $config = ActiveRecordModel::getApplication()->getConfig(); $config->set('RECURRING_BILLING_PAYMENT_DUE_DATE_DAYS', 7); $config->save(); // data $userID = 110; $product1ID = 339; $recurringProductPeriodID = 19; // ~ // create first order $user = User::getInstanceByID($userID, true); $product1 = Product::getInstanceByID($product1ID, true); $order = CustomerOrder::getNewInstance($user); $order->save(true); $rpp = RecurringProductPeriod::getInstanceByID($recurringProductPeriodID); $item = $order->addProduct($product1, 1, true); $item->save(); $recurringItem = RecurringItem::getNewInstance($rpp, $item); $recurringItem->setupPrice->set(100); $recurringItem->periodPrice->set(25); $recurringItem->save(); $order->finalize(); // generate invoices echo '<pre>Invoices for {CustomerOrder ID:' . $order->getID() . '}:', "\n"; $now = time(); for ($ts = $now; $ts < strtotime('+20 months', $now); $ts = $ts + 60 * 60 * 24) { $z = CustomerOrder::generateRecurringInvoices(date('Y-m-d', $ts)); foreach ($z as $id) { echo '{CustomerOrder ID:' . $id . '}', "\n"; } } die('-done-</pre>'); }
/** * @role create */ public function create() { ActiveRecord::beginTransaction(); $user = User::getInstanceByID((int) $this->request->get('customerID'), true, true); $user->loadAddresses(); $order = CustomerOrder::getNewInstance($user); $status = CustomerOrder::STATUS_NEW; $order->status->set($status); $order->isFinalized->set(0); $order->capturedAmount->set(0); $order->totalAmount->set(0); $order->dateCompleted->set(new ARSerializableDateTime()); $order->currency->set($this->application->getDefaultCurrency()); foreach (array('billingAddress' => 'defaultBillingAddress', 'shippingAddress' => 'defaultShippingAddress') as $orderField => $userField) { if ($user->{$userField}->get()) { $user->{$userField}->get()->userAddress->get()->load(); $address = clone $user->{$userField}->get()->userAddress->get(); $address->save(); $order->{$orderField}->set($address); } } $response = $this->save($order); ActiveRecord::commit(); return $response; }
public function saveQuickEdit() { $user = User::getInstanceByID((int) $this->request->get('id'), true); $validator = UserController::createUserFormValidator($this, $user, true); if ($validator->isValid()) { $email = $this->request->get('email'); $password = $this->request->get('password'); if ($user && $email != $user->email->get() && User::getInstanceByEmail($email) || !$user && User::getInstanceByEmail($email)) { return new JSONResponse(false, 'failure', $this->translate('_err_this_email_is_already_being_used_by_other_user')); } if ($groupID = (int) $this->request->get('UserGroup')) { $group = UserGroup::getInstanceByID((int) $groupID); } else { $group = null; } if (!$user) { $user = User::getNewInstance($email, $password, $group); } $user->loadRequestData($this->request); $user->userGroup->set($group); if (!empty($password)) { $user->setPassword($password); } $user->save(); return $this->quickEditSaveResponse($user); } else { return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_could_not_save_user_details')); } }
public function create() { $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>'); $request = $this->application->getRequest(); $orderID = $request->get('orderID'); $currencyID = $request->get('currencyID'); $amount = $request->get('amount'); $method = $request->get('method'); $gatewayTransactionID = $request->get('gatewayTransactionID'); if (intval($orderID) <= 0) { throw new Exception('Order ID is required'); } if (!isset($currencyID) || !isset($method) || !isset($gatewayTransactionID)) { throw new Exception('Complete required fields : currencyID, method, gatewayTransactionID'); } $transaction_result = new TransactionResult(); $transaction_result->currency->set($currencyID); // = $currencyID; $transaction_result->amount->set($amount); //= $amount; $transaction_result->gatewayTransactionID->set($gatewayTransactionID); // = $gatewayTransactionID; $transaction_result->setTransactionType(TransactionResult::TYPE_SALE); $order = CustomerOrder::getInstanceById($orderID); $order->loadAll(); $order_array = $order->toArray(); $user = User::getInstanceByID($order_array['userID']); $user->load(); $order->user->set($user); if ($current_transaction = Transaction::getInstance($order, $gatewayTransactionID)) { $current_transaction->method->set($method); $current_transaction->save(); } else { $new_transaction = Transaction::getNewInstance($order, $transaction_result); $new_transaction->method->set($method); $new_transaction->save(); if (!$this->finalizeOrder($order, $user)) { // Create new order for current user $new_order = CustomerOrder::getNewInstance($user); $new_order->beginTransaction(); $new_order->save(); $new_order->commit(); } } $parser = $this->getParser(); $apiFieldNames = $parser->getApiFieldNames(); $f = new ARSelectFilter(); $f->mergeCondition(new EqualsCond(new ARFieldHandle('Transaction', 'orderID'), $orderID)); $transactions = ActiveRecordModel::getRecordSetArray('Transaction', $f); $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>'); if (false && count($transactions) == 0) { throw new Exception('Transactions not found'); } while ($transaction = array_shift($transactions)) { $transaction_response = $response->addChild('transaction'); foreach ($transaction as $k => $v) { if (in_array($k, $apiFieldNames)) { $transaction_response->addChild($k, htmlentities($v)); } } } return new SimpleXMLResponse($response); }
public function filter() { $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>'); $parser = $this->getParser(); $customers = User::getRecordSetArray('User', $parser->getARSelectFilter(), true); // $addressFieldNames = array_keys(ActiveRecordModel::getSchemaInstance('UserAddress')->getFieldList()); $addressFieldNames = array('firstName', 'lastName', 'address1', 'address2', 'city', 'stateName', 'postalCode', 'phone'); $userFieldNames = $parser->getApiFieldNames(); foreach ($customers as $customer) { $customerNode = $response->addChild('customer'); foreach ($userFieldNames as $fieldName) { $customerNode->addChild($fieldName, is_string($customer[$fieldName]) ? $customer[$fieldName] : ''); } // todo: join? how?? m?! $u = User::getInstanceByID($customer['ID'], true); $u->loadAddresses(); // default billing and shipping addreses foreach (array('defaultShippingAddress', 'defaultBillingAddress') as $addressType) { if (is_numeric($customer[$addressType . 'ID'])) { $address = $u->defaultBillingAddress->get()->userAddressID->get(); foreach ($addressFieldNames as $addressFieldName) { $customerNode->addChild($addressType . '_' . $addressFieldName, $address->{$addressFieldName}->get()); } } } $this->mergeUserEavFields($customerNode, $u); $this->clear($u); } return new SimpleXMLResponse($response); }