Beispiel #1
0
 /**
  * Select a Product by ID from the database.
  * @static
  * @param       integer     $id             The Product ID
  * @return      Product                     The Product object on success,
  *                                          false otherwise
  * @global      ADONewConnection
  * @author      Reto Kohli <*****@*****.**>
  */
 static function getById($id)
 {
     global $objDatabase;
     if (!$id) {
         return NULL;
     }
     $arrSql = \Text::getSqlSnippets('`product`.`id`', FRONTEND_LANG_ID, 'Shop', array('name' => self::TEXT_NAME, 'short' => self::TEXT_SHORT, 'long' => self::TEXT_LONG, 'keys' => self::TEXT_KEYS, 'code' => self::TEXT_CODE, 'uri' => self::TEXT_URI));
     $query = "\n            SELECT `product`.`id`, `product`.`category_id`,\n                   `product`.`ord`, `product`.`active`, `product`.`weight`,\n                   `product`.`picture`,\n                   `product`.`normalprice`, `product`.`resellerprice`,\n                   `product`.`discountprice`, `product`.`discount_active`,\n                   `product`.`stock`, `product`.`stock_visible`,\n                   `product`.`distribution`,\n                   `product`.`date_start`, `product`.`date_end`,\n                   `product`.`manufacturer_id`,\n                   `product`.`b2b`, `product`.`b2c`,\n                   `product`.`vat_id`,\n                   `product`.`flags`,\n                   `product`.`usergroup_ids`,\n                   `product`.`group_id`, `product`.`article_id`,\n                   `product`.`minimum_order_quantity`, " . $arrSql['field'] . "\n              FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_products` AS `product`" . $arrSql['join'] . "\n             WHERE `product`.`id`={$id}";
     $objResult = $objDatabase->Execute($query);
     if (!$objResult) {
         return self::errorHandler();
     }
     if ($objResult->RecordCount() != 1) {
         return false;
     }
     $id = $objResult->fields['id'];
     $strCode = $objResult->fields['code'];
     if ($strCode === null) {
         $strCode = \Text::getById($id, 'Shop', self::TEXT_CODE)->content();
     }
     $strName = $objResult->fields['name'];
     if ($strName === null) {
         $strName = \Text::getById($id, 'Shop', self::TEXT_NAME)->content();
     }
     $strShort = $objResult->fields['short'];
     if ($strShort === null) {
         $strShort = \Text::getById($id, 'Shop', self::TEXT_SHORT)->content();
     }
     $strLong = $objResult->fields['long'];
     if ($strLong === null) {
         $strLong = \Text::getById($id, 'Shop', self::TEXT_LONG)->content();
     }
     $strUri = $objResult->fields['uri'];
     if ($strUri === null) {
         $strUri = \Text::getById($id, 'Shop', self::TEXT_URI)->content();
     }
     $strKeys = $objResult->fields['keys'];
     if ($strKeys === null) {
         $strKeys = \Text::getById($id, 'Shop', self::TEXT_KEYS)->content();
     }
     $objProduct = new Product($strCode, $objResult->fields['category_id'], $strName, $objResult->fields['distribution'], $objResult->fields['normalprice'], $objResult->fields['active'], $objResult->fields['ord'], $objResult->fields['weight'], $objResult->fields['id']);
     $objProduct->pictures = $objResult->fields['picture'];
     $objProduct->resellerprice = floatval($objResult->fields['resellerprice']);
     $objProduct->short = $strShort;
     $objProduct->long = $strLong;
     $objProduct->stock($objResult->fields['stock']);
     $objProduct->stock_visible($objResult->fields['stock_visible']);
     $objProduct->discountprice = floatval($objResult->fields['discountprice']);
     $objProduct->discount_active($objResult->fields['discount_active']);
     $objProduct->b2b($objResult->fields['b2b']);
     $objProduct->b2c($objResult->fields['b2c']);
     $objProduct->date_start($objResult->fields['date_start']);
     $objProduct->date_end($objResult->fields['date_end']);
     $objProduct->manufacturer_id = $objResult->fields['manufacturer_id'];
     $objProduct->uri = $strUri;
     $objProduct->vat_id = $objResult->fields['vat_id'];
     $objProduct->flags = $objResult->fields['flags'];
     $objProduct->usergroup_ids = $objResult->fields['usergroup_ids'];
     $objProduct->group_id = $objResult->fields['group_id'];
     $objProduct->article_id = $objResult->fields['article_id'];
     $objProduct->keywords = $strKeys;
     $objProduct->minimum_order_quantity = $objResult->fields['minimum_order_quantity'];
     // Fetch the Product Attribute relations
     $objProduct->arrRelations = Attributes::getRelationArray($objProduct->id);
     //die("dfhreh: ".$objProduct->category_id());
     return $objProduct;
 }
