public function customValidation($attribute, $params) { if ($this->emailPhone != '' && $this->orderId != '') { $intCustomer = null; $objCustomer = null; $objCart = null; $found = 0; //Is this a customer email address, or possible an email attached to an SRO if (strtolower(substr($this->orderId, 0, 2)) == "s-") { $objSro = Sro::model()->findByAttributes(array('customer_email_phone' => $this->emailPhone, 'ls_id' => $this->orderId)); if (!$objSro instanceof SRO) { $this->addError($this->orderId, Yii::t('yii', 'Order/Email combination not found')); Yii::app()->clientScript->registerScript('orderalert', 'alert("Order/Email combination not found");'); } else { $this->orderType = CartType::sro; } } else { //Regular Order $objCustomer = Customer::LoadByEmail($this->emailPhone); if (!$objCustomer instanceof Customer) { $this->addError($this->emailPhone, Yii::t('yii', 'Email address not found')); Yii::app()->clientScript->registerScript('emailalert', 'alert("Email address not found");'); } else { $objCart = Cart::model()->findByAttributes(array('id_str' => $this->orderId, 'customer_id' => $objCustomer->id)); if (!$objCart instanceof Cart) { $this->addError($this->orderId, Yii::t('yii', 'Order/Email combination not found')); Yii::app()->clientScript->registerScript('orderalert', 'alert("Order/Email combination not found");'); } else { $this->orderType = CartType::order; } } } } }
public function validAccount($attribute, $param) { $objCustomer = Customer::LoadByEmail($this->email); if (!$objCustomer instanceof Customer) { $this->addError($attribute, Yii::t('global', 'Email address not found')); return; } $intQty = Yii::app()->db->createCommand("SELECT COUNT(*) from " . Wishlist::model()->tableName() . "\n\t\t\t\t\tWHERE\n\t\t\t\t\tcustomer_id=" . $objCustomer->id . " AND\n\t\t\t\t\tvisibility=" . Wishlist::PUBLICLIST . ";")->queryScalar(); if ($intQty == 0) { $this->addError($attribute, Yii::t('wishlist', 'No publicly searchable wish lists for this email address.')); return; } }
public function run() { $model = new LookupForm(); if (isset($_POST['LookupForm'])) { $model->attributes = $_POST['LookupForm']; if ($model->validate()) { //Because our validate already checks to see if it's a valid combination, we can trust loading here and just redir if ($model->orderType == CartType::order) { $objCustomer = Customer::LoadByEmail($model->emailPhone); $objCart = Cart::model()->findByAttributes(array('id_str' => $model->orderId, 'customer_id' => $objCustomer->id)); Yii::app()->controller->redirect($objCart->Link); } if ($model->orderType == CartType::sro) { $objSro = Sro::model()->findByAttributes(array('customer_email_phone' => $model->emailPhone, 'ls_id' => $model->orderId)); Yii::app()->controller->redirect($objSro->Link); } } } $this->render('index', array('model' => $model)); }
public function savePage($page) { switch ($page) { case 2: if (!_xls_get_conf('LIGHTSPEED_CLOUD', 0) > 0) { _xls_set_conf('LSKEY', strtolower(md5($this->LSKEY))); } _xls_set_conf('TIMEZONE', $this->TIMEZONE); Configuration::exportKeys($this->encryptionKey, $this->encryptionSalt); //Now that we have encryption keys written, save the account if we have it if (!empty($this->loginemail) && !empty($this->loginpassword)) { $objCustomer = Customer::LoadByEmail($this->loginemail); if (!$objCustomer instanceof Customer) { $objCustomer = new Customer(); $objCustomer->first_name = "Admin"; $objCustomer->last_name = "User"; $objCustomer->record_type = 1; $objCustomer->pricing_level = 1; $objCustomer->preferred_language = "en"; $objCustomer->currency = "USD"; $objCustomer->email = $this->loginemail; $objCustomer->mainphone = _xls_get_conf('STORE_PHONE'); } $objCustomer->password = _xls_encrypt($this->loginpassword); $objCustomer->allow_login = 2; $objCustomer->save(); } break; case 3: _xls_set_conf('STORE_NAME', $this->STORE_NAME); _xls_set_conf('EMAIL_FROM', $this->EMAIL_FROM); _xls_set_conf('STORE_ADDRESS1', $this->STORE_ADDRESS1); _xls_set_conf('STORE_ADDRESS2', $this->STORE_ADDRESS2); _xls_set_conf('STORE_CITY', $this->STORE_CITY); _xls_set_conf('STORE_STATE', $this->STORE_STATE); _xls_set_conf('STORE_COUNTRY', $this->STORE_COUNTRY); _xls_set_conf('STORE_ZIP', $this->STORE_ZIP); _xls_set_conf('STORE_HOURS', $this->STORE_HOURS); _xls_set_conf('STORE_PHONE', $this->STORE_PHONE); break; case 4: if (is_null($this->EMAIL_SMTP_SERVER)) { $this->EMAIL_SMTP_SERVER = ''; } if (is_null($this->EMAIL_SMTP_PORT)) { $this->EMAIL_SMTP_PORT = ''; } if (is_null($this->EMAIL_SMTP_USERNAME)) { $this->EMAIL_SMTP_USERNAME = ''; } if (is_null($this->EMAIL_SMTP_PASSWORD)) { $this->EMAIL_SMTP_PASSWORD = ''; } _xls_set_conf('EMAIL_SMTP_SERVER', $this->EMAIL_SMTP_SERVER); _xls_set_conf('EMAIL_SMTP_PORT', $this->EMAIL_SMTP_PORT); _xls_set_conf('EMAIL_SMTP_USERNAME', $this->EMAIL_SMTP_USERNAME); _xls_set_conf('EMAIL_SMTP_PASSWORD', _xls_encrypt($this->EMAIL_SMTP_PASSWORD)); _xls_set_conf('EMAIL_SMTP_SECURITY_MODE', $this->EMAIL_SMTP_SECURITY_MODE); break; } }
/** * Add an order for display * * @param string $passkey * @param string $strId * @param int $intDttDate * @param int $intDttDue * @param string $strPrintedNotes * @param string $strStatus * @param string $strEmail * @param string $strPhone * @param string $strZipcode * @param int $intTaxcode * @param float $fltShippingSell * @param float $fltShippingCost * @return string */ public function add_order($passkey, $strId, $intDttDate, $intDttDue, $strPrintedNotes, $strStatus, $strEmail, $strPhone, $strZipcode, $intTaxcode, $fltShippingSell, $fltShippingCost) { if (!$this->check_passkey($passkey)) { return self::FAIL_AUTH; } $objDocument = Document::LoadByIdStr($strId); if (!$objDocument instanceof Document) { $objDocument = new Document(); } else { // if cart already exists then delete the items foreach ($objDocument->documentItems as $item) { $item->qty = 0; $item->save(); $item->product->SetAvailableInventory(); $item->delete(); } } $objDocument->order_type = CartType::order; $objDocument->order_str = $strId; $objDocument->printed_notes = $strPrintedNotes; $objDocument->datetime_cre = date("Y-m-d H:i:s", trim($intDttDate)); $objDocument->datetime_due = date("Y-m-d H:i:s", trim($intDttDue)); $objDocument->fk_tax_code_id = $intTaxcode ? $intTaxcode : 0; $objDocument->status = $strStatus; $objCustomer = Customer::LoadByEmail($strEmail); if ($objCustomer instanceof Customer) { $objDocument->customer_id = $objCustomer->id; } $objCart = Cart::LoadByIdStr($strId); if ($objCart instanceof Cart) { $objDocument->cart_id = $objCart->id; } $objDocument->status = $strStatus; if (!$objDocument->save()) { Yii::log("SOAP ERROR : add_order " . print_r($objDocument->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); return self::UNKNOWN_ERROR; } if ($objCart instanceof Cart) { $objCart->document_id = $objDocument->id; $objCart->save(); } if (substr($strId, 0, 3) == "WO-") { Configuration::SetHighestWO(); } return self::OK; }
/** * This function will run parse an order that we get from Amazon MWS. * It saves orders of the customers to the DB. * @param $response ListOrderItemsResponse Contains the orders from Amazon * Marketplace WebService * @return void */ public function parseListOrders($response) { $checkDate = date("Y-m-d", strtotime($this->amazon_check_time)); $listOrdersResult = $response->getListOrdersResult(); if ($listOrdersResult->isSetOrders()) { $orders = $listOrdersResult->getOrders(); $orderList = $orders->getOrder(); foreach ($orderList as $order) { if ($order->isSetAmazonOrderId()) { $strOrderId = $order->getAmazonOrderId(); Yii::log("Found Amazon Order " . $strOrderId, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__); $objCart = Cart::LoadByIdStr($strOrderId); if (!$objCart instanceof Cart) { //We ignore orders we've already downloaded $objCart = new Cart(); $objCart->id_str = $strOrderId; $objCart->origin = 'amazon'; //We mark this as just a cart, not an order, because we download the items next $objCart->cart_type = CartType::cart; $objOrderTotal = $order->getOrderTotal(); Yii::log("Order total information " . print_r($objOrderTotal, true), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__); $objCart->total = $objOrderTotal->getAmount(); $objCart->currency = $objOrderTotal->getCurrencyCode(); $objCart->status = OrderStatus::Requested; $objCart->datetime_cre = $order->getPurchaseDate(); $objCart->modified = $order->getLastUpdateDate(); if (!$objCart->save()) { Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } //Since email from is Anonymous, we probably will have to create a shell record $objCustomer = Customer::LoadByEmail($order->getBuyerEmail()); if (!$objCustomer) { $customerName = $this->_getCustomerName($order->getBuyerName()); $objCustomer = new Customer(); $objCustomer->email = $order->getBuyerEmail(); $objCustomer->first_name = $customerName['first_name']; $objCustomer->last_name = $customerName['last_name']; $objCustomer->record_type = Customer::EXTERNAL_SHELL_ACCOUNT; $objCustomer->allow_login = Customer::UNAPPROVED_USER; $objCustomer->save(); } $objCart->customer_id = $objCustomer->id; if (!$objCart->save()) { Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } if ($order->isSetShippingAddress()) { $shippingAddress = $order->getShippingAddress(); $countrycode = Country::IdByCode($shippingAddress->getCountryCode()); if ($shippingAddress->isSetStateOrRegion()) { $objState = State::LoadByCode($shippingAddress->getStateOrRegion(), $countrycode); } $customerName = $this->_getCustomerName($shippingAddress->getName()); $config = array('address_label' => 'amazon', 'customer_id' => $objCustomer->id, 'first_name' => $customerName['first_name'], 'last_name' => $customerName['last_name'], 'address1' => $shippingAddress->getAddressLine1(), 'address2' => trim($shippingAddress->getAddressLine2() . " " . $shippingAddress->getAddressLine3()), 'city' => $shippingAddress->getCity(), 'state_id' => $objState->id, 'postal' => $shippingAddress->getPostalCode(), 'country_id' => $countrycode, 'phone' => $shippingAddress->getPhone()); $objCustAddress = CustomerAddress::findOrCreate($config); $objCustomer->default_billing_id = $objCustAddress->id; $objCustomer->default_shipping_id = $objCustAddress->id; $objCustomer->save(); $objCart->shipaddress_id = $objCustAddress->id; $objCart->billaddress_id = $objCustAddress->id; //Amazon doesn't provide billing data, just dupe if (!$objCart->save()) { Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } Yii::log("Looking for destination " . $objState->country_code . " " . $objState->code . " " . $shippingAddress->getPostalCode(), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__); $objDestination = Destination::LoadMatching($objState->country_code, $objState->code, $shippingAddress->getPostalCode()); if ($objDestination === null) { Yii::log("Did not find destination, using default in Web Store ", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__); $objDestination = Destination::getAnyAny(); } $objCart->tax_code_id = $objDestination->taxcode; $objCart->recalculateAndSave(); } if ($order->isSetShipServiceLevel()) { $strShip = $order->getShipServiceLevel(); //If we have a shipping object already, update it, otherwise create it if (isset($objCart->shipping)) { $objShipping = $objCart->shipping; } else { //create $objShipping = new CartShipping(); if (!$objShipping->save()) { Yii::log("Error saving shipping info for cart " . print_r($objShipping->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } } if ($order->isSetShipmentServiceLevelCategory()) { $strShip = $order->getShipmentServiceLevelCategory(); } $objShipping->shipping_module = get_class($this); $objShipping->shipping_data = $strShip; $objShipping->shipping_method = $this->objModule->getConfig('product'); $objShipping->shipping_cost = 0; $objShipping->shipping_sell = 0; $objShipping->save(); $objCart->shipping_id = $objShipping->id; if (!$objCart->save()) { Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } } //Because Amazon comes down with no payment info, just generate one here $objP = new CartPayment(); $objP->payment_method = $this->objModule->getConfig('ls_payment_method'); $objP->payment_module = get_class($this); $objP->payment_data = 'Amazon'; $objP->payment_amount = $objOrderTotal->getAmount(); $objP->datetime_posted = $order->getPurchaseDate(); if (!$objP->save()) { Yii::log("Error saving payment " . print_r($objP->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } $objCart->payment_id = $objP->id; if (!$objCart->save()) { Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } TaskQueue::CreateEvent('integration', get_class($this), 'ListOrderDetails', $objCart->id_str . "," . $checkDate); } } } } }