public function sendMetrikaData() { $m = new Metrika(); $response = $m->run(); $data = array('YA_METRIKA_CART' => array('name' => 'YA_METRIKA_CART', 'flag' => 'basket', 'type' => 'action', 'class' => 1, 'depth' => 0, 'conditions' => array(array('url' => 'metrikaCart', 'type' => 'exact'))), 'YA_METRIKA_ORDER' => array('name' => 'YA_METRIKA_ORDER', 'flag' => 'order', 'type' => 'action', 'class' => 1, 'depth' => 0, 'conditions' => array(array('url' => 'metrikaOrder', 'type' => 'exact'))), 'YA_METRIKA_WISHLIST' => array('name' => 'YA_METRIKA_WISHLIST', 'flag' => '', 'type' => 'action', 'class' => 1, 'depth' => 0, 'conditions' => array(array('url' => 'metrikaWishlist', 'type' => 'exact')))); $ret = array(); $error = ''; if (Configuration::get('YA_METRIKA_TOKEN') != '') { if ($response) { $counter = $m->getCounter(); if (!empty($counter->counter->code)) { Configuration::UpdateValue('YA_METRIKA_CODE', $counter->counter->code, true); } $otvet = $m->editCounter(); if ($otvet->counter->id != Configuration::get('YA_METRIKA_NUMBER')) { $error .= $this->displayError($this->l('Saving the settings the meter is not the meter number is incorrect.')); } else { $tmp_goals = $m->getCounterGoals(); $goals = array(); foreach ($tmp_goals->goals as $goal) { $goals[$goal->name] = $goal; } $types = array('YA_METRIKA_ORDER', 'YA_METRIKA_WISHLIST', 'YA_METRIKA_CART'); foreach ($types as $type) { $conf = explode('_', $type); $conf = $conf[0] . '_' . $conf[1] . '_CELI_' . $conf[2]; if (Configuration::get($conf) == 0 && isset($goals[$type])) { $ret['delete_' . $type] = $m->deleteCounterGoal($goals[$type]->id); } elseif (Configuration::get($conf) == 1 && !isset($goals[$type])) { $params = $data[$type]; $ret['add_' . $type] = $m->addCounterGoal(array('goal' => $params)); } } } } elseif (!empty($m->errors)) { $error .= $this->displayError($m->errors); } } else { $error .= $this->displayError($this->l('The token for authorization is missing! Get the token and repeat!')); } if ($error == '') { $this->metrika_status .= $this->displayConfirmation($this->l('Data was successfully sent and saved! Code metrici updated pages automatically.')); } else { $this->metrika_status .= $error; } }
public function sendMetrikaData() { $m = new Metrika(); $response = $m->run(); $data = array('YA_METRIKA_CART' => array('name' => 'YA_METRIKA_CART', 'flag' => 'basket', 'type' => 'action', 'class' => 1, 'depth' => 0, 'conditions' => array(array('url' => 'metrikaCart', 'type' => 'exact'))), 'YA_METRIKA_ORDER' => array('name' => 'YA_METRIKA_ORDER', 'flag' => 'order', 'type' => 'action', 'class' => 1, 'depth' => 0, 'conditions' => array(array('url' => 'metrikaOrder', 'type' => 'exact'))), 'YA_METRIKA_WISHLIST' => array('name' => 'YA_METRIKA_WISHLIST', 'flag' => '', 'type' => 'action', 'class' => 1, 'depth' => 0, 'conditions' => array(array('url' => 'metrikaWishlist', 'type' => 'exact')))); $ret = array(); $error = ''; if (Configuration::get('YA_METRIKA_TOKEN') != '') { if ($response) { $counter = $m->getCounter(); if (!empty($counter->counter->code)) { Configuration::UpdateValue('YA_METRIKA_CODE', $counter->counter->code, true); } $otvet = $m->editCounter(); if ($otvet->counter->id != Configuration::get('YA_METRIKA_NUMBER')) { $error .= $this->displayError($this->l('Сохранение настроек счётчика не выполнено или номер счётчика неверен.')); } else { $tmp_goals = $m->getCounterGoals(); foreach ($tmp_goals->goals as $goal) { $goals[$goal->name] = $goal; } $types = array('YA_METRIKA_ORDER', 'YA_METRIKA_WISHLIST', 'YA_METRIKA_CART'); foreach ($types as $type) { $conf = explode('_', $type); $conf = $conf[0] . '_' . $conf[1] . '_CELI_' . $conf[2]; if (Configuration::get($conf) == 0 && isset($goals[$type])) { $ret['delete_' . $type] = $m->deleteCounterGoal($goals[$type]->id); } elseif (Configuration::get($conf) == 1 && !isset($goals[$type])) { $params = $data[$type]; $ret['add_' . $type] = $m->addCounterGoal(array('goal' => $params)); } } } } elseif (!empty($m->errors)) { $error .= $this->displayError($m->errors); } } else { $error .= $this->displayError($this->l('Токен для авторизации отсутствует! Получите токен и повторите!')); } if ($error == '') { $this->metrika_status .= $this->displayConfirmation($this->l('Данные успешно отправлены и сохранены! Код метрники обновится на страницах автоматически.')); } else { $this->metrika_status .= $error; } }