/** * Sends the tracking information to mailchimp if we have the tracking ids * Logs errors * @param $store_id * @param string $store_name * @param int $order_id * @param int $total_amount * @param int $tax_amount * @param int $shipping_amount * @param array $products * @return bool */ public static function sendOrderInformations($store_id, $store_name = "Store name", $order_id = 0, $total_amount = 0, $tax_amount = 0, $shipping_amount = 0, $products = array(0 => array("product_id" => 0, "sku" => "", "product_name" => "", "category_id" => 0, "category_name" => "", "qty" => 1.0, "cost" => 0.0))) { // log the errors to a file JLog::addLogger(array('text_file' => 'com_cmc_ecom360.php')); $session = JFactory::getSession(); $mc_cid = $session->get('mc_cid', ''); $mc_eid = $session->get('mc_eid', ''); if (!$mc_cid && !$mc_eid) { JLog::add('No cid and eid specified for the request', JLOG::ERROR); return false; } $order = array(); $order["id"] = $order_id; $order["email_id"] = $mc_eid; $order["total"] = (double) $total_amount; $order["shipping"] = (double) $shipping_amount; $order["tax"] = (double) $tax_amount; $order["store_id"] = $store_id; $order["store_name"] = $store_name; $order["campaign_id"] = $mc_cid; // Optional $order["items"] = $products; $api = new cmcHelperChimp(); $api->ecommOrderAdd($order); if ($api->errorCode) { JLog::add($api->errorMessage, JLOG::ERROR, $api->errorCode); return false; } return true; }
/** * Delete the user subscription * * @return void */ public function delete() { JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN')); $user = JFactory::getUser(); $appl = JFactory::getApplication(); $input = $appl->input; $listId = $input->getString('listid'); $db = JFactory::getDBO(); $query = $db->getQuery(true); if ($user->guest) { $appl->enqueueMessage(JText::_('COM_CMC_YOU_NEED_TO_BE_LOGGED_IN_TO_UNSUBSCRIBE')); } $query->select('*')->from('#__cmc_users')->where('(' . $db->qn('user_id') . '=' . $db->q($user->get('id')) . ' OR email = ' . $db->q($user->email) . ')')->where($db->qn('list_id') . '=' . $db->q($listId)); $db->setQuery($query); $subscription = $db->loadObject(); if ($subscription) { $chimp = new cmcHelperChimp(); if ($chimp->listUnsubscribe($listId, $subscription->email)) { $appl->enqueueMessage(JText::_('COM_CMC_YOU_WERE_SUCCESSFULLY_UNSUBSCRIBED')); } $query->clear('select'); $query->clear('from'); $query->delete('#__cmc_users'); $db->setQuery($query); $db->execute(); } $appl->redirect($_SERVER['HTTP_REFERER']); }
/** * Unsubscribes a user from the mailchimp list * * @param object $user - the user object * * @throws Exception * * @return bool|string */ public static function unsubscribeList($user) { $api = new cmcHelperChimp(); $api->listUnsubscribe($user->list_id, $user->email, true); if ($api->errorCode) { throw new Exception(JTEXT::_("COM_CMC_UNSUBSCRIBE_FAILED") . ": " . $api->errorMessage, $api->errorCode); } return true; }
/** * Gets the account details from mailchimp * * @return mixed */ public function getAccountDetails() { $cache = JFactory::getCache('mod_ccc_cmc_mailchimp', 'output'); $cache->setCaching(true); $details = $cache->get('details'); if (!$details) { $chimp = new cmcHelperChimp(); $data = $chimp->getAccountDetails(); $details = serialize($data); $cache->store($details, 'details'); } return unserialize($details); }
/** * Method to get the field input markup. * * @return string */ public function getInput() { $content = ''; $api = new cmcHelperChimp(); $lists = $api->lists(); $key = 'id'; $val = 'name'; $options[] = array($key => '', $val => '-- ' . JText::_('MOD_CMC_PLEASE_SELECT_A_LIST') . ' --'); foreach ($lists['data'] as $list) { $options[] = array($key => $list[$key], $val => $list[$val]); } $option = JFactory::getApplication()->input->get('option'); $controller = in_array($option, array('com_modules', 'com_advancedmodules')) ? 'module' : 'plugin'; $attribs = "onchange='submitbutton(\"{$controller}.apply\")'"; if ($options) { $content = JHtml::_('select.genericlist', $options, 'jform[params][listid]', $attribs, $key, $val, $this->value, $this->id); } return $content; }
/** * Create an array with mailchimps interest fields * * @param string $listId - the list id * * @return array|bool */ public static function getInterestsFields($listId) { $api = new cmcHelperChimp(); $interests = $api->listInterestGroupings($listId); $key = 'id'; $val = 'name'; $options = false; if ($interests) { foreach ($interests as $interest) { if ($interest['form_field'] != 'hidden') { $groups = ''; foreach ($interest['groups'] as $ig) { $groups .= $ig['name'] . '##' . $ig['name'] . '####'; } $groups = substr($groups, 0, -4); $options[] = array($key => $interest[$key] . ';' . $interest['form_field'] . ';' . $interest['name'] . ';' . $groups, $val => $interest[$val]); } } } return $options; }
/** * Checks if the current user exists in the mailchimp database * * @throws Exception * * @return void */ public function exist() { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $chimp = new cmcHelperChimp(); $input = JFactory::getApplication()->input; $form = $input->get('jform', '', 'array'); $mergeVars = CmcHelperList::mergeVars($form); $email = $mergeVars['EMAIL']; $listId = $form['cmc']['listid']; // Check if the user is in the list already $userlists = $chimp->listsForEmail($email); if ($userlists && in_array($listId, $userlists)) { $exist = true; $url = JRoute::_('index.php?option=com_cmc&task=subscription.update&email=' . $email . '&listid=' . $listId); } else { $exist = false; $url = ''; } echo json_encode(array('exists' => $exist, 'url' => $url)); jexit(); }
/** * Batch subscribe users * * @param string $list - the list to subscribe to * @param array $batch - the batch with users * * @return void */ private function batchSubscribe($list, $batch) { $appl = JFactory::getApplication(); $chimp = new cmcHelperChimp(); $status = $chimp->listBatchSubscribe($list, $batch); if ($status['error_count']) { foreach ($status['errors'] as $error) { $appl->enqueueMessage($error['message']); } } else { $appl->enqueueMessage(JText::_('COM_CMC_ADD_GROUP_SUCCESS')); } }
/** * Loads the interests * * @return mixed|string */ public function loadInterests() { $plugin = GetCmcTab::getPlugin(); $listid = $plugin->params->get('listid', ""); if (empty($listid)) { $content = '<div style="float:left;">' . JText::_('PLG_CMCCB_NO_INTEREST_GROUPS') . '</div>'; return $content; } $api = new cmcHelperChimp(); $interests = $api->listInterestGroupings($listid); $key = 'id'; $val = 'name'; $options = false; if ($interests) { foreach ($interests as $interest) { if ($interest['form_field'] != 'hidden') { $groups = ''; foreach ($interest['groups'] as $ig) { $groups .= $ig['name'] . '##' . $ig['name'] . '####'; } $groups = substr($groups, 0, -4); $options[] = array($key => $interest[$key] . ';' . $interest['form_field'] . ';' . $interest['name'] . ';' . $groups, $val => $interest[$val]); } } } $attribs = 'multiple="multiple" size="8"'; if ($options) { $content = JHtml::_('select.genericlist', $options, 'params[interests][]', $attribs, $key, $val, explode("|*|", $plugin->params->get('interests', ""))); } else { $content = '<div style="float:left;">' . JText::_('PLG_CMCCB_NO_INTEREST_GROUPS') . '</div>'; } return $content; }
/** * Checks if the user is already subscribed to the list * * @param string $listId - The listid * @param string $email - The E-Mail * * @return bool */ public static function isSubscribed($listId, $email) { // Check if user email already registered $chimp = new cmcHelperChimp(); $userlists = $chimp->listsForEmail($email); if ($userlists && in_array($listId, $userlists)) { return true; } else { return false; } }