Exemple #1
0
 public function index()
 {
     $this->document->setTitle(Sumo\Language::getVar('APP_SHIPPINGPRODUCT_TITLE'));
     $this->document->addBreadcrumbs(array('href' => $this->url->link('common/apps', '', 'SSL'), 'text' => Sumo\Language::getVar('SUMO_ADMIN_APPS_DASHBOARD')));
     $this->document->addBreadcrumbs(array('text' => Sumo\Language::getVar('APP_SHIPPINGPRODUCT_TITLE')));
     $this->document->addScript('view/js/jquery/jquery.parsley.js');
     $this->data['stores'] = $this->model_settings_stores->getStores();
     $this->data['current_store'] = isset($this->request->get['store_id']) ? $this->request->get['store_id'] : 0;
     Sumo\Logger::info('Loading model settings');
     $this->load->appModel('Settings');
     if ($this->request->server['REQUEST_METHOD'] == 'POST') {
         $this->shippingproduct_model_settings->setSettings($this->data['current_store'], $this->request->post['settings']);
         $this->redirect($this->url->link('app/shippingproduct', '', 'SSL'));
     }
     $this->data['settings'] = $this->shippingproduct_model_settings->getSettings($this->data['current_store']);
     $this->load->model('localisation/geo_zone');
     $this->data['zones'] = $this->model_localisation_geo_zone->getGeoZones();
     $this->data['geo_zone_id'] = isset($this->request->get['geo_zone_id']) ? $this->request->get['geo_zone_id'] : $this->config->get('zone_id');
     $this->load->model('settings/stores');
     $this->data['tax'] = $this->model_settings_stores->getSettings($this->data['current_store'], 'tax_percentage');
     if (!is_array($this->data['tax']) || !count($this->data['tax']) || !isset($this->data['tax']['default'])) {
         $this->data['tax'] = $this->model_settings_general->getSetting('tax_percentage');
     }
     $this->template = 'index.tpl';
     $this->children = array('common/header', 'common/footer');
     $this->response->setOutput($this->render());
 }
Exemple #2
0
 public function setAppStatus($store_id, $active = 0)
 {
     try {
         $list = array();
         $list['app'] = $this->getAppId();
         $list['store'] = $store_id;
         Sumo\Database::query("DELETE FROM PREFIX_apps_active WHERE app_id = :app AND store_id = :store", $list);
         $list['active'] = $active;
         Sumo\Database::query("INSERT INTO PREFIX_apps_active SET app_id = :app, store_id = :store, active = :active", $list);
     } catch (\Exception $e) {
         Sumo\Logger::error('Changing app status failed: ' . print_r($e, true));
     }
 }
