/**
  *  Javascript strings Localization wrapper for Drupal
  * @param $locale
  */
 public function l10n($locale)
 {
     $strings = DruniqueAPIUtil::call('page_blocks.json', ['tag' => 'javascript'], $locale);
     $strings = Hash::combine($strings, '{s}.title', '{s}.content');
     $this->set(['result' => $strings, '_serialize' => 'result']);
     $this->response->cache('-1 minute', '+1 days');
 }
 /**
  * Get Item drupal content for admin
  * @param $sku
  * @return null
  */
 protected function getItemDrupal($sku)
 {
     if (empty($sku)) {
         return null;
     }
     $drupal = null;
     DruniqueAPIUtil::getData(['api_url' => 'product.json', 'params' => ['sku' => $sku], 'tag' => 'product_' . $sku, 'locale' => 'en_US', 'duration' => 'long'], $drupal);
     return $drupal;
 }
 public function updateSystemSetting()
 {
     App::import('Model', 'SystemSetting');
     $system_setting = new SystemSetting();
     $value = $this->data['new_val'];
     $result = $system_setting->saveSetting('allow_expedited_shipping', $value);
     if (!is_numeric($value)) {
         $this->sendError(500, DruniqueAPIUtil::content('Not A Number', $this->DruniqueAPI->page_data));
         return;
     }
     $this->sendSuccess(DruniqueAPIUtil::content('Expedited Shipping ' . (!$value ? 'Disabled' : 'Enabled') . '.', $this->DruniqueAPI->page_data));
 }
 /**
  * Send via mandrill template
  *
  * $data needs:
  * 	- template_name
  * 	- template_content
  * 	- template_content_field_name
  * 	- subject
  * 	- from_presenter_id
  * 	- from_email
  * 	- from_name
  * 	- to array
  * 		- name
  * 		- email
  * 	- img_url
  * 	- template_name
  *  - tag
  *
  *
  * @throws Exception
  * @throws Mandrill_Error
  */
 public function sendTemplate()
 {
     $data = $this->request->data;
     try {
         App::import('model', 'TeamCommunication');
         $this->TeamCommunication = new TeamCommunication();
         App::import('model', 'TeamCommunicationRestriction');
         $this->TeamCommunicationRestriction = new TeamCommunicationRestriction();
         $is_restricted = $this->TeamCommunicationRestriction->isRestricted($data['from_presenter_id']);
         if ($is_restricted !== FALSE) {
             $this->sendError(500, DruniqueAPIUtil::content('Restricted', $this->DruniqueAPI->page_data));
         } else {
             $mandrill = new Mandrill(MANDRILL_API_KEY);
             $template_name = $data['template_name'];
             $template_content = array(array('name' => $data['template_content_field_name'], 'content' => $data['template_content']));
             $to = array();
             $merge_vars = array();
             $tag = $data['from_email'] . "-" . $data['tag'] . "-" . date('Y-m-d H:i:s');
             foreach ($data['to'] as $value) {
                 if ($this->TeamCommunicationRestriction->isRestricted($value['email'], 'receive')) {
                     continue;
                 }
                 $to[] = array('name' => $value['name'], 'email' => $value['email']);
                 $merge_vars[] = array('rcpt' => $value['email'], 'vars' => array(array('name' => 'FNAME', 'content' => $value['name']), array('name' => 'PRS', 'content' => $value['prs']), array('name' => 'LIFETIME_PRS', 'content' => $value['lifetime_prs']), array('name' => 'NEW_REC_STATUS', 'content' => $value['recognized_status']), array('name' => 'FAST_START_END', 'content' => '01/12/2015'), array('name' => 'LIFETIME_REMAINING', 'content' => '10.00'), array('name' => 'REMAINING_PRS', 'content' => '10.00'), array('name' => 'REMAINING_CoWS', 'content' => '10.00'), array('name' => 'REMAINING_QFL', 'content' => '0'), array('name' => 'REMAINING_CiWS', 'content' => '0')));
             }
             $message = array('from_email' => $data['from_email'], 'from_name' => $data['from_name'], 'to' => $to, 'headers' => array('Reply-To' => $data['from_email']), 'track_opens' => TRUE, 'track_clicks' => TRUE, 'auto_text' => TRUE, 'auto_html' => NULL, 'inline_css' => NULL, 'url_strip_qs' => NULL, 'preserve_recipients' => FALSE, 'view_content_link' => NULL, 'bcc_address' => $data['from'], 'tracking_domain' => NULL, 'signing_domain' => NULL, 'return_path_domain' => NULL, 'merge' => TRUE, 'global_merge_vars' => array(array('name' => 'PROFILEIMAGEURL', 'content' => $data['img_url']), array('name' => 'DATE', 'content' => date('m/d/Y')), array('name' => 'PRESENTER_FNAME', 'content' => $data['from_first_name']), array('name' => 'RECOGNIZED_STATUS', 'content' => 'Black')), 'merge_vars' => $merge_vars);
             $async = TRUE;
             $mandrill->messages->sendTemplate($template_name, $template_content, $message, $async);
             //store email
             $this->TeamCommunication->create();
             $this->TeamCommunication->set('presenter_id', $data['from_presenter_id']);
             $this->TeamCommunication->set('tag', $tag);
             $this->TeamCommunication->set('content', $data['template_content']);
             $this->TeamCommunication->set('created', date('Y-m-d H:i:s'));
             $this->TeamCommunication->save();
         }
         $this->sendSuccess(TRUE);
     } catch (Mandrill_Error $e) {
         // Mandrill errors are thrown as exceptions
         error_log('A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage());
         // A mandrill error occurred: Mandrill_Unknown_Subaccount - No subaccount exists with the id 'customer-123'
         $this->sendError(500, FALSE);
     }
 }
 public function orderSearch($search_type, $search_term)
 {
     $this->data = $this->request->data;
     if (empty($search_term)) {
         $this->sendError(500, DruniqueAPIUtil::content('Empty Search', $this->DruniqueAPI->page_data));
     }
     if (empty($this->data['user_id'])) {
         $this->sendError(500, DruniqueAPIUtil::content('Need a user id', $this->DruniqueAPI->page_data));
     } else {
         $user_id = $this->data['user_id'];
         if (!empty($this->data['presenter_id'])) {
             $presenter_id = $this->data['presenter_id'];
         } else {
             $presenter_id = NULL;
         }
         switch ($search_type) {
             case 'purchaser':
                 $result = $this->Order->getOrderHistoryByPurchaser($user_id, $presenter_id, $search_term);
                 break;
             case 'email':
                 $result = $this->Order->getOrderHistoryByEmail($user_id, $presenter_id, $search_term);
                 break;
             case 'shipto':
                 $result = $this->Order->getOrderHistoryByShipto($user_id, $presenter_id, $search_term);
                 break;
             case 'party':
                 $result = $this->Order->getOrderHistoryByParty($user_id, $presenter_id, $search_term);
                 break;
             case 'month':
                 $result = $this->Order->getOrderHistoryByMonth($user_id, $presenter_id, $search_term);
                 break;
             case 'default':
                 $result = $this->Order->getOrderHistoryByMonth($user_id, $presenter_id);
                 break;
         }
         if (!empty($result)) {
             $this->sendSuccess($result);
         } else {
         }
     }
 }
 /**
  * Get drupal data
  * $config = [
  *   'api_url' => 'page_data.json',
  *   'duration' => 'short',
  *   'caching'  => true,
  *   'locale'   => 'en_US
  * ];
  * @param $config
  * @param $data
  * @return null
  */
 public function getData($config, &$data)
 {
     if (empty($config)) {
         return null;
     }
     /**
      * Get defaults
      */
     $config = array_merge($this->getDefaultConfig(), $config);
     /**
      * Setup params
      */
     if (empty($config['params'])) {
         $config['params'] = ['tag' => $config['action'] . '-page'];
     }
     $data = DruniqueAPIUtil::call($config['api_url'], $config['params'], $config['locale']);
 }
示例#7
0
 /**
  * Wrapper of CakeEmail object creation and submission.
  * @param $emailData
  * @param string $templateName
  * @param string $to
  * @param string $subjectBlockName
  * @param string $tag
  * @param string $locale
  * @param bool $debug
  * @param array $emailOptions
  * @return string
  * @throws Exception
  */
 public static function sendEmail($emailData, $templateName = '', $to = '', $subjectBlockName = '', $tag = '', $locale = 'en-US', $debug = false, $emailOptions = array())
 {
     if (empty($templateName) || empty($to) || empty($subjectBlockName)) {
         CakeLog::error('CRITICAL EXEPTION: In email library.');
         CakeLog::error('Empty argument passed to email sender.');
         throw new BadMethodCallException('Empty argument passed to email sender.', 1);
         return false;
     }
     // Since getting the data from Drupal happens in-line we need to check
     // for errors by seeing if we only get log_info back and nothing else.
     if (!empty($tag)) {
         $drupalData = array();
         DruniqueAPIUtil::getData(['api_url' => 'email_text.json', 'params' => ['tag' => $tag], 'locale' => $locale], $drupalData);
         if (sizeof($drupalData) <= 1) {
             CakeLog::error('CRITICAL EXEPTION: In email library.');
             CakeLog::error('Unable to get view variables from CMS.');
             throw new Exception('Unable to get view variables from CMS.', 1);
             return false;
         }
         $emailData['email_text'] = $drupalData;
     }
     $email = new CakeEmail('default');
     $subject = DruniqueAPIUtil::content($subjectBlockName, $emailData['email_text']);
     $subject = preg_replace('/[\\pZ\\pC]/u', ' ', $subject);
     if ($debug) {
         $email->transport('Debug');
     }
     // Make sure format is set correctly based on existence of templates.
     $format = 'both';
     $htmlTemplateExists = is_readable(APP . "View/Emails/html/{$templateName}.ctp");
     $textTemplateExists = is_readable(APP . "View/Emails/text/{$templateName}.ctp");
     if (!$htmlTemplateExists && !$textTemplateExists) {
         CakeLog::error('CRITICAL ERROR: In email library.');
         CakeLog::error("Unable to find email template named {$templateName}.ctp");
         return false;
     } elseif (!$htmlTemplateExists && $textTemplateExists) {
         $format = 'text';
     } elseif ($htmlTemplateExists && !$textTemplateExists) {
         $format = 'html';
     }
     $email->template($templateName, 'default')->emailFormat($format)->to($to)->subject(html_entity_decode($subject, ENT_QUOTES))->viewVars($emailData);
     if (isset($emailOptions['bcc'])) {
         $email->bcc($emailOptions['bcc']);
     }
     if (isset($emailOptions['cc'])) {
         $email->cc($emailOptions['cc']);
     }
     try {
         $response = $email->send();
         if ($debug) {
             return $response;
         }
         if ($response) {
             $result = 'Email was sent successfully';
         } else {
             $result = 'Email failed to send without exceptions';
             CakeLog::error('CRITICAL ERROR: Email library failed to send an email without exception.');
             Cakelog::error(print_r($email, true));
         }
     } catch (Exception $e) {
         $result = 'Email failed with exception: ' . print_r($e->getMessage(), true);
         CakeLog::error('CRITICAL ERROR: In email library.');
         CakeLog::error($e->getMessage());
     }
     return $result;
 }
 public function sendInvite($partyId = null)
 {
     $result = $this->Party->partyFromId($partyId);
     $partyData = $result['Party'];
     $siteurl = $this->Session->read('siteurl');
     $email_frm_type = !empty($this->data['emailFormType']) ? $this->data['emailFormType'] : 'invite';
     if (empty($this->presenterId)) {
         $presenter = $this->Presenter->loadFromWebsite($siteurl->site_url);
     } else {
         $presenter = $this->Presenter->presenterFromUserId($this->userId);
     }
     if (!empty($this->data['email'])) {
         $userLocale = $this->User->userLocale($presenter['Presenter']['user_id']);
         $language = $party['hostess']['language'];
         $email_data = ["id" => $partyId, "name" => h($this->data['name']), "presenter_name" => h($presenter['User']['first_name'] . " " . $presenter['User']['last_name']), "presenter_email" => h($presenter['User']['Email']['email']), "event_desc" => h($partyData['event_desc']), "site_url" => h($presenter['PresenterSite']['site_url']), "shareUrl" => $this->data['emailFormUrl']];
         YouniqueEmail::queueEmail($email_data, 'en_us_newparty_' . $email_frm_type, $this->data['email'], 'You Have Been Invited to Party', 'sendInvite-page', $userLocale);
         // $this->sendPartyInviteToPerson($formData, $presenter, $this->data['email']);
         $this->sendSuccess(true);
     }
     $this->sendError(500, array("messages" => DruniqueAPIUtil::content('Invitation could not be sent', $this->DruniqueAPI->page_data)));
 }
 /**
  * Backorders v2 UI - Returns an array containing the item name from Drupal
  * If the returned value is false, the sku name was not found.
  * If the returned value is a string, an error has occured and the string is error message
  * @param $locale
  * @return array | boolean:false | string
  */
 public function getItemName($locale)
 {
     $criteria = ['contain' => ['ParentItems'], 'conditions' => ['Item.sku' => $this->sku]];
     try {
         $item = $this->Item->find('first', $criteria);
         // update to work with DruniqueAPIUtil::drupalName
         $item['Item']['ParentItems'] = $item['ParentItems'];
         unset($item['ParentItems']);
         $item_name = DruniqueAPIUtil::drupalName($item, $locale);
     } catch (Exception $e) {
         return $e->getMessage();
     }
     // if Drupal didn't return anything use the $item object if possible
     if (empty($item_name)) {
         if (empty($item)) {
             return false;
         }
         $p_name = $item['Item']['ParentItems']['name'];
         $item_name = (empty($p_name) ? '' : $p_name . ' - ') . $item['Item']['name'];
     }
     // put the item name into an array
     $data['Item'] = array('name' => $item_name);
     return $data;
 }
示例#10
0
 public function admin_searchLooks()
 {
     $look_id = isset($this->data['look_id']) && !empty($this->data['look_id']) ? $this->data['look_id'] : NULL;
     $look_name = isset($this->data['look_name']) && !empty($this->data['look_name']) ? $this->data['look_name'] : NULL;
     $start_date = isset($this->data['start_date']) && !empty($this->data['start_date']) ? $this->data['start_date'] : NULL;
     $end_date = isset($this->data['end_date']) && !empty($this->data['end_date']) ? $this->data['end_date'] : NULL;
     $page = isset($this->data['page']) && !empty($this->data['page']) ? $this->data['page'] : 0;
     if (is_null($look_id) && is_null($look_name) && is_null($start_date) && is_null($end_date)) {
         $this->sendError(500, DruniqueAPIUtil::content('Empty Search', $this->DruniqueAPI->page_data));
         return;
     }
     $conditions = [];
     $conditions['look_status_id'] = Look::STATUS_ACTIVE;
     if (!is_null($look_id)) {
         $conditions['Look.id'] = $look_id;
     }
     if (!is_null($look_name)) {
         $conditions['name LIKE'] = "%" . $look_name . "%";
     }
     if (!is_null($start_date) && !empty($start_date)) {
         $conditions['created >='] = $start_date;
     }
     if (!is_null($end_date) && !empty($end_date)) {
         $conditions['created <='] = $end_date;
     }
     $looks = $this->Look->find('all', ['conditions' => $conditions, 'contain' => ["User", 'Picture', 'LookMedia'], 'page' => $page, 'limit' => 50, 'order' => 'created desc']);
     $results = [];
     foreach ($looks as $value) {
         $results[] = ['id' => $value['Look']['id'], 'img' => !empty($value['Picture']['reference']) ? $value['Picture']['reference'] : $value['LookMedia'][0]['reference'], 'name' => $value['Look']['name'], 'creator_id' => $value['User']['id'], 'creator' => $value['User']['first_name'] . ' ' . $value['User']['last_name'], 'created' => $value['Look']['created'], 'love_it_count' => $value['Look']['likes']];
     }
     $this->sendSuccess($results);
 }
示例#11
0
 public function profile($userId)
 {
     $this->requirePresenterLoggedIn();
     $this->User->id = $userId;
     if ($this->User->belongsToPresenter($this->presenterId)) {
         $user = $this->User->find("first", array("contain" => array("Email", "Address" => array("State", "Country"), "Phone"), "conditions" => array("User.id" => $userId)));
         $profile = array("id" => $user['User']['id'], "first_name" => $user['User']['first_name'], "last_name" => $user['User']['last_name'], "name" => $user['User']['first_name'] . " " . $user['User']['last_name'], "user_default_locale" => $user['User']['user_default_locale'], "facebook_id" => $user['User']['facebook_id'], "largeimage" => $user['User']['largeimage'], "address" => array("address1" => $user['Address']['address1'], "address2" => $user['Address']['address2'], "address3" => $user['Address']['address3'], "city" => $user['Address']['city'], "postal_code" => strtoupper($user['Address']['postal_code']), "state" => $user['Address']['State']['name'], "country" => $user['Address']['Country']['name']), "phone" => $user['Phone']['phone'], "email" => $user['Email']['email']);
         $this->sendSuccess($profile);
     } else {
         $this->sendError(500, DruniqueAPIUtil::content('Unkonwn User', $this->DruniqueAPI->page_data));
     }
 }
 public function admin_addAccomplishment()
 {
     App::import('model', 'AdminUserAudit');
     $this->AdminUserAudit = new AdminUserAudit();
     App::import('model', 'Accomplishment');
     $this->Accomplishment = new Accomplishment();
     $user_id = $this->data['user_id'];
     $presenter = $this->Presenter->presenterFromUserId($user_id);
     $presenter_id = $presenter['Presenter']['id'];
     $accomplishment = $this->data['accomplishment'];
     $admin_user = $this->Session->read('admin_user')->id;
     $date_added = $this->data['datetime'];
     if (!$user_id || !$accomplishment) {
         $this->sendError(500, DruniqueAPIUtil::content('Missing required parameter', $this->DruniqueAPI->page_data));
         return;
     }
     switch ($accomplishment) {
         case 'yellow':
         case 'pink':
         case 'blue':
         case 'green':
         case 'orange':
         case 'purple':
         case 'black':
             if (!$this->Accomplishment->accomplishmentExistsForUser("statusadvancement", $user_id, $accomplishment)) {
                 if (!$presenter) {
                     $this->sendError(500, DruniqueAPIUtil::content('There was an error', $this->DruniqueAPI->page_data));
                     return;
                 }
                 $result = $this->Accomplishment->presenterStatusAdvancement($presenter, $accomplishment, $date_added);
                 if (!$result) {
                     $this->sendError(500, DruniqueAPIUtil::content('There was an error', $this->DruniqueAPI->page_data));
                     return;
                 }
             } else {
                 $this->sendError(500, DruniqueAPIUtil::content('Accomplishment already exists', $this->DruniqueAPI->page_data));
                 return;
             }
             break;
         case 'faststart':
             if (!$this->Accomplishment->accomplishmentExistsForUser("faststart", $user_id)) {
                 $this->Accomplishment->fastStart($presenter, $date_added);
             } else {
                 $this->sendError(500, DruniqueAPIUtil::content('Accomplishment already exists', $this->DruniqueAPI->page_data));
                 return;
             }
             break;
         case 'party':
             App::import('model', 'Party');
             $this->Party = new Party();
             $parties = $this->Party->find('all', ['conditions' => ['party_total >=' => 1000, 'presenter_id' => $presenter_id]]);
             if (empty($parties)) {
                 $this->sendError(500, DruniqueAPIUtil::content('No matching parties', $this->DruniqueAPI->page_data));
                 return;
             }
             foreach ($parties as $key => $value) {
                 if (!$this->Accomplishment->accomplishmentExistsForUser("party1000", $user_id, $value['Party']['id'])) {
                     //gotta get the party
                     $party = $this->Party->partyFromId($value['Party']['id']);
                     $party['Presenter']['User']['id'] = $party['Presenter']['user_id'];
                     $this->Accomplishment->party1000($party, $date_added);
                 }
             }
             break;
         default:
             $this->sendError(500, DruniqueAPIUtil::content('Invalid accomplishment', $this->DruniqueAPI->page_data));
             return;
             break;
     }
     //log who did it
     $admin_data = array('admin_user_id' => $admin_user, 'reference_name' => 'accomplishment.reference_id', 'reference_id' => $accomplishment, 'old_value' => '', 'new_value' => $accomplishment, 'notes' => "Admin tool used to add accomplishment");
     $this->AdminUserAudit->save($admin_data);
     $this->sendSuccess(DruniqueAPIUtil::content('Accomplishment added', $this->DruniqueAPI->page_data));
 }
 private function _cancelOrder($orderId)
 {
     //load the order
     $order = $this->Order->loadPaymentDetails($orderId);
     //save array of entries created to roll them back if need be
     $halfPriceItemsCreated = array();
     $yCashCreated = array();
     $refundFailedFlag = FALSE;
     //refund any half price items used on order
     $items = array();
     foreach ($order['OrderCustomer']['OrderItem'] as $itemValue) {
         $items[] = $itemValue;
         //creates an array of coupons used on the order
     }
     //refunds each coupon used
     foreach ($items as $key => $value) {
         if (count($value['CouponPresenterUser']) > 0) {
             foreach ($value['CouponPresenterUser'] as $couponPresenterUser) {
                 $halfPriceItemsCreated[] = $this->Order->OrderCustomer->OrderItem->CouponPresenterUser->saveCreate(array("CouponPresenterUser" => array("coupon_presenter_id" => $couponPresenterUser['coupon_presenter_id'], "user_id" => $couponPresenterUser['user_id'], "reference_id" => $couponPresenterUser['reference_id'], "user_visible" => (int) $couponPresenterUser['user_visible'], "date_added" => date('Y-m-d H:i:s'), "expiration_date" => "0000-00-00")));
             }
         }
     }
     //refund ycash and credit card pmts
     $payments = $order['OrderPayment'];
     if (count($payments) > 0) {
         foreach ($payments as $value) {
             switch ($value['order_payment_type_id']) {
                 case OrderPayment::TYPE_LEDGER:
                     //y cash
                     //						TODO: TEST THIS!!
                     //						//get original record
                     //						$productCredit = $this->ProductCredit->find("first", array(
                     //							"conditions"=>array(
                     //								"id"=>$value['transactionid']
                     //							)
                     //						));
                     //
                     //						$methodId 		= $productCredit['ProductCredit']['product_credit_entry_type_id'];
                     //						$typeId 		= $productCredit['ProductCredit']['product_credit_type_id'];
                     //						$marketId 		= $productCredit['ProductCredit']['market_id'];
                     //						$presenterId 	= $productCredit['ProductCredit']['presenter_id'];
                     //						$userId 		= $productCredit['ProductCredit']['user_id'];
                     //						$cost 			= Money::fromFloat($productCredit['ProductCredit']['amount']);
                     //						$entryUser 		= $productCredit['ProductCredit']['entry_user'];
                     //						$referenceId 	= $productCredit['ProductCredit']['reference_id'];
                     //
                     //						$yCashCreated = $this->ProductCredit->credit($methodId, $typeId, $marketId, $presenterId, $userId, $cost, $entryUser,$referenceId);
                     $yCashCreated = $this->_refundYCash($value['transactionid']);
                     break;
                 case OrderPayment::TYPE_OXXO:
                     $order_paid = $value['order_payment_status_id'];
                     if ($order_paid == OrderPayment::STATUS_PENDING) {
                         $refundFailedFlag == false;
                         break;
                     }
                     if ($order_paid == OrderPayment::STATUS_SUCCESS) {
                         $amount = $value['amount'];
                         $typeId = ProductCredit::TYPE_REFUND;
                         $methodId = ProductCredit::METHOD_SYSTEM;
                         $marketId = $order['Order']['order_market_id'];
                         $presenterId = $order['Order']['presenter_id'];
                         $userId = $order['Order']['user_id'];
                         $cost = $value['amount'];
                         $entryUser = '******';
                         $referenceId = $orderId;
                         $result = $this->ProductCredit->credit($methodId, $typeId, $marketId, $presenterId, $userId, $cost, $entryUser, $referenceId);
                         $refundFailedFlag == false;
                     }
                     break;
                 case OrderPayment::TYPE_CREDITCARD:
                     //credit card
                 //credit card
                 default:
                     //will also catch paypal payments
                     $currency = $this->Market->getCurrencyType($order['Order']['order_market_id']);
                     $refundResult = $this->_processRefund($value['transactionid'], $value['amount'], $currency, $value['order_payment_processor_id'], $orderId);
                     if (!$refundResult) {
                         $refundFailedFlag = TRUE;
                     }
                     break;
             }
         }
     }
     //$last_quote_date = ($this->Session->check('last_quote_date') ? $this->Session->read('last_quote_date') : null);
     $this->Order->create_negative_invoice($orderId);
     if ($refundFailedFlag !== TRUE) {
         //no errors
         //check for order promos that may need to be rolled back
         $productCreditToVoid = $this->ProductCredit->find("first", array("conditions" => array("reference_id" => $orderId, "product_credit_type_id" => ProductCredit::TYPE_PROMOCREDIT)));
         if (!empty($productCreditToVoid)) {
             $this->ProductCredit->read('', $productCreditToVoid['ProductCredit']['id']);
             $this->ProductCredit->set(array("product_credit_status_type_id" => ProductCredit::STATUS_VOIDED));
             $this->ProductCredit->save();
         }
         //change the order status to cancelled which means the order had not shipped yet
         $this->Order->id = $orderId;
         $this->Order->saveField("order_status_id", Order::STATUS_CANCELLED);
         $this->OrderItem->cancelLineItems($order['OrderCustomer']['id']);
         // New Netsuite compatible cancellation.
         $this->Order->setDynamicData($orderId, 'netsuite_cancel', 'pending', false, true);
         //set royalty to zero
         $this->RoyaltiesEarned->read('', $order['RetailRoyalty']['id']);
         $this->RoyaltiesEarned->set("point_amount", 0);
         $this->RoyaltiesEarned->set("amount", 0);
         $this->RoyaltiesEarned->set("date_paid", date('Y-m-d H:i:s'));
         $this->RoyaltiesEarned->save();
         $this->sendSuccess(TRUE);
     } else {
         //errors
         //roll back ycash, half price items
         foreach ($yCashCreated as $value) {
             if (isset($value['id'])) {
                 $this->ProductCredit->delete($value['id']);
             }
         }
         foreach ($halfPriceItemsCreated as $value) {
             if (isset($value['CouponPresenterUser']['id'])) {
                 $this->Order->OrderCustomer->OrderItem->CouponPresenterUser->delete($value['CouponPresenterUser']['id']);
             }
         }
         $this->sendError(500, DruniqueAPIUtil::content('Refund failed', $this->DruniqueAPI->page_data));
     }
 }
示例#14
0
 /**
  * Update promos on order items
  *  - and Add drupal Item Names
  *
  * @param $o
  * @param string $locale
  */
 private function updatePromosAddDrupal(&$o, $locale = 'en_US')
 {
     $this->PromotionalProduct = ClassRegistry::init('PromotionalProduct');
     $this->NsWarehouse = ClassRegistry::init('NsWarehouse');
     $this->Item = ClassRegistry::init('Item');
     foreach ($o['OrderCustomer']['OrderItem'] as $ik => &$item) {
         /**
          * Set backorder restock date
          */
         if (!empty($item['OrderItemRestock'][0]['restock_date']) && $item['order_item_hold_code_id'] == OrderItemHoldCode::BACKORDERED) {
             $item['estimated_date'] = $item['OrderItemRestock'][0]['restock_date'];
         } else {
             $item['estimated_date'] = null;
         }
         $wid = $item['ns_warehouse_id'];
         $date = $item['date_created'];
         $bo_date = $this->NsWarehouse->backOrderStartDate($date, $item['Item']['sku'], $wid);
         if (!empty($bo_date)) {
             $item['backorder_start'] = $bo_date;
         }
         /**
          * Set drupal data
          */
         $item['Item']['name'] = DruniqueAPIUtil::drupalName($item, $locale);
         $promo = $this->PromotionalProduct->find('first', ['conditions' => ['reward_sku' => $item['Item']['sku']]]);
         $item['Item']['PromotionalProduct'] = $promo['PromotionalProduct'];
     }
 }
示例#15
0
 public function createECBAccomplishment($userToReceive, $eligibleStatus, $yearmonth)
 {
     $page_data = NULL;
     $usable_userLocale = empty($userToReceive['User']['user_default_locale']) ? 'en_US' : $userToReceive['User']['user_default_locale'];
     DruniqueAPIUtil::getData(['api_url' => 'page_blocks.json', 'params' => ['tag' => 'createECBAccomplishment-page'], 'tag' => "createECBAccomplishment-page_" . $usable_userLocale, 'locale' => $usable_userLocale, 'duration' => 'long'], $page_data);
     $userName = $userToReceive['User']['first_name'] . " " . $userToReceive['User']['last_name'];
     switch ($eligibleStatus) {
         case 5:
             $accomplishmentType = "ecbgreen";
             $accomplishmentMessage = DruniqueAPIUtil::content('eliteconsistencyaccomplishment_0', $page_data, $userName);
             $fullaccomplishmentType = "fullecbgreen";
             $fullaccomplishmentMessage = DruniqueAPIUtil::content('eliteconsistencyaccomplishment_1', $page_data, $userName);
             break;
         case 6:
             $accomplishmentType = "ecborange";
             $accomplishmentMessage = DruniqueAPIUtil::content('eliteconsistencyaccomplishment_2', $page_data, $userName);
             $fullaccomplishmentType = "fullecborange";
             $fullaccomplishmentMessage = DruniqueAPIUtil::content('eliteconsistencyaccomplishment_3', $page_data, $userName);
             break;
     }
     //Give the presenter an accomplishment for their efforts
     $this->saveCreate(array('type' => $accomplishmentType, 'bragger' => 1, 'user_id' => $userToReceive['User']['id'], 'message' => $accomplishmentMessage, 'datetime' => date('Y-m-d h:i:s'), 'reference_id' => $yearmonth, 'facebook_id' => '-1'));
     //Has the presenter earned all four months? Give them another accomplishment
     $countECB = $this->find('count', array('conditions' => array('user_id' => $userToReceive['User']['id'], 'type' => $accomplishmentType)));
     if ($countECB == 4) {
         $this->saveCreate(array('type' => $fullaccomplishmentType, 'bragger' => 1, 'user_id' => $userToReceive['User']['id'], 'message' => $fullaccomplishmentMessage, 'datetime' => date('Y-m-d h:i:s'), 'facebook_id' => '-1'));
     }
 }
 /**
  * Set express checkout
  */
 public function setExpressPayment()
 {
     $prices = $this->prices(TRUE);
     if (empty($prices)) {
         $this->sendError(500, DruniqueAPIUtil::content('no price info', $this->DruniqueAPI->page_data));
     }
     $amount = number_format($prices['total']['charge']->amount / 100, 2);
     $marketId = $this->request->data['market_id'];
     $market = $this->Market->find("first", array("fields" => array("currency"), "conditions" => array("id" => $marketId)));
     $currency = $market['Market']['currency'];
     //get presenter site url for the return url
     $presenter_id = $this->request->data["sponsor_id"];
     $presenter_site = $this->Presenter->PresenterSite->find('first', array("conditions" => array("presenter_id" => $presenter_id)));
     $presenter_site_url = $presenter_site['PresenterSite']['site_url'];
     $expressPayment = $this->Payment->setExpressPayment($amount, $currency, $presenter_site_url);
     if ($expressPayment) {
         $this->sendSuccess($expressPayment);
     } else {
         $this->sendError(500, DruniqueAPIUtil::content('cannot create paypal trans', $this->DruniqueAPI->page_data));
     }
 }
示例#17
0
 /**
  * Bullet method with string replacement
  * @param $title
  * @param $index
  * @param null $args
  * @return string
  */
 public function bullet_r($title, $index, $args = null)
 {
     $bullet = $this->bullet($title);
     if (!empty($bullet) && isset($bullet[$index])) {
         $bullet = $bullet[$index];
     } else {
         if (!empty($data)) {
             DruniqueAPIUtil::log_error($data, $title);
         }
         return $title;
     }
     $arguments = func_get_args();
     return htmlspecialchars_decode($this->parse($bullet, array_slice($arguments, 2)));
 }
示例#18
0
 public function updateSystemSetting()
 {
     App::import('Model', 'SystemSetting');
     $system_setting = new SystemSetting();
     $value = $this->data['new_qty'];
     $result = $system_setting->saveSetting('snap_orders_qty', $value);
     if (!is_numeric($value)) {
         $this->sendError(500, DruniqueAPIUtil::content('Not A Number', $this->DruniqueAPI->page_data));
         return;
     }
     $this->sendSuccess(DruniqueAPIUtil::content('New value saved', $this->DruniqueAPI->page_data));
 }