Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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');
     }
 }
Example #3
0
 /**
 	@param $productsIDs  array of product IDs to compare
 	@param $compareBy    array of attribute IDs to include in the result compare list
 */
 function __construct($productsIDs, $compareBy)
 {
     $prodAttributes = array();
     foreach ($productsIDs as $prodId) {
         $product = new Product($prodId);
         $prodAttributes[$product->id()] = $product->attributes();
         $this->items[$product->id()] = array();
     }
     foreach ($compareBy as $attrId) {
         foreach ($prodAttributes as $prodId => $attrs) {
             $attr = new Attribute($attrId);
             if ($this->isSetInAtLeastOne($prodAttributes, $attr->id())) {
                 $this->items[$prodId][$attr->id()] = $attrs->get($attr->id());
                 $this->fullList[$attr->id()] = $attr;
                 if (!$this->isEqualForAll($prodAttributes, $attr->id())) {
                     $this->listOfDifferences[$attr->id()] = $attr;
                 }
             }
         }
     }
 }
Example #4
0
 /**
  * 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;
 }