Exemple #3
0
$registry->set('weight', new Sumo\Weight($registry));
Sumo\Logger::info('Weight created');
// Length
$registry->set('length', new Sumo\Length($registry));
Sumo\Logger::info('Lenght created');
// User
$registry->set('user', new User($registry));
Sumo\Logger::info('User created');
// Front Controller
$controller = new Front($registry);
Sumo\Logger::info('Front created');
// Login
$controller->addPreAction(new Sumo\Action('common/home/login'));
Sumo\Logger::info('Front pre-action common/home/login added');
// Permission
$controller->addPreAction(new Sumo\Action('common/home/permission'));
Sumo\Logger::info('Front pre-action common/home/permission added');
// Router
if (isset($request->get['route'])) {
    $route = strtolower($request->get['route']);
    $action = new Sumo\Action($route);
    Sumo\Logger::info('Action created with route ' . htmlentities($route));
} else {
    $action = new Sumo\Action('common/home');
    Sumo\Logger::info('Action created with route common/home');
}
// Dispatch
$controller->dispatch($action, new Sumo\Action('error/not_found'));
Sumo\Logger::info('Dispatching action with fallback error/not_found');
// Output
$output = $response->output();
Exemple #4
0
 public function checkSettings($store_id = 0)
 {
     // update 1.0.1; language string for sofort
     Sumo\Language::getVar('APP_MOLLIE_CATALOG_SOFORT_DESCRIPTION');
     $check = self::query("SELECT value FROM PREFIX_translations WHERE key_id = (SELECT id FROM PREFIX_translations_keys WHERE name = 'APP_MOLLIE_CATALOG_SOFORT_DESCRIPTION') AND language_id = 1")->fetch();
     if (empty($check['value'])) {
         self::query("INSERT INTO PREFIX_translations SET value = 'Betaal met SoFort banking', key_id = (SELECT id FROM PREFIX_translations_keys WHERE name = 'APP_MOLLIE_CATALOG_SOFORT_DESCRIPTION'), language_id =1");
     }
     $data = $this->getSettings($store_id);
     if (!$data['enabled']) {
         return true;
     }
     unset($data['enabled']);
     if (empty($data['general']['api_key'])) {
         Sumo\Logger::warning('[Mollie] API Key is not set');
         return false;
     } else {
         include 'api.php';
         $test = new ModelApi($this->registry);
         try {
             $test->setKey($data['general']['api_key']);
         } catch (\Exception $e) {
             Sumo\Logger::warning('[Mollie] API Key is invalid');
             return false;
         }
         try {
             $testData = $test->callMethods();
             if (isset($testData['error'])) {
                 Sumo\Logger::warning('[Mollie] API Key is invalid, error returned from Mollie: ' . Sumo\Language::getVar('APP_MOLLIE_ERROR_' . strtoupper($response['error']['type'])));
                 return false;
             } else {
                 if (!count($testData['data'])) {
                     Sumo\Logger::warning('[Mollie] API Key is valid, but no payment options are available!');
                     return false;
                 } else {
                     $countDisabled = 0;
                     foreach ($testData['data'] as $list) {
                         if (!isset($data[$list['id']]['enabled']) || !$data[$list['id']]['enabled']) {
                             $countDisabled++;
                         }
                     }
                     if ($countDisabled == count($testData['data'])) {
                         Sumo\Logger::warning('[Mollie] There are no payment options enabled');
                         return false;
                     }
                 }
             }
         } catch (\Exception $e) {
             Sumo\Logger::warning('[Mollie] Unknown API error occured');
             return false;
         }
     }
     if (!isset($data['tax'])) {
         Sumo\Logger::warning('[Mollie] Tax is not set');
         return false;
     }
     if (empty($data['instructions'][$this->config->get('language_id')])) {
         Sumo\Logger::warning('[Mollie] Instructions for default language is not set');
         return false;
     }
     unset($data['instructions']);
     if (!count($data)) {
         return false;
     }
     return true;
 }
