public static function optInSMS($userId) { $u = ClassRegistry::init('User'); //get the user $userId, $message $user = $u->find("first", array("contain" => array("SmsPhone"), "conditions" => array("User.id" => $userId))); //get the SMS record $SMS = ClassRegistry::init('Sms'); $smsRecord = $SMS->find('first', array('conditions' => array('user_id' => $user['User']['id']))); //get user's phone number $phone_number = $user['SmsPhone']['phone']; //set the opt-in message for the sms $message = "Younique Products\r\n\r\nWe've received notice that you wish to opt-in to receive recurring SMS texts. Reply YES to complete the opt-in process.\r\n\r\nReply STOP to stop.\r\n\r\nReply HELP for help.\r\n\r\nMessage & data rates may apply."; // this line loads the library include_once '../Vendor/twilio/sdk/Services/Twilio.php'; $client = new Services_Twilio(SmsUtil::$account_sid, SmsUtil::$auth_token); if ($smsRecord['Sms']['smsoptin'] == -2 && False) { try { $client->account->messages->create(array('From' => "+13853991960", 'To' => $phone_number, 'Body' => $message)); return "message sent"; } catch (Services_Twilio_RestException $e) { cakelog::error("------------------------------\n SMS message failed: \n To: " . $phone_number . "\n error: " . $e->getMessage() . "\n------------------------------"); return "SMS message failed"; } } return "User has not asked to sign up for SMS messages."; }
/** * Order shipment with packages for receipt * @param $order_id */ public function packages($order_id) { $packages = []; if (!empty($order_id)) { $shipments = $this->OrderShipment->find('all', ['contain' => ['OrderItem' => ['Item' => ['ItemContent']]], 'fields' => ['OrderShipment.id', 'OrderShipment.carrier', 'OrderShipment.tracking_number', 'OrderShipment.date_shipped'], 'conditions' => ['OrderShipment.order_id' => $order_id, 'OrderShipment.date_shipped IS NOT NULL']]); foreach ($shipments as $os) { $shipment = []; $shipment['tracking'] = Hash::extract($os, 'OrderShipment'); $shipment['tracking']['url'] = $this->OrderShipment->getTrackingLink($shipment['tracking']['tracking_number'], $shipment['tracking']['carrier']); $shipment['tracking']['date_shipped'] = date("m/d/Y", strtotime($shipment['tracking']['date_shipped'])); foreach ($os['OrderItem'] as $item) { cakelog::debug(print_r($item['Item'], true)); $name = !empty($item['Item']['ItemContent']['display_name']) ? $item['Item']['ItemContent']['display_name'] : $item['Item']['name']; $shipment['items'][] = ['name' => $name, 'qty' => $item['quantity']]; } $packages[] = $shipment; } } $this->set(['result' => $packages, '_serialize' => ['result']]); }
public function checkout() { $shipping_addresses = YouniqueAPI::call("/user/getUserShippingAddresses/" . $this->userId); cakelog::debug($this->Session->read('order.user_id')); $this->set('shipping_addresses', $shipping_addresses); cakelog::debug(print_r($shipping_addresses, true)); if ($this->Session->check('activate_link')) { $this->setWebsiteInfo($this->Session->read('activate_link')); } if ($this->isUserLoggedIn()) { $cart_items = $this->Session->read('shoppingcart'); foreach ($cart_items as $item) { if ($item['sku'] == 'US-91516-14') { $this->setWebsiteInfo(); break; } } } $bt_token = YouniqueAPI::call("/shoppingcart/getToken"); $this->set("bt_token", $bt_token); $this->set('consumption_check', $this->personalConsumptionCheck()); $processor = YouniqueAPI::call("/shoppingcart/determineProcessor/" . $this->marketId); $this->set("processor", $processor); $this->set("hideshopnav", true); //set to TRUE to activate PayPal Payments (not the cc processing, just the pay with PayPal option $paypal_active = FALSE; if (!empty($this->request->query['productcredits'])) { $this->set("productcredits", $this->request->query['productcredits']); } $sofort_authorized = YouniqueAPI::call("/user/topSofort/" . $this->presenterId); if ($sofort_authorized != 'FALSE') { $this->set('sofort_authorized', 'true'); } else { $this->set('sofort_authorized', 'false'); } $giro_authorized = YouniqueAPI::call("/user/topGiro/" . $this->presenterId); if ($giro_authorized != 'FALSE') { $this->set('giro_authorized', 'true'); } else { $this->set('giro_authorized', 'false'); } $this->set("paypal_active", $paypal_active); if ($this->isUserLoggedIn()) { $user_data = YouniqueAPI::call("user/getUserdata/" . $this->userId); if (isset($this->presenterMarketId) && $this->presenterMarketId != 0) { $temp_market = $this->presenterMarketId; } elseif (isset($user_data->User->user_default_locale)) { $temp_market = YouniqueAPI::call('language/marketFromLanguage/' . $user_data->User->user_default_locale)[0]; } } else { $temp_market = isset($this->marketId) ? $this->marketId : 1; } $user_default_locale = $this->Session->read('Config.language') ? $this->Session->read('Config.language') : 'en_US'; $this->set('user_default_locale', $user_default_locale); $this->set('temp_market', $temp_market); if (!empty($this->partyId)) { $this->set("referlink", $this->generateUrl(array("controller" => "party", "partyid" => $this->partyId, "action" => "index"), true)); } else { $this->set("referlink", $this->generateUrl(array("controller" => "products", "action" => "/"), true)); } }
/** * Add Free Items to Order * * @param Order $Model * @param null $id * @return bool */ public function addFreeItems(Order $Model, $id = null) { if (empty($id)) { $id = $Model->id; } $Model->id = $id; $order = $Model->loadDisplayDetails(); $this->OrderItem = ClassRegistry::init('OrderItem'); $this->Item = ClassRegistry::init('Item'); /** * Add Free items */ foreach ($this->free_items as $free_item) { $already_added = false; $shipment_id = null; $ns_warehouse_id = null; $qualifying_qty = 0; $item = $this->Item->find('first', ['conditions' => ['Item.sku' => $free_item['sku']], 'fields' => ['Item.id']]); /** * Check if free item is backordered */ if (!empty($free_item['ns_warehouse_id'])) { if ($this->OrderItem->NsWarehouse->backordered($free_item['sku'], $free_item['ns_warehouse_id'])) { $hold_code = OrderItemHoldCode::BACKORDERED; $item_type = OrderItemType::TYPE_BACK_ORDER; } else { $hold_code = OrderItemHoldCode::NONE; $item_type = OrderItemType::TYPE_RETAIL; } } /** * Check if market qualifies for item */ if ($free_item['market_id'] == null || $free_item['market_id'] == $order['Order']['order_market_id']) { $qualifying_market = true; } else { $qualifying_market = false; } /** * Check order if qualifies to add free item */ foreach ($order['OrderCustomer']['OrderItem'] as $order_item) { if (empty($free_item['qualifying'])) { $shipment_id = $order_item['order_shipment_id']; $ns_warehouse_id = $order_item['ns_warehouse_id']; } else { if (in_array($order_item['Item']['sku'], $free_item['qualifying'])) { if (!$this->OrderItem->NsWarehouse->backordered($order_item['Item']['sku'], $order_item['ns_warehouse_id'])) { $hold_code = OrderItemHoldCode::NONE; $item_type = OrderItemType::TYPE_RETAIL; //check to make sure we actually have stock of the free item in the warehouse if ($this->OrderItem->NsWarehouse->backordered($free_item['sku'], $order_item['ns_warehouse_id'])) { cakelog::debug('this free item is on backorder!'); $hold_code = OrderItemHoldCode::BACKORDERED; $item_type = OrderItemType::TYPE_BACK_ORDER; } else { $shipment_id = $order_item['order_shipment_id']; $ns_warehouse_id = $order_item['ns_warehouse_id']; } } $qualifying_qty += $order_item['quantity']; } } /** * Check if the free item has already been added */ if ($order_item['Item']['sku'] == $free_item['sku']) { $already_added = TRUE; } } /** * Add free item to shipment if not already added */ if (!empty($item) && $qualifying_market && !empty($shipment_id) && !$already_added && !empty($ns_warehouse_id)) { $this->OrderItem->clear(); if ($free_item['ns_warehouse_id'] == NULL) { $item_data = ['order_customer_id' => $order['OrderCustomer']['id'], 'order_shipment_id' => $shipment_id, 'order_item_hold_code_id' => $hold_code, 'item_id' => $item['Item']['id'], 'order_item_type_id' => $item_type, 'promotion_id' => 0, 'price' => 0, 'commission' => 0, 'quantity' => $qualifying_qty, 'extended_price' => 0, 'tax_amount' => 0, 'handling_fee' => 0, 'points' => 0, 'date_created' => date('Y-m-d H:i:s'), 'ns_warehouse_id' => $ns_warehouse_id]; } else { $item_data = ['order_customer_id' => $order['OrderCustomer']['id'], 'order_shipment_id' => $shipment_id, 'order_item_hold_code_id' => $hold_code, 'item_id' => $item['Item']['id'], 'order_item_type_id' => $item_type, 'promotion_id' => 0, 'price' => 0, 'commission' => 0, 'quantity' => $free_item['quantity'], 'extended_price' => 0, 'tax_amount' => 0, 'handling_fee' => 0, 'points' => 0, 'date_created' => date('Y-m-d H:i:s'), 'ns_warehouse_id' => $free_item['ns_warehouse_id']]; } $this->OrderItem->save($item_data); } } return true; }
public function shippingAddressList($userId) { $sql = "SELECT * FROM addresses WHERE user_id = {$userId}\r\n AND address_type_id IN (2, 3)\r\n ORDER BY address_type_id ASC"; $return = $this->query($sql); $State = ClassRegistry::init('State'); foreach ($return as $key => $address) { $state = $State->find('first', array('conditions' => ['id' => $address['addresses']['state_id']])); $state_name = strtolower($state['State']['name']); $return[$key]['addresses']['state_name'] = $state_name; } cakelog::Debug(print_r($return, true)); return $return; }