container = $container; } public function handle($options) { foreach ($this->getFullTariffMap() as $action) { $actionCode = $action['action_code']; foreach ($action['tariffs'] as $tariff) { $tariffCode = $tariff['tariff_code']; if (isset($options['actions'][$actionCode]['tariffs'][$tariffCode])) { continue; } $options['actions'][$actionCode]['tariffs'][$tariffCode] = array('categories' => array()); } } return parent::handle($options); } public function renderSection() { ?> getFullTariffMap() as $action) { $this->renderAction($action); } ?>
getSettingName() . '[actions][' . $action['action_code'] . ']'; ?> display_settings(array( 'type' => 'select', 'label' => 'Multi select', 'id' => $prefix . '[type]', 'name' => $prefix . '[type]', 'vals' => $this->getActionTypes(), 'value' => $action['type'], )) ?> display_settings(array( 'type' => 'select', 'label' => 'User type', 'id' => $prefix . '[user_type]', 'name' => $prefix . '[user_type]', 'value' => $action['user_type'], 'vals' => $this->getUserTypes(), )); ?> display_settings(array( // 'type' => 'text', // 'label' => 'Price from', // 'id' => $prefix . '[price_from]', // 'name' => $prefix . '[price_from]', // 'value' => 0, // 'default' => $action['price_from'] // )); // ?> display_settings(array( // 'type' => 'text', // 'label' => 'Price to', // 'id' => $prefix . '[price_to]', // 'name' => $prefix . '[price_to]', // 'value' => 0, // 'default' => $action['price_to'] // )); // ?> renderTariff($tariff, $action); } } protected function renderTariff($tariff, $action) { $prefix = $this->getSettingName() . '[actions][' . $action['action_code'] . '][tariffs][' . $tariff['tariff_code'] . ']'; ?> display_settings(array( 'type' => 'multiselect', 'label' => 'Multi select', 'id' => $prefix . '[categories]', 'name' => $prefix . '[categories]', 'vals' => $this->getCategoryMap(), 'value' => $tariff['categories'], )); ?> __('None', 'admitadtracking'), AdmitadParameterStrategy::USER_TYPE_NEW => __('New user', 'admitadtracking'), AdmitadParameterStrategy::USER_TYPE_OLD => __('Old user', 'admitadtracking'), ); } protected function getActionTypes() { $types = array( __('Not active', 'admitadtracking'), __('Sale', 'admitadtracking'), ); return $types; } protected function getActionDefaultOptions() { return array('tariffs' => array(), 'type' => null, 'price_from' => null, 'price_to' => null, 'user_type' => null); } protected function getTariffDefaultOptions() { return array('categories' => array()); } protected function getDefaults() { return array('actions' => array()); } protected function getFullTariffMap() { $data = $this->container->getAdmitadManager()->getAdvertiserInfo(); $optionsMap = $this->container->getSettings()->get('actions', 'actions') ?: array(); $map = array(); foreach ($data['actions'] as $actionData) { $actionCode = $actionData['action_code']; foreach ($actionData['tariffs'] as $tariffData) { $tariffCode = $tariffData['tariff_code']; if (isset($optionsMap[$actionCode]['tariffs'][$tariffCode])) { $map[$actionCode]['tariffs'][$tariffCode] = $optionsMap[$actionCode]['tariffs'][$tariffCode]; } } if (!isset($optionsMap[$actionCode])) { continue; } foreach ($optionsMap[$actionCode] as $key => $value) { if ($key == 'tariffs') { continue; } $map[$actionCode][$key] = $value; } } foreach ($data['actions'] as $action) { $actionCode = $action['action_code']; foreach ($this->getActionDefaultOptions() as $key => $value) { if (!isset($map[$actionCode][$key])) { $map[$actionCode][$key] = $value; } } foreach ($action['tariffs'] as $tariff) { $tariffCode = $tariff['tariff_code']; if (!isset($map[$actionCode]['tariffs'][$tariffCode])) { $map[$actionCode]['tariffs'][$tariffCode] = $this->getTariffDefaultOptions(); } $map[$actionCode]['tariffs'][$tariffCode] = array_merge($tariff, $map[$actionCode]['tariffs'][$tariffCode]); } $map[$actionCode] = array_merge($action, $map[$actionCode]); } return $map; } protected function getCategoryMap() { $map = array(); foreach ($this->getCategories() as $category) { $map[$category->term_id] = str_repeat(' . ', $category->depth) . $category->name; } return $map; } protected function getCategories() { $categories = array(); $roots = array(); foreach (get_terms('product_cat') as $category) { $categories[$category->term_id] = $category; $category->children = array(); if (!$category->parent) { array_push($roots, $category); continue; } if (isset($categories[$category->parent]) and $categories[$category->parent]->children) { array_push($categories[$category->parent]->children, $category); } } return $this->getWithChildren($roots); } protected function getWithChildren($categories, $level = 0) { $result = array(); foreach ($categories as $category) { $category->depth = $level; array_push($result, $category); foreach ($this->getWithChildren($category->children, $level + 1) as $child) { array_push($result, $child); } } return $result; } }