Exemple #5
0
 public function getProducts($data)
 {
     Sumo\Logger::info('getProducts: ' . print_r($data, true));
     $result = $search = array();
     if (isset($data['path'])) {
         $categories = explode('_', $data['path']);
         $category_id = end($categories);
     }
     if (!empty($data['data']['filter_category_id'])) {
         $category_id = $data['data']['filter_category_id'];
     }
     if (empty($data['data']['start'])) {
         $data['data']['start'] = 0;
     }
     if (empty($data['data']['limit'])) {
         $data['data']['limit'] = 15;
     }
     if (empty($data['data']['sort'])) {
         $data['data']['sort'] = 'p.sort_order';
     }
     if (empty($data['data']['order']) || !in_array($data['data']['order'], array('ASC', 'DESC'))) {
         $data['data']['order'] = 'ASC';
     }
     $cache = 'wsp_plist_product_category_' . md5(json_encode($data));
     $result = Sumo\Cache::find($cache);
     if (is_array($result) && count($result)) {
         Sumo\Logger::info('Got products from cache: ' . print_r($result, true));
         return $result;
     }
     if ($data['type'] == 'category') {
         $sql = 'SELECT p.product_id
         FROM PREFIX_product AS p';
         if ($data['data']['sort'] == 'pd.name') {
             $sql .= ' LEFT JOIN PREFIX_product_description pd
             ON (p.product_id = pd.product_id)';
         }
         $sql .= '
         LEFT JOIN PREFIX_product_to_category AS ptc
             ON ptc.product_id = p.product_id
         WHERE ptc.category_id = :category_id
             AND p.status = 1
         GROUP BY p.product_id';
         if ($data['data']['sort'] == 'pd.name') {
             $sql .= ' ORDER BY pd.name ' . $data['data']['order'];
         }
         $values = array('category_id' => $category_id);
     }
     if (!empty($sql)) {
         $total = $this->fetchAll($sql, $values);
         $result['total'] = count($total);
         $sql .= ' LIMIT ' . $data['data']['start'] . ',' . $data['data']['limit'];
         $products = $this->fetchAll($sql, $values);
     }
     if (is_array($products)) {
         foreach ($products as $p) {
             $product = $this->getProduct($p['product_id']);
             $result[] = $product;
         }
     }
     Sumo\Cache::set($cache, $result);
     Sumo\Logger::info('Put products in cache: ' . print_r($result, true));
     return $result;
 }
 protected final function render()
 {
     Sumo\Logger::info('rendering app now');
     foreach ($this->children as $child) {
         $this->data[basename($child)] = $this->getChild($child);
     }
     $this->registry->set('currentApp', $this->getCurrentApp());
     $dir = 'apps/' . strtolower($this->registry->get('currentApp'));
     $template = $this->template;
     $this->template = DIR_TEMPLATE . $this->config->get('template') . '/template/' . $dir . '/' . $this->template;
     // First try if the full/exact path is given
     if (!file_exists($this->template)) {
         //trigger_error('Error 1: Could not load template ' . $this->template . '!', E_USER_ERROR);
         $this->template = str_replace($this->config->get('template') . '/template/', 'base/template/', $this->template);
     }
     if (!file_exists($this->template)) {
         //trigger_error('Error 2: Could not load template ' . $this->template . '!', E_USER_ERROR);
         $dir = DIR_HOME . $dir;
         $test = explode('/', trim(DIR_APPLICATION, '/'));
         $test = end($test);
         if ($test == 'admin') {
             $dir .= '/admin/';
         } else {
             $dir .= '/catalog/';
         }
         $dir .= 'view/template/';
         $this->template = $dir . $template;
     }
     if (file_exists($this->template)) {
         extract($this->data);
         ob_start();
         require $this->template;
         $this->output = ob_get_contents();
         ob_end_clean();
         Sumo\Logger::info('Rendering for ' . strtolower($this->registry->get('currentApp')) . ' finished; loaded template ' . $this->template);
         return str_replace('</head>', '<meta name="generator" content="SumoStore" /></head>', $this->output);
     } else {
         trigger_error('Error: Could not load template ' . $this->template . ' for ' . strtolower($this->registry->get('currentApp')) . '!', E_USER_ERROR);
         if (isset($this->data['header'])) {
             $this->output .= $this->data['header'];
         }
         if (isset($this->data['footer'])) {
             $this->output .= $this->data['footer'];
         }
         return $this->output;
     }
 }
