protected function setUp() { parent::setUp(); \ContextCore::getContext()->employee = new \Employee(1); $this->moduleManagerBuilder = ModuleManagerBuilder::getInstance(); $this->moduleManager = $this->moduleManagerBuilder->build(); $this->moduleNames = ['pscsx3241', 'pscsx32412']; }
/** * Get combination for a product * * @param int $idProduct * * @return array Combinations */ public function getProductCombinations($idProduct) { $context = \ContextCore::getContext(); //get product $product = new \ProductCore((int) $idProduct, false); if (!is_object($product) || empty($product->id)) { return false; } $allCombinations = $product->getAttributeCombinations(1, false); $allCombinationsIds = array_map(function ($o) { return $o['id_product_attribute']; }, $allCombinations); $combinations = []; foreach ($allCombinationsIds as $combinationId) { $combinations[] = $product->getAttributeCombinationsById($combinationId, $context->employee->id_lang)[0]; } return $combinations; }
/** * Get all Tax Rules Groups with rates * * @return array TaxRulesGroup */ public function getTaxRulesGroupWithRates() { $address = new \Address(); $address->id_country = (int) \ContextCore::getContext()->country->id; $tax_rules_groups = $this->getTaxRulesGroups(); $tax_rates = array(0 => array('id_tax_rules_group' => 0, 'rates' => array(0), 'computation_method' => 0)); foreach ($tax_rules_groups as $tax_rules_group) { $id_tax_rules_group = (int) $tax_rules_group['id_tax_rules_group']; $tax_calculator = \TaxManagerFactoryCore::getManager($address, $id_tax_rules_group)->getTaxCalculator(); $tax_rates[$id_tax_rules_group] = array('id_tax_rules_group' => $id_tax_rules_group, 'rates' => array(), 'computation_method' => (int) $tax_calculator->computation_method); if (isset($tax_calculator->taxes) && count($tax_calculator->taxes)) { foreach ($tax_calculator->taxes as $tax) { $tax_rates[$id_tax_rules_group]['rates'][] = (double) $tax->rate; } } else { $tax_rates[$id_tax_rules_group]['rates'][] = 0; } } return $tax_rates; }
/** * Unit testing purpose only */ public static function deleteTestingInstance() { self::$instance = null; }
/** * Get a singleton context * * @return Context */ public static function getContext() { if (!isset(self::$instance)) { self::$instance = new Context(); } return self::$instance; }
/** * This fix is used to have a ready translation in the smarty 'l' function. * Called by AutoResponseFormatTrait in beforeActionSuggestResponseFormat(). * So if you do not use this Trait, you must call this method by yourself in the action. * * @param string $legacyController */ public function setupLegacyTranslationContext($legacyController = 'AdminTab') { OldContext::getContext()->override_controller_name_for_translations = $legacyController; }
/** * {@inheritdoc} */ public function countAllProducts() { $idShop = \ContextCore::getContext()->shop->id; $sqlSelect = array('id_product' => array('table' => 'p', 'field' => 'id_product')); $sqlTable = array('p' => 'product', 'sa' => array('table' => 'product_shop', 'join' => 'JOIN', 'on' => 'p.`id_product` = sa.`id_product` AND sa.id_shop = ' . $idShop)); $sql = $this->compileSqlQuery($sqlSelect, $sqlTable); \Db::getInstance()->executeS($sql, true, false); $total = \Db::getInstance()->executeS('SELECT FOUND_ROWS();', true, false); $total = $total[0]['FOUND_ROWS()']; return $total; }
/** * Returns an array of event names this subscriber wants to listen to. * * The array keys are event names and the value are a function name * that will be solved by magic __call(). The function contains data to extract: hookId, moduleId * * TODO: add cache layer on $listeners * * @return array The listeners array */ public static function getSubscribedEvents() { $listeners = array(); //Hack SF2 cache clear : if context not mounted, bypass legacy call $legacyContext = OldContext::getContext(); if (!$legacyContext || empty($legacyContext->shop) || empty($legacyContext->employee)) { return $listeners; } $hooks = \HookCore::getHooks(); foreach ($hooks as $hook) { $name = $hook['name']; $id = $hook['id_hook']; $moduleListeners = array(); $modules = array(); //SF2 cache clear bug fix : call bqSQL alias function if (function_exists("bqSQL")) { $modules = \HookCore::getHookModuleExecList($name); } if (is_array($modules)) { foreach ($modules as $order => $module) { $moduleId = $module['id_module']; $functionName = 'call_' . $id . '_' . $moduleId; $moduleListeners[] = array($functionName, 2000 - $order); } if (count($moduleListeners)) { $listeners[$name] = $moduleListeners; } } } return $listeners; }
/** * Generate preview URL deactivate * * @param string $preview_url * * @return string preview url deactivate */ public function getPreviewUrlDeactivate($preview_url) { $context = \ContextCore::getContext(); $token = \ToolsCore::getAdminTokenLite('AdminProducts'); $admin_dir = dirname($_SERVER['PHP_SELF']); $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1); $preview_url_deactivate = $preview_url . (strpos($preview_url, '?') === false ? '?' : '&') . 'adtoken=' . $token . '&ad=' . $admin_dir . '&id_employee=' . (int) $context->employee->id; return $preview_url_deactivate; }