Beispiel #2
0
 /**
  * Set up the HTML elements for all the Product Attributes of any Product.
  *
  * The following types of Attributes are supported:
  * 0    Dropdown menu, customers may select no (the default) or one option.
  * 1    Radio buttons, customers need to select one option.
  * 2    Checkboxes, customers may select no, one or several options.
  * 3    Dropdown menu, customers need to select one option.
  * 4    Optional text field
  * 5    Mandatory text field
  * 6    Optional file upload field
  * 7    Mandatory file upload field
  * Types 1 and 3 are functionally identical, they only differ by
  * the kind of widget being used.
  * The individual Product Attributes carry a unique ID enabling the
  * JavaScript code contained within the Shop page to verify that
  * all mandatory choices have been made before any Product can
  * be added to the cart.
  * @param   integer     $product_id     The Product ID
  * @param   string      $formName       The name of the HTML form containing
  *                                      the Product and options
  * @param   integer     $cart_id        The optional cart Product ID,
  *                                      null if not applicable.
  * @param   boolean     $flagUpload     If a product has an upload
  *                                      Attribute associated with it,
  *                                      this parameter will be set to true
  * @return  string                      The string with the HTML code
  */
 static function productOptions($product_id, $formName, $cart_id = null, &$flagUpload = false)
 {
     global $_ARRAYLANG;
     //\DBG::log("productOptions($product_id, $formName, $cart_id, $flagUpload): Entered");
     // Semicolon separated list of Attribute name IDs to verify
     // before the Product is added to the cart
     $checkOptionIds = '';
     // check if the product option block exists in the template
     if (self::$objTemplate->blockExists('shopProductOptionsRow') && self::$objTemplate->blockExists('shopProductOptionsValuesRow')) {
         $domId = 0;
         $count = 0;
         $arrAttributes = Attributes::getArray($count, null, null, '`ord` ASC', array('product_id' => $product_id));
         //\DBG::log("Attributes: ".var_export($arrAttributes, true));
         // When there are no Attributes for this Product, hide the
         // options blocks
         if (empty($arrAttributes)) {
             self::$objTemplate->hideBlock('shopProductOptionsRow');
             self::$objTemplate->hideBlock('shopProductOptionsValuesRow');
         } else {
             // Loop through the Attribute Names for the Product
             foreach ($arrAttributes as $attribute_id => $objAttribute) {
                 $mandatory = false;
                 $arrOptions = Attributes::getOptionArrayByAttributeId($attribute_id);
                 $arrRelation = Attributes::getRelationArray($product_id);
                 // This attribute does not apply for this product
                 if (empty($arrRelation)) {
                     continue;
                 }
                 $selectValues = '';
                 // create head of option menu/checkbox/radiobutton
                 switch ($objAttribute->getType()) {
                     case Attribute::TYPE_CHECKBOX:
                     case Attribute::TYPE_TEXT_OPTIONAL:
                     case Attribute::TYPE_UPLOAD_OPTIONAL:
                     case Attribute::TYPE_TEXTAREA_OPTIONAL:
                     case Attribute::TYPE_EMAIL_OPTIONAL:
                     case Attribute::TYPE_EMAIL_OPTIONAL:
                     case Attribute::TYPE_URL_OPTIONAL:
                     case Attribute::TYPE_DATE_OPTIONAL:
                     case Attribute::TYPE_NUMBER_INT_OPTIONAL:
                     case Attribute::TYPE_NUMBER_FLOAT_OPTIONAL:
                         // No container nor hidden field for optional types
                         break;
                     case Attribute::TYPE_MENU_OPTIONAL:
                         // There is no hidden input field here either,
                         // but the dropdown menu container
                         $selectValues = '<select name="productOption[' . $attribute_id . ']" id="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '" style="width:180px;">' . "\n" . '<option value="0">' . $objAttribute->getName() . '&nbsp;' . $_ARRAYLANG['TXT_CHOOSE'] . "</option>\n";
                         break;
                     case Attribute::TYPE_RADIOBUTTON:
                     case Attribute::TYPE_TEXT_MANDATORY:
                     case Attribute::TYPE_UPLOAD_MANDATORY:
                     case Attribute::TYPE_TEXTAREA_MANDATORY:
                     case Attribute::TYPE_EMAIL_MANDATORY:
                     case Attribute::TYPE_URL_MANDATORY:
                     case Attribute::TYPE_DATE_MANDATORY:
                     case Attribute::TYPE_NUMBER_INT_MANDATORY:
                     case Attribute::TYPE_NUMBER_FLOAT_MANDATORY:
                         $mandatory = true;
                         // The Attribute name, indicating a mandatory option.
                         $selectValues = '<input type="hidden" id="productOption-' . $product_id . '-' . $attribute_id . '" value="' . $objAttribute->getName() . '" />' . "\n";
                         // The Attribute verification regex, if applicable
                         $regex = Attribute::getVerificationRegex($objAttribute->getType());
                         if ($regex != '') {
                             $selectValues .= '<input type="hidden" id="attributeVerification-' . $product_id . '-' . $attribute_id . '" value="' . $regex . '" />' . "\n";
                         }
                         $checkOptionIds .= "{$attribute_id};";
                         break;
                     case Attribute::TYPE_MENU_MANDATORY:
                         $selectValues = '<input type="hidden" id="productOption-' . $product_id . '-' . $attribute_id . '" value="' . $objAttribute->getName() . '" />' . "\n" . '<select name="productOption[' . $attribute_id . ']" id="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '" style="width:180px;">' . "\n" . (count($arrOptions) > 1 ? '<option value="0">' . $objAttribute->getName() . '&nbsp;' . $_ARRAYLANG['TXT_CHOOSE'] . "</option>\n" : '');
                         $checkOptionIds .= "{$attribute_id};";
                         break;
                 }
                 $i = 0;
                 foreach ($arrOptions as $option_id => $arrOption) {
                     // This option does not apply to this product
                     if (!isset($arrRelation[$option_id])) {
                         continue;
                     }
                     $option_price = '';
                     $selected = false;
                     // Show the price only if non-zero
                     if ($arrOption['price'] != 0) {
                         $option_price = '&nbsp;(' . Currency::getCurrencyPrice($arrOption['price']) . '&nbsp;' . Currency::getActiveCurrencySymbol() . ')';
                     }
                     // mark the option value as selected if it was before
                     // and this page was requested from the cart
                     if (isset($cart_id)) {
                         $options = Cart::get_options_array($cart_id, $attribute_id);
                         if (is_array($options) && in_array($option_id, $options)) {
                             $selected = true;
                         }
                     }
                     // create option menu/checkbox/radiobutton
                     switch ($objAttribute->getType()) {
                         case Attribute::TYPE_MENU_OPTIONAL:
                             $selectValues .= '<option value="' . $option_id . '" ' . ($selected ? 'selected="selected"' : '') . ' >' . $arrOption['value'] . $option_price . "</option>\n";
                             break;
                         case Attribute::TYPE_RADIOBUTTON:
                             $selectValues .= '<input type="radio" name="productOption[' . $attribute_id . ']" id="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '" value="' . $option_id . '"' . ($selected ? ' checked="checked"' : '') . ' /><label for="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '">&nbsp;' . $arrOption['value'] . $option_price . "</label><br />\n";
                             break;
                         case Attribute::TYPE_CHECKBOX:
                             $selectValues .= '<input type="checkbox" name="productOption[' . $attribute_id . '][' . $i . ']" id="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '" value="' . $option_id . '"' . ($selected ? ' checked="checked"' : '') . ' /><label for="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '">&nbsp;' . $arrOption['value'] . $option_price . "</label><br />\n";
                             break;
                         case Attribute::TYPE_MENU_MANDATORY:
                             $selectValues .= '<option value="' . $option_id . '"' . ($selected ? ' selected="selected"' : '') . ' >' . $arrOption['value'] . $option_price . "</option>\n";
                             break;
                         case Attribute::TYPE_TEXT_OPTIONAL:
                         case Attribute::TYPE_TEXT_MANDATORY:
                             //                            $option_price = '&nbsp;';
                             $selectValues .= '<input type="text" name="productOption[' . $attribute_id . ']" id="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '" value="' . $arrOption['value'] . '" style="width:180px;" />' . '<label for="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '">' . $option_price . "</label><br />\n";
                             break;
                         case Attribute::TYPE_EMAIL_OPTIONAL:
                         case Attribute::TYPE_EMAIL_MANDATORY:
                             //                            $option_price = '&nbsp;';
                             $selectValues .= '<input type="text" name="productOption[' . $attribute_id . ']" id="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '" value="' . $arrOption['value'] . '" style="width:180px;" />' . '<label for="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '">' . $option_price . "</label><br />\n";
                             break;
                         case Attribute::TYPE_URL_OPTIONAL:
                         case Attribute::TYPE_URL_MANDATORY:
                             //                            $option_price = '&nbsp;';
                             $selectValues .= '<input type="text" name="productOption[' . $attribute_id . ']" id="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '" value="' . $arrOption['value'] . '" style="width:180px;" />' . '<label for="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '">' . $option_price . "</label><br />\n";
                             break;
                         case Attribute::TYPE_DATE_OPTIONAL:
                         case Attribute::TYPE_DATE_MANDATORY:
                             //                            $option_price = '&nbsp;';
                             // Passed by reference
                             $element_id = 'productOption-' . $product_id . '-' . $attribute_id . '-' . $domId;
                             $selectValues .= \Html::getDatepicker('productOption[' . $attribute_id . ']', array('defaultDate' => $arrOption['value']), 'style="width:180px;"', $element_id) . '<label for="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '">' . $option_price . "</label><br />\n";
                             break;
                         case Attribute::TYPE_NUMBER_INT_OPTIONAL:
                         case Attribute::TYPE_NUMBER_INT_MANDATORY:
                             //                            $option_price = '&nbsp;';
                             $selectValues .= '<input type="text" name="productOption[' . $attribute_id . ']" id="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '" value="' . $arrOption['value'] . '" style="width:180px;" />' . '<label for="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '">' . $option_price . "</label><br />\n";
                             break;
                         case Attribute::TYPE_NUMBER_FLOAT_OPTIONAL:
                         case Attribute::TYPE_NUMBER_FLOAT_MANDATORY:
                             //                            $option_price = '&nbsp;';
                             $selectValues .= '<input type="text" name="productOption[' . $attribute_id . ']" id="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '" value="' . $arrOption['value'] . '" style="width:180px;" />' . '<label for="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '">' . $option_price . "</label><br />\n";
                             break;
                         case Attribute::TYPE_UPLOAD_OPTIONAL:
                         case Attribute::TYPE_UPLOAD_MANDATORY:
                             //                            $option_price = '&nbsp;';
                             $selectValues .= '<input type="file" name="productOption[' . $attribute_id . ']" id="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '" style="width:180px;" />' . '<label for="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '">' . $option_price . "</label><br />\n";
                             break;
                         case Attribute::TYPE_TEXTAREA_OPTIONAL:
                         case Attribute::TYPE_TEXTAREA_MANDATORY:
                             //                            $valuePrice = '&nbsp;';
                             $selectValues .= '<textarea name="productOption[' . $attribute_id . ']" id="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '" style="width:300px;">' . contrexx_input2xhtml($arrOption['value']) . '</textarea>' . '<label for="productOption-' . $product_id . '-' . $attribute_id . '-' . $domId . '">' . $option_price . "</label><br />\n";
                             break;
                     }
                     ++$i;
                     ++$domId;
                 }
                 // create foot of option menu/checkbox/radiobutton
                 switch ($objAttribute->getType()) {
                     case Attribute::TYPE_MENU_OPTIONAL:
                         $selectValues .= "</select><br />";
                         break;
                     case Attribute::TYPE_RADIOBUTTON:
                         $selectValues .= "<br />";
                         break;
                     case Attribute::TYPE_CHECKBOX:
                         $selectValues .= "";
                         break;
                     case Attribute::TYPE_MENU_MANDATORY:
                         $selectValues .= "</select><br />";
                         break;
                         // Set enctype in form if one of these is present
                     // Set enctype in form if one of these is present
                     case Attribute::TYPE_UPLOAD_OPTIONAL:
                     case Attribute::TYPE_UPLOAD_MANDATORY:
                         // Avoid code analyzer warning
                         $flagUpload = true || $flagUpload;
                         break;
                         /* Nothing to to
                                                 case Attribute::TYPE_TEXT_OPTIONAL:
                                                 case Attribute::TYPE_TEXT_MANDATORY:
                                                 case Attribute::TYPE_TEXTAREA_OPTIONAL:
                                                 case Attribute::TYPE_TEXTAREA_MANDATORY:
                                                 case Attribute::TYPE_EMAIL_OPTIONAL:
                                                 case Attribute::TYPE_EMAIL_MANDATORY:
                                                 case Attribute::TYPE_URL_OPTIONAL:
                                                 case Attribute::TYPE_URL_MANDATORY:
                                                 case Attribute::TYPE_DATE_OPTIONAL:
                                                 case Attribute::TYPE_DATE_MANDATORY:
                                                 case Attribute::TYPE_NUMBER_INT_OPTIONAL:
                                                 case Attribute::TYPE_NUMBER_INT_MANDATORY:
                                                 case Attribute::TYPE_NUMBER_FLOAT_OPTIONAL:
                                                 case Attribute::TYPE_NUMBER_FLOAT_MANDATORY:
                         */
                 }
                 $selectValues .= "\n";
                 self::$objTemplate->setVariable(array('SHOP_PRODCUT_OPTION' => $selectValues, 'SHOP_PRODUCT_OPTION' => $selectValues, 'SHOP_PRODUCT_OPTIONS_NAME' => $objAttribute->getName(), 'SHOP_PRODUCT_OPTIONS_TITLE' => '<a href="javascript:{}" onclick="toggleOptions(' . $product_id . ', this)" title="' . $_ARRAYLANG['TXT_OPTIONS'] . '">' . $_ARRAYLANG['TXT_OPTIONS'] . "</a>\n"));
                 if ($mandatory && self::$objTemplate->blockExists('product_attribute_mandatory')) {
                     self::$objTemplate->touchBlock('product_attribute_mandatory');
                 }
                 self::$objTemplate->parse('shopProductOptionsValuesRow');
             }
             self::$objTemplate->parse('shopProductOptionsRow');
         }
     }
     return "return checkProductOption('shopProductForm{$formName}', " . "{$product_id}, '" . substr($checkOptionIds, 0, strlen($checkOptionIds) - 1) . "');";
 }
 /**
  * Constructor
  * @param   integer   $type         The type of the Attribute
  * @param   integer   $id           The optional Attribute ID
  * @param   integer   $product_id   The optional Product ID
  */
 function __construct($name, $type, $id = 0, $product_id = false)
 {
     $this->name = $name;
     $this->setType($type);
     $this->id = $id;
     $this->product_id = $product_id;
     if ($id) {
         $this->arrValues = Attributes::getOptionArrayByAttributeId($id);
     }
     if ($product_id) {
         $this->arrRelation = Attributes::getRelationArray($product_id);
     }
 }