Exemple #7
0
 public function getProducts($data)
 {
     $result = $search = array();
     if (isset($data['path'])) {
         $categories = explode('_', $data['path']);
         $category_id = end($categories);
     }
     if (!empty($data['data']['filter_category_id'])) {
         $category_id = $data['data']['filter_category_id'];
     }
     if (empty($data['data']['start'])) {
         $data['data']['start'] = 0;
     }
     if (empty($data['data']['limit'])) {
         $data['data']['limit'] = 15;
     }
     if (empty($data['data']['sort'])) {
         $data['data']['sort'] = 'p.sort_order';
     }
     if (empty($data['data']['order']) || !in_array($data['data']['order'], array('ASC', 'DESC'))) {
         $data['data']['order'] = 'ASC';
     }
     $cache = 'wsp_plist_product_category_' . md5(json_encode($data));
     $result = Sumo\Cache::find($cache);
     if (is_array($result) && count($result)) {
         Sumo\Logger::info('Got products from cache: ');
         return $result;
     }
     if ($data['type'] == 'category') {
         $sql = 'SELECT p.product_id, COUNT(*) AS total
         FROM PREFIX_product AS p';
         if ($data['data']['sort'] == 'pd.name') {
             $sql .= ' LEFT JOIN PREFIX_product_description pd
             ON (p.product_id = pd.product_id)';
         }
         if (!empty($data['data']['filter_filter'])) {
             $sql .= ' LEFT JOIN PREFIX_product_attribute AS pa ON pa.product_id = p.product_id ';
         }
         $sql .= '
         LEFT JOIN PREFIX_product_to_category AS ptc
             ON ptc.product_id = p.product_id
         WHERE ptc.category_id = :category_id
             AND p.status = 1 ';
         if (!empty($data['data']['filter_filter'])) {
             $filter = array();
             if (is_array($data['data']['filter_filter'])) {
                 foreach ($data['data']['filter_filter'] as $id => $unused) {
                     if (!is_numeric($id) || empty($id)) {
                         continue;
                     }
                     $filter[] = $id;
                 }
             } else {
                 if (is_numeric($data['data']['filter_filter']) && !empty($data['data']['filter_filter'])) {
                     $filter[] = $data['data']['filter_filter'];
                 }
             }
             if (count($filter)) {
                 $sql .= ' AND pa.attribute_id IN (' . implode(',', $filter) . ') ';
             }
         }
         $sql .= '
         GROUP BY p.product_id ';
         switch ($data['data']['sort']) {
             case 'pd.name':
                 $sql .= 'ORDER BY pd.name ' . $data['data']['order'];
                 break;
             case 'p.price':
                 $sql .= 'ORDER BY p.price ' . $data['data']['order'];
                 break;
             case 'p.model':
                 $sql .= 'ORDER BY p.model_2 ' . $data['data']['order'];
                 break;
             default:
                 $sql .= 'ORDER BY p.sort_order ' . $data['data']['order'];
                 break;
         }
         $values = array('category_id' => $category_id);
     }
     if ($data['type'] == 'category_path') {
         $categoriesData = $this->fetchAll("SELECT category_id FROM PREFIX_category_path WHERE path_id = :id", array('id' => $category_id));
         $categories = array();
         foreach ($categoriesData as $item) {
             $categories[] = $item['category_id'];
         }
         $sql = 'SELECT p.product_id, COUNT(*) AS total
         FROM PREFIX_product AS p';
         if ($data['data']['sort'] == 'pd.name') {
             $sql .= ' LEFT JOIN PREFIX_product_description pd
             ON (p.product_id = pd.product_id)';
         }
         if (!empty($data['data']['filter_filter'])) {
             $sql .= ' LEFT JOIN PREFIX_product_attribute AS pa ON pa.product_id = p.product_id ';
         }
         $sql .= '
         LEFT JOIN PREFIX_product_to_category AS ptc
             ON ptc.product_id = p.product_id
         WHERE ';
         if (count($categories)) {
             $sql .= 'ptc.category_id IN(' . implode(',', $categories) . ')
             AND p.status = 1 ';
         } else {
             $sql .= 'p.status = 1 ';
         }
         if (!empty($data['data']['filter_filter'])) {
             $filter = array();
             if (is_array($data['data']['filter_filter'])) {
                 foreach ($data['data']['filter_filter'] as $id => $unused) {
                     if (!is_numeric($id) || empty($id)) {
                         continue;
                     }
                     $filter[] = $id;
                 }
             } else {
                 if (is_numeric($data['data']['filter_filter']) && !empty($data['data']['filter_filter'])) {
                     $filter[] = $data['data']['filter_filter'];
                 }
             }
             if (count($filter)) {
                 $sql .= ' AND pa.attribute_id IN (' . implode(',', $filter) . ') ';
             }
         }
         $sql .= '
         GROUP BY p.product_id ';
         switch ($data['data']['sort']) {
             case 'pd.name':
                 $sql .= 'ORDER BY pd.name ' . $data['data']['order'];
                 break;
             case 'p.price':
                 $sql .= 'ORDER BY p.price ' . $data['data']['order'];
                 break;
             case 'p.model':
                 $sql .= 'ORDER BY p.model_2 ' . $data['data']['order'];
                 break;
             default:
                 $sql .= 'ORDER BY p.sort_order ' . $data['data']['order'];
                 break;
         }
         $values = array();
     }
     if ($data['type'] == 'manufacturer') {
         $sql = 'SELECT p.product_id, COUNT(*) AS total
         FROM PREFIX_product AS p';
         if ($data['data']['sort'] == 'pd.name') {
             $sql .= ' LEFT JOIN PREFIX_product_description pd
             ON (p.product_id = pd.product_id)';
         }
         if (!empty($data['data']['filter_filter'])) {
             $sql .= ' LEFT JOIN PREFIX_product_attribute AS pa ON pa.product_id = p.product_id ';
         }
         $sql .= '
         LEFT JOIN PREFIX_product_to_category AS ptc
             ON ptc.product_id = p.product_id
         WHERE p.manufacturer_id = :manufacturer_id
             AND p.status = 1 ';
         if (!empty($data['data']['filter_filter'])) {
             $filter = array();
             if (is_array($data['data']['filter_filter'])) {
                 foreach ($data['data']['filter_filter'] as $id => $unused) {
                     if (!is_numeric($id) || empty($id)) {
                         continue;
                     }
                     $filter[] = $id;
                 }
             } else {
                 if (is_numeric($data['data']['filter_filter']) && !empty($data['data']['filter_filter'])) {
                     $filter[] = $data['data']['filter_filter'];
                 }
             }
             if (count($filter)) {
                 $sql .= ' AND pa.attribute_id IN (' . implode(',', $filter) . ') ';
             }
         }
         $sql .= '
         GROUP BY p.product_id ';
         switch ($data['data']['sort']) {
             case 'pd.name':
                 $sql .= 'ORDER BY pd.name ' . $data['data']['order'];
                 break;
             case 'p.price':
                 $sql .= 'ORDER BY p.price ' . $data['data']['order'];
                 break;
             case 'p.model':
                 $sql .= 'ORDER BY p.model_2 ' . $data['data']['order'];
                 break;
             default:
                 $sql .= 'ORDER BY p.sort_order ' . $data['data']['order'];
                 break;
         }
         $values = array('manufacturer_id' => $data['data']['filter_manufacturer_id']);
     }
     if (!empty($sql)) {
         $total = $this->query($sql, $values)->fetch();
         $result['total'] = $total['total'];
         $sql .= ' LIMIT ' . $data['data']['start'] . ',' . $data['data']['limit'];
         if ($data['type'] == 'category_path') {
             if (!$total || !count($total)) {
                 Sumo\Logger::warning('total query failed');
                 return;
             }
             Sumo\Logger::warning(print_r($total, true));
         }
         $products = $this->fetchAll($sql, $values);
         Sumo\Logger::info('Total products count: ' . $result['total'] . ', fetchAll with limit: ' . print_r($products, true));
     }
     if (is_array($products) && count($products)) {
         $count = 1;
         foreach ($products as $p) {
             if (empty($p['product_id'])) {
                 continue;
             }
             $product = $this->getProduct($p['product_id']);
             if ((!$product['stock_visible'] || $product['stock_visible'] == 2 && !$this->config->get('display_stock_empty')) && $product['quantity'] <= 0) {
                 Sumo\Logger::info('Product ' . $p['product_id'] . ' has no stock and may not be visible, or shop is set to disable low quantity products');
                 continue;
             }
             $result[$count++] = $product;
         }
     }
     if (!$result['total'] && $data['type'] == 'category') {
         $data['type'] = 'category_path';
         return $this->getProducts($data);
     }
     Sumo\Cache::set($cache, $result);
     Sumo\Logger::info('Put products in cache');
     return $result;
 }
Exemple #8
0
 public function checkSettings($store_id = 0)
 {
     $data = $this->getSettings($store_id);
     if (!$data['enabled']) {
         return true;
     }
     if (!count($data['merchant'])) {
         return false;
     } else {
         if (empty($data['merchant']['id'])) {
             Sumo\Logger::warning('[Sisow] Merchant id is empty');
             return false;
         }
         if (empty($data['merchant']['key'])) {
             Sumo\Logger::warning('[Sisow] Merchant key is empty');
             return false;
         }
         include 'api.php';
         $api = new ModelApi($this->registry);
         try {
             $api->setMerchant($data['merchant']['id'], $data['merchant']['key']);
             $methods = $api->callMethods();
             if (isset($methods['error'])) {
                 Sumo\Logger::warning('[Sisow] Merchant id/key is invalid');
                 return false;
             } else {
                 if (!count($methods['merchant']['payments'])) {
                     Sumo\Logger::warning('[Sisow] Merchant is valid, but no payment options are available');
                     return false;
                 }
             }
         } catch (\Exception $e) {
             Sumo\Logger::warning('[Sisow] Unexpected error occured while validating merchant id/key');
             return false;
         }
     }
     if (!count($data['status'])) {
         return false;
     }
     foreach ($data['status'] as $type => $id) {
         if ($id <= 0) {
             Sumo\Logger::warning('[Sisow] Status for ' . $type . ' is empty');
             return false;
         }
     }
     if (!count($data['purchaseid'])) {
         return false;
     } else {
         if (empty($data['purchaseid'][$this->config->get('language_id')])) {
             Sumo\Logger::warning('[Sisow] Purchase description for default language is empty');
             return false;
         }
     }
     if (empty($data['tax'])) {
         Sumo\Logger::warning('[Sisow] No tax has been set');
         return false;
     }
     return true;
 }