/** * Returns product by xml string. * * @param string XML. * @return Product. */ static function product($xml) { $x = new \SimpleXMLElement($xml); $result = new Product(); $result->id(trim((string) $x->productID)); $result->name(trim((string) $x->name)); $result->currency(trim((string) $x->price['currency'])); $result->price(trim((string) $x->price)); $result->url(trim((string) $x->productURL)); $result->imgUrl(trim((string) $x->imageURL)); $result->description(trim((string) $x->description)); $cats = []; foreach ($x->categories->category as $cat) { $cats[] = trim((string) $cat); } $result->categories($cats); $adds = []; foreach ($x->additional->field as $add) { $adds[trim((string) $add['name'])] = trim((string) $add); } $result->additional($adds); return $result; }
$appconf = parse_ini_file($file, true); if (isset($appconf['Admin']['handler'])) { if (isset($appconf['Admin']['install'])) { $ver = $this->installed($app, $appconf['Admin']['version']); if ($ver === true) { // installed $tools[$appconf['Admin']['handler']] = $appconf['Admin']; $tools[$appconf['Admin']['handler']]['class'] = false; } elseif ($ver === false) { // not installed $appconf['Admin']['name'] .= ' (' . i18n_get('click to install') . ')'; $tools[$appconf['Admin']['install']] = $appconf['Admin']; $tools[$appconf['Admin']['install']]['class'] = 'not-installed'; } else { // needs upgrade $appconf['Admin']['name'] .= ' (' . i18n_get('click to upgrade') . ')'; $tools[$appconf['Admin']['upgrade']] = $appconf['Admin']; $tools[$appconf['Admin']['upgrade']]['class'] = 'needs-upgrade'; } } else { // no installer, as you were $tools[$appconf['Admin']['handler']] = $appconf['Admin']; $tools[$appconf['Admin']['handler']]['class'] = false; } } } uasort($tools, 'admin_head_links_sort'); $out = array('name' => Product::name(), 'logo' => Product::logo_toolbar(), 'links' => $tpl->render('admin/head/links', array('user' => User::val('name'), 'tools' => $tools))); $page->layout = false; header('Content-Type: application/json'); echo json_encode($out);
/** * Parse the category/product breadcrumb * * Parses the template block shopNavbar and shop_breadcrumb based on * the currently selected category and product. * * @param \Cx\Core\Html\Sigma $objTpl The template object to be used to parse the breadcrumb on. * @param integer $selectedCatId The ID of the currently selected category. * @param Product $product The currently selected product. */ static function parseBreadcrumb($objTpl, $selectedCatId = 0, $product = null) { // Only the visible ShopCategories are present $arrShopCategoryTree = ShopCategories::getTreeArray(false, true, true, $selectedCatId, 0, 0); // The trail of IDs from root to the selected ShopCategory, // built along with the tree array when calling getTreeArray(). $arrTrail = ShopCategories::getTrailArray($selectedCatId); // Display the ShopCategories foreach ($arrShopCategoryTree as $arrShopCategory) { $level = $arrShopCategory['level']; // Skip levels too deep: if ($level >= 2) { continue; } $id = $arrShopCategory['id']; $style = 'shopnavbar' . ($level + 1); if (in_array($id, $arrTrail)) { $style .= '_active'; } // parse shopNavbar if ($objTpl->blockExists('shopNavbar')) { $objTpl->setVariable(array('SHOP_CATEGORY_STYLE' => $style, 'SHOP_CATEGORY_ID' => $id, 'SHOP_CATEGORY_NAME' => str_repeat(' ', 3 * $level) . str_replace('"', '"', $arrShopCategory['name']))); $objTpl->parse("shopNavbar"); } // skip shop_breadcrumb parsing in case the required template blocks are missing if (!$objTpl->blockExists('shop_breadcrumb') || !$objTpl->blockExists('shop_breadcrumb_part')) { continue; } // skip shop_breadcrumb parsing in case the category is not part of the selected category tree if (!in_array($id, $arrTrail)) { continue; } // parse the category in shop_breadcrumb $objTpl->setVariable(array('SHOP_BREADCRUMB_PART_SRC' => \Cx\Core\Routing\URL::fromModuleAndCmd('Shop' . MODULE_INDEX, '', FRONTEND_LANG_ID, array('catId' => $id))->toString(), 'SHOP_BREADCRUMB_PART_TITLE' => contrexx_raw2xhtml($arrShopCategory['name']))); $objTpl->parse('shop_breadcrumb_part'); } // skip shop_breadcrumb parsing in case the required template blocks are missing if (!$objTpl->blockExists('shop_breadcrumb') && !$objTpl->blockExists('shop_breadcrumb_part')) { return; } // parse Product in shop_breadcrumb if a product is being viewed if ($product) { $objTpl->setVariable(array('SHOP_BREADCRUMB_PART_SRC' => \Cx\Core\Routing\URL::fromModuleAndCmd('Shop' . MODULE_INDEX, '', FRONTEND_LANG_ID, array('productId' => $product->id()))->toString(), 'SHOP_BREADCRUMB_PART_TITLE' => contrexx_raw2xhtml($product->name()))); $objTpl->parse('shop_breadcrumb_part'); } // show or hide the shop_breadcrumb template block, depending on if a category // has been selected or a product is being viewed if (array_intersect(array_keys($arrShopCategoryTree), $arrTrail) || $product) { $objTpl->touchBlock('shop_breadcrumb'); } else { $objTpl->hideBlock('shop_breadcrumb'); } }
/** * Outputs an admin login form at /admin if the * user isn't logged in as an admin. If they are, * it simply forwards to / where they should see * the admin toolbar and edit buttons. */ $page->id = 'admin'; $page->layout = 'admin'; if (isset($_GET['redirect'])) { $_POST['redirect'] = $_GET['redirect']; } if (!isset($_POST['redirect']) || empty($_POST['redirect']) || !Validator::validate($_POST['redirect'], 'header')) { $_POST['redirect'] = $appconf['General']['login_redirect']; } $redir = parse_url($_POST['redirect']); if ($redir === false || $_POST['redirect'] !== $redir['path'] && $_POST['redirect'] !== $redir['path'] . '?' . $redir['query']) { $_POST['redirect'] = $appconf['General']['login_redirect']; } if (!User::require_admin()) { $page->title = sprintf('<img src="%s" alt="%s" style="margin-left: -7px" />', Product::logo_login(), Product::name()); $page->window_title = __('Please log in to continue.'); if (!empty($_POST['username'])) { echo '<p>' . __('Incorrect email or password, please try again.') . '</p>'; } else { echo '<p>' . __('Please log in to continue.') . '</p>'; } echo $tpl->render('admin/index'); return; } $this->redirect($_POST['redirect']);
/** * Stores the posted Product, if any * @return boolean True on success, null on noop, false otherwise */ static function store_product() { global $_ARRAYLANG; if (!isset($_POST['bstore'])) { return null; } $product_name = contrexx_input2raw($_POST['product_name']); $product_code = contrexx_input2raw($_POST['product_code']); // Multiple Categories $category_id = isset($_POST['shopCategoriesAssigned']) ? contrexx_input2raw(join(',', $_POST['shopCategoriesAssigned'])) : ''; $customer_price = $_POST['customer_price']; $reseller_price = $_POST['reseller_price']; $discount_active = !empty($_POST['discount_active']); $discount_price = $_POST['discount_price']; //DBG::log("ShopManager::store_product(): customer_price $customer_price, reseller_price $reseller_price, discount_price $discount_price"); $vat_id = $_POST['vat_id']; $short = contrexx_input2raw($_POST['short']); $long = contrexx_input2raw($_POST['long']); $stock = $_POST['stock']; $stock_visible = !empty($_POST['stock_visible']); $uri = contrexx_input2raw($_POST['uri']); $active = !empty($_POST['articleActive']); $b2b = !empty($_POST['B2B']); $b2c = !empty($_POST['B2C']); $date_start = contrexx_input2raw($_POST['date_start']); $date_end = contrexx_input2raw($_POST['date_end']); $manufacturer_id = isset($_POST['manufacturer_id']) ? contrexx_input2int($_POST['manufacturer_id']) : 0; $minimum_order_quantity = $_POST['minimum_order_quantity']; // Currently not used on the detail page // $flags = (isset($_POST['Flags']) // ? join(' ', $_POST['Flags']) : ''); $distribution = $_POST['distribution']; // Different meaning of the "weight" field for downloads! // The getWeight() method will treat purely numeric values // like the validity period (in days) the same as a weight // without its unit and simply return its integer value. $weight = $distribution == 'delivery' ? Weight::getWeight($_POST['weight']) : $_POST['accountValidity']; // Assigned frontend groups for protected downloads $usergroup_ids = isset($_POST['groupsAssigned']) ? implode(',', $_POST['groupsAssigned']) : ''; $discount_group_count_id = $_POST['discount_group_count_id']; $discount_group_article_id = $_POST['discount_group_article_id']; //DBG::log("ShopManager::store_product(): Set \$discount_group_article_id to $discount_group_article_id"); $keywords = contrexx_input2raw($_POST['keywords']); for ($i = 1; $i <= 3; ++$i) { // Images outside the above directory are copied to the shop image folder. // Note that the image paths below do not include the document root, but // are relative to it. $picture = contrexx_input2raw($_POST['productImage' . $i]); // Ignore the picture if it's the default image! // Storing it would be pointless. // Images outside the above directory are copied to the shop image folder. // Note that the image paths below do not include the document root, but // are relative to it. if ($picture == self::$defaultImage || !self::moveImage($picture)) { $picture = ''; } // Update the posted path (used below) $_POST['productImage' . $i] = $picture; } // add all to pictures DBstring $imageName = base64_encode($_POST['productImage1']) . '?' . base64_encode($_POST['productImage1_width']) . '?' . base64_encode($_POST['productImage1_height']) . ':' . base64_encode($_POST['productImage2']) . '?' . base64_encode($_POST['productImage2_width']) . '?' . base64_encode($_POST['productImage2_height']) . ':' . base64_encode($_POST['productImage3']) . '?' . base64_encode($_POST['productImage3_width']) . '?' . base64_encode($_POST['productImage3_height']); // Note that the flags of the Product *MUST NOT* be changed // when inserting or updating the Product data, as the original // flags are needed for their own update later. $objProduct = null; $product_id = intval($_POST['id']); if ($product_id) { $objProduct = Product::getById($product_id); } $new = false; if (!$objProduct) { $new = true; $objProduct = new Product($product_code, $category_id, $product_name, $distribution, $customer_price, $active, 0, $weight); if (!$objProduct->store()) { return \Message::error($_ARRAYLANG['TXT_SHOP_PRODUCT_ERROR_STORING']); } // $product_id = $objProduct->id(); } // Apply the changes to all Products with the same Product code. // Note: This is disabled for the time being, as virtual categories are, too. // if ($product_code != '') { // $arrProduct = Products::getByCustomId($product_code); // } else { // $arrProduct = array($objProduct); // } // if (!is_array($arrProduct)) return false; // foreach ($arrProduct as $objProduct) { // Update each product $objProduct->code($product_code); // NOTE: Only change the parent ShopCategory for a Product // that is in a real ShopCategory. $objProduct->category_id($category_id); $objProduct->name($product_name); $objProduct->distribution($distribution); $objProduct->price($customer_price); $objProduct->active($active); // On the overview only: $objProduct->ord(); $objProduct->weight($weight); $objProduct->resellerprice($reseller_price); $objProduct->discount_active($discount_active); $objProduct->discountprice($discount_price); $objProduct->vat_id($vat_id); $objProduct->short($short); $objProduct->long($long); $objProduct->stock($stock); $objProduct->minimum_order_quantity($minimum_order_quantity); $objProduct->stock_visible($stock_visible); $objProduct->uri($uri); $objProduct->b2b($b2b); $objProduct->b2c($b2c); $objProduct->date_start($date_start); $objProduct->date_end($date_end); $objProduct->manufacturer_id($manufacturer_id); $objProduct->pictures($imageName); // Currently not used on the detail page // $objProduct->flags($flags); $objProduct->usergroup_ids($usergroup_ids); $objProduct->group_id($discount_group_count_id); $objProduct->article_id($discount_group_article_id); $objProduct->keywords($keywords); //DBG::log("ShopManager::store_product(): Product: reseller_price ".$objProduct->resellerprice()); // Remove old Product Attributes. // They are re-added below. $objProduct->clearAttributes(); // Add current product attributes if (isset($_POST['options']) && is_array($_POST['options'])) { foreach ($_POST['options'] as $valueId => $nameId) { $order = intval($_POST['productOptionsSortId'][$nameId]); $objProduct->addAttribute(intval($valueId), $order); } } // Mind that this will always be an *update*, see the call to // store() above. if (!$objProduct->store()) { return \Message::error($_ARRAYLANG['TXT_SHOP_PRODUCT_ERROR_STORING']); } // } // Add/remove Categories and Products to/from // virtual ShopCategories. // Note that this *MUST* be called *AFTER* the Product is updated // or inserted. // Virtual categories are disabled for the time being // Products::changeFlagsByProductCode( // $product_code, $flags // ); $objImage = new \ImageManager(); $arrImages = Products::get_image_array_from_base64($imageName); // Create thumbnails if not available, or update them foreach ($arrImages as $arrImage) { if (!empty($arrImage['img']) && $arrImage['img'] != ShopLibrary::noPictureName) { if (!$objImage->_createThumbWhq(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopPath() . '/', \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/', $arrImage['img'], \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_max_width', 'Shop'), \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_max_height', 'Shop'), \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_quality', 'Shop'))) { \Message::error(sprintf($_ARRAYLANG['TXT_SHOP_COULD_NOT_CREATE_THUMBNAIL'], $arrImage['img'])); } } } \Message::ok($new ? $_ARRAYLANG['TXT_DATA_RECORD_ADDED_SUCCESSFUL'] : $_ARRAYLANG['TXT_DATA_RECORD_UPDATED_SUCCESSFUL']); switch ($_POST['afterStoreAction']) { case 'newEmpty': \Cx\Core\Csrf\Controller\Csrf::redirect('index.php?cmd=Shop' . MODULE_INDEX . '&act=products&tpl=manage'); case 'newTemplate': \Cx\Core\Csrf\Controller\Csrf::redirect('index.php?cmd=Shop' . MODULE_INDEX . '&act=products&tpl=manage&id=' . $objProduct->id() . '&new=1'); } \Cx\Core\Csrf\Controller\Csrf::redirect('index.php?cmd=Shop' . MODULE_INDEX . '&act=products'); // Never reached return true; }
function ajax_get_goods($id = null) { if (!($order = Order::find($id))) { return; } elseif (!$this->accessible($order)) { return false; } else { return Product::name('p')->join(OrderProduct::$table, 'p.id', '=', 'product')->where('order', '=', $order->id); } }
if (count($tools) === 0 && admin\Toolbar::$autofill === false) { $tools = admin\Toolbar::apps($this); $is_apps = true; } else { if (admin\Toolbar::$autofill) { // Extend the tools list with any unused app resources. $apps = admin\Toolbar::apps($this); foreach ($tools as $column => $group) { // filter out resources that are already in use $apps = array_diff_key($apps, $group); } if (count($apps)) { $i = 0; $j = 2; $column = admin\Toolbar::$autofill; $tools[$column] = array(); foreach ($apps as $handler => $app) { if (++$i > 7) { $i = 0; $column = admin\Toolbar::$autofill . ' (' . $j++ . ')'; $tools[$column] = array(); } $tools[$column][$handler] = $apps[$handler]; } } } $is_apps = false; } $editable = User::require_acl('admin/toolbar'); $out = array('name' => Product::name(), 'logo' => Product::logo_toolbar(), 'is_apps' => $is_apps || count($tools) === 0 && !$editable, 'links' => $tpl->render('admin/head/links', array('user' => User::val('name'), 'tools' => $tools, 'is_apps' => $is_apps, 'editable' => $editable))); echo json_encode($out);