Beispiel #4
0
 /**
  * Partial view of the Attributes for a Product being edited
  *
  * Only called by {@see view_product_edit()}.
  * Mind that the $product_id may be empty (usually zero) for new Products.
  * @access  private
  * @param   integer   $product_id    The ID of the Product being edited
  * @return  void
  */
 private static function viewpart_product_attributes($product_id = null)
 {
     $i = 0;
     $count = 0;
     // If a Product is selected, check those Product Attribute values
     // associated with it
     $arrRelation = Attributes::getRelationArray($product_id);
     foreach (Attributes::getArray($count) as $attribute_id => $objAttribute) {
         // All options available for this Product Attribute
         $arrOptions = Attributes::getOptionArrayByAttributeId($attribute_id);
         $nameSelected = false;
         $order = 0;
         foreach ($arrOptions as $option_id => $arrOption) {
             $valueSelected = false;
             if (in_array($option_id, array_keys($arrRelation))) {
                 $valueSelected = true;
                 $nameSelected = true;
                 $order = $arrRelation[$option_id];
             }
             self::$objTemplate->setVariable(array('SHOP_PRODUCTS_ATTRIBUTE_ID' => $attribute_id, 'SHOP_PRODUCTS_ATTRIBUTE_VALUE_ID' => $option_id, 'SHOP_PRODUCTS_ATTRIBUTE_VALUE_TEXT' => $arrOption['value'] . ' (' . $arrOption['price'] . ' ' . Currency::getDefaultCurrencySymbol() . ')', 'SHOP_PRODUCTS_ATTRIBUTE_VALUE_SELECTED' => $valueSelected ? \Html::ATTRIBUTE_CHECKED : ''));
             self::$objTemplate->parse('optionList');
         }
         self::$objTemplate->setVariable(array('SHOP_PRODUCTS_ATTRIBUTE_ROW_CLASS' => 'row' . (++$i % 2 + 1), 'SHOP_PRODUCTS_ATTRIBUTE_ID' => $attribute_id, 'SHOP_PRODUCTS_ATTRIBUTE_NAME' => $objAttribute->getName(), 'SHOP_PRODUCTS_ATTRIBUTE_SELECTED' => $nameSelected ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_PRODUCTS_ATTRIBUTE_DISPLAY_TYPE' => $nameSelected ? 'block' : 'none', 'SHOP_PRODUCTS_ATTRIBUTE_SORTID' => $order));
         self::$objTemplate->parse('attributeList');
     }
 }