コード例 #1
0
ファイル: product.class.php プロジェクト: JohnToro/paypal
 /**
  *   Display the detail page for the product.
  *
  *   @return string      HTML for the product page.
  */
 public function Detail()
 {
     global $_CONF, $_PP_CONF, $_TABLES, $LANG_PP, $_USER, $_SYSTEM;
     USES_lib_comments();
     $prod_id = $this->id;
     if ($prod_id < 1 || !$this->enabled || !$this->isAvailable()) {
         return PAYPAL_errorMessage($LANG_PP['invalid_product_id'], 'info');
     }
     $retval = COM_startBlock();
     // Set the template dir based on the configured template version
     $tpl_dir = PAYPAL_PI_PATH . '/templates/detail/' . $_PP_CONF['product_tpl_ver'];
     $T = new Template($tpl_dir);
     $T->set_file('product', 'product_detail_attrib.thtml');
     $name = $this->name;
     $l_desc = PLG_replaceTags($this->description);
     $s_desc = PLG_replaceTags($this->short_description);
     // Highlight the query terms if coming from a search
     if (isset($_REQUEST['query']) && !empty($_REQUEST['query'])) {
         $name = COM_highlightQuery($name, $_REQUEST['query']);
         $l_desc = COM_highlightQuery($l_desc, $_REQUEST['query']);
         $s_desc = COM_highlightQuery($s_desc, $_REQUEST['query']);
     }
     $onsale = $this->isOnSale();
     $act_price = $onsale ? $this->sale_price : $this->price;
     $qty_disc_txt = '';
     foreach ($this->qty_discounts as $qty => $pct) {
         $qty_disc_txt .= sprintf('Buy %d, save %.02f%%<br />', $qty, $pct);
     }
     // Get custom text input fields
     if ('' != $this->custom) {
         $T->set_block('product', 'CustAttrib', 'cAttr');
         $text_field_names = explode('|', $this->custom);
         foreach ($text_field_names as $id => $text_field_name) {
             $T->set_var(array('fld_id' => "cust_text_fld_{$id}", 'fld_name' => htmlspecialchars($text_field_name)));
             $T->parse('cAttr', 'CustAttrib', true);
         }
     }
     $T->set_var(array('is_uikit' => $_SYSTEM['framework'] == 'uikit' ? 'true' : '', 'have_attributes' => $this->hasAttributes(), 'id' => $prod_id, 'name' => $name, 'short_description' => $s_desc, 'description' => $l_desc, 'cur_decimals' => $this->currency->Decimals(), 'price' => $this->currency->FormatValue($act_price), 'orig_price' => $this->currency->Format($this->price), 'on_sale' => $onsale ? 'true' : '', 'img_cell_width' => $_PP_CONF['max_thumb_size'] + 20, 'price_prefix' => $this->currency->Pre(), 'price_postfix' => $this->currency->Post(), 'onhand' => $this->track_onhand ? $this->onhand : '', 'qty_disc' => $qty_disc_txt));
     // Retrieve the photos and put into the template
     $sql = "SELECT img_id, filename\n                FROM {$_TABLES['paypal.images']} \n                WHERE product_id='{$prod_id}'";
     //echo $sql;die;
     $img_res = DB_query($sql);
     $photo_detail = '';
     $T->set_var('have_photo', '');
     // assume no photo available
     if ($img_res && DB_numRows($img_res) > 0) {
         for ($i = 0; $prow = DB_fetchArray($img_res, false); $i++) {
             if ($prow['filename'] != '' && file_exists("{$_PP_CONF['image_dir']}/{$prow['filename']}")) {
                 if ($i == 0) {
                     $T->set_var('main_img', PAYPAL_ImageUrl($prow['filename'], $tpl_config['lg_img_width'] - 20, $tpl_config['lg_img_height'] - 20));
                 }
                 $T->set_block('product', 'Thumbnail', 'PBlock');
                 $T->set_var(array('img_file' => $prow['filename'], 'disp_img' => PAYPAL_ImageUrl($prow['filename'], $tpl_config['lg_img_width'] - 20, $tpl_config['lg_img_height'] - 20), 'lg_img' => PAYPAL_URL . '/images/products/' . $prow['filename'], 'img_url' => PAYPAL_URL . '/images/products', 'thumb_url' => PAYPAL_ImageUrl($prow['filename']), 'tn_width' => $_PP_CONF['max_thumb_size'], 'tn_height' => $_PP_CONF['max_thumb_size']));
                 $T->parse('PBlock', 'Thumbnail', true);
             }
         }
     }
     // Get the product options, if any, and set them into the form
     $cbrk = '';
     $T->set_block('product', 'AttrSelect', 'attrSel');
     foreach ($this->options as $id => $Attr) {
         /*if ($Attr['attr_value'] === '') {
               $type = 'text';
           } else {
               $type = 'select';
           }*/
         $type = 'select';
         if ($Attr['attr_name'] != $cbrk) {
             if ($cbrk != '') {
                 // end block if not the first element
                 $T->set_var(array('attr_name' => $cbrk, 'attr_options' => $attributes, 'opt_id' => $id));
                 $T->parse('attrSel', 'AttrSelect', true);
             }
             $cbrk = $Attr['attr_name'];
             $attributes = '';
         }
         if ($type == 'select') {
             if ($Attr['attr_price'] != 0) {
                 $attr_str = sprintf(" ( %+.2f )", $Attr['attr_price']);
             } else {
                 $attr_str = '';
             }
             $attributes .= '<option value="' . $id . '|' . $Attr['attr_value'] . '|' . $Attr['attr_price'] . '">' . $Attr['attr_value'] . $attr_str . '</option>' . LB;
             /*} else {
                   $attributes .= "<input type=\"hidden\" name=\"on{$i}\" 
                           value=\"{$Attr['attr_name']}\">\n";
                   $attributes .= $Attr['attr_name'] . ':</td>
                       <td><input class="uk-contrast uk-form" type"text" name="os' . $i. '" value="" size="32" /></td></tr>';
               */
         }
     }
     if ($cbrk != '') {
         // finish off the last selection
         $T->set_var(array('attr_name' => $cbrk, 'attr_options' => $attributes, 'opt_id' => $id));
         $T->parse('attrSel', 'AttrSelect', true);
     }
     $buttons = $this->PurchaseLinks();
     $T->set_block('product', 'BtnBlock', 'Btn');
     foreach ($buttons as $name => $html) {
         if ($name == 'add_cart') {
             // Set the add to cart button in the main form
             $T->set_var('add_cart_button', $html);
         } else {
             $T->set_var('buy_now_button', $html);
             $T->parse('Btn', 'BtnBlock', true);
         }
     }
     // Show the user comments if enabled globally and for this product
     if (plugin_commentsupport_paypal() && $this->comments_enabled != PP_COMMENTS_DISABLED) {
         // if enabled or closed
         if ($_CONF['commentsloginrequired'] == 1 && COM_isAnonUser()) {
             // Set mode to "disabled"
             $mode = -1;
         } else {
             $mode = $this->comments_enabled;
         }
         $T->set_var('usercomments', CMT_userComments($prod_id, $this->short_description, 'paypal', '', '', 0, 1, false, false, $mode));
     }
     if ($this->rating_enabled == 1) {
         $PP_ratedIds = RATING_getRatedIds('paypal');
         if (in_array($prod_id, $PP_ratedIds)) {
             $static = true;
             $voted = 1;
         } elseif (plugin_canuserrate_paypal($A['id'], $_USER['uid'])) {
             $static = 0;
             $voted = 0;
         } else {
             $static = 1;
             $voted = 0;
         }
         $rating_box = RATING_ratingBar('paypal', $prod_id, $this->votes, $this->rating, $voted, 5, $static, 'sm');
         $T->set_var('rating_bar', $rating_box);
     } else {
         $T->set_var('ratign_bar', '');
     }
     if ($this->isAdmin) {
         // Add the quick-edit link for administrators
         $T->set_var(array('pi_admin_url' => PAYPAL_ADMIN_URL, 'can_edit' => 'true'));
     }
     $retval .= $T->parse('output', 'product');
     // Update the hit counter
     DB_query("UPDATE {$_TABLES['paypal.products']}\n                SET views = views + 1\n                WHERE id = '{$prod_id}'");
     $retval .= COM_endBlock();
     return $retval;
 }
コード例 #2
0
ファイル: product.class.php プロジェクト: NewRoute/paypal
 /**
  *   Display the detail page for the product.
  *
  *   @return string      HTML for the product page.
  */
 public function Detail()
 {
     global $_CONF, $_PP_CONF, $_TABLES, $LANG_PP, $_USER;
     USES_lib_comments();
     $prod_id = $this->id;
     if ($prod_id < 1 || !$this->enabled) {
         return PAYPAL_errorMessage($LANG_PP['invalid_product_id'], 'info');
     }
     $retval = COM_startBlock();
     // Set the template dir based on the configured template version
     $T = new Template(PAYPAL_PI_PATH . '/templates/detail' . $_PP_CONF['tpl_ver_detail']);
     if ($this->hasAttributes()) {
         $detail_template = 'product_detail_attrib.thtml';
     } else {
         $detail_template = 'product_detail.thtml';
     }
     $T->set_file('product', $detail_template);
     $name = $this->name;
     $l_desc = PLG_replaceTags($this->description);
     $s_desc = PLG_replaceTags($this->short_description);
     // Highlight the query terms if coming from a search
     if (isset($_REQUEST['query']) && !empty($_REQUEST['query'])) {
         $name = COM_highlightQuery($name, $_REQUEST['query']);
         $l_desc = COM_highlightQuery($l_desc, $_REQUEST['query']);
         $s_desc = COM_highlightQuery($s_desc, $_REQUEST['query']);
     }
     $act_price = $this->sale_price == $this->price ? $this->price : $this->sale_price;
     $T->set_var(array('id' => $prod_id, 'name' => $name, 'short_description' => $s_desc, 'description' => $l_desc, 'cur_decimals' => $this->currency->Decimals(), 'price' => $this->currency->FormatValue($act_price), 'orig_price' => $this->currency->Format($this->price), 'on_sale' => $act_price == $this->price ? '' : 'true', 'img_cell_width' => $_PP_CONF['max_thumb_size'] + 20, 'price_prefix' => $this->currency->Pre(), 'price_postfix' => $this->currency->Post(), 'onhand' => $this->track_onhand ? $this->onhand : ''));
     // Retrieve the photos and put into the template
     $sql = "SELECT img_id, filename\n                FROM {$_TABLES['paypal.images']} \n                WHERE product_id='{$prod_id}'";
     //echo $sql;die;
     $img_res = DB_query($sql);
     $photo_detail = '';
     $T->set_var('have_photo', '');
     // assume no photo available
     if ($img_res && DB_numRows($img_res) > 0) {
         for ($i = 0; $prow = DB_fetchArray($img_res, false); $i++) {
             if ($prow['filename'] != '' && file_exists("{$_PP_CONF['image_dir']}/{$prow['filename']}")) {
                 if ($i == 0) {
                     $T->set_var('main_img', $prow['filename']);
                 }
                 $T->set_block('product', 'Thumbnail', 'PBlock');
                 $T->set_var('img_file', $prow['filename']);
                 $T->set_var('img_url', PAYPAL_URL . '/images/products');
                 $T->set_var('thumb_url', PAYPAL_ImageUrl($prow['filename']));
                 $T->parse('PBlock', 'Thumbnail', true);
                 $T->set_var('have_photo', 'true');
             }
         }
     }
     // Get the product options, if any, and set them into the form
     $i = 0;
     $cbrk = '';
     $attributes = '';
     foreach ($this->options as $id => $Attr) {
         if ($Attr['attr_name'] != $cbrk) {
             if ($i > 0) {
                 $attributes .= "</select></td></tr>\n";
             } else {
                 $attributes = '<table border="0">' . "\n";
             }
             $cbrk = $Attr['attr_name'];
             $attributes .= "<tr><td>\n                    <input type=\"hidden\" name=\"on{$i}\" \n                    value=\"{$Attr['attr_name']}\">\n\n                    <input type=\"hidden\" name=\"os{$i}\" \n                    value=\"\">\n\n                    {$Attr['attr_name']}:</td>\n                    <td align=\"left\">\n                    <select name=\"options[]\"\n                    onchange=\"ProcessForm(this.form);\">\n";
             /*<td align=\"left\"><select name=\"pp_os{$i}\"*/
             $i++;
         }
         if ($Attr['attr_price'] != 0) {
             $attr_str = sprintf(" ( %+.2f )", $Attr['attr_price']);
         } else {
             $attr_str = '';
         }
         $attributes .= '<option value="' . $id . '|' . $Attr['attr_value'] . '|' . $Attr['attr_price'] . '">' . $Attr['attr_value'] . $attr_str . '</option>' . LB;
     }
     if ($attributes != '') {
         $attributes .= "</select></td></tr></table>\n";
         $T->set_var('attributes', $attributes);
     }
     $buttons = $this->PurchaseLinks();
     $T->set_block('product', 'BtnBlock', 'Btn');
     foreach ($buttons as $name => $html) {
         $T->set_var('button', $html);
         $T->parse('Btn', 'BtnBlock', true);
     }
     // Show the user comments if enabled globally and for this product
     if (plugin_commentsupport_paypal() && $this->comments_enabled != PP_COMMENTS_DISABLED) {
         // if enabled or closed
         if ($_CONF['commentsloginrequired'] == 1 && COM_isAnonUser()) {
             // Set mode to "disabled"
             $mode = -1;
         } else {
             $mode = $this->comments_enabled;
         }
         $T->set_var('usercomments', CMT_userComments($prod_id, $this->short_description, 'paypal', '', '', 0, 1, false, false, $mode));
     }
     if ($this->rating_enabled == 1) {
         $PP_ratedIds = RATING_getRatedIds('paypal');
         if (in_array($prod_id, $PP_ratedIds)) {
             $static = true;
             $voted = 1;
         } elseif (plugin_canuserrate_paypal($A['id'], $_USER['uid'])) {
             $static = 0;
             $voted = 0;
         } else {
             $static = 1;
             $voted = 0;
         }
         $rating_box = RATING_ratingBar('paypal', $prod_id, $this->votes, $this->rating, $voted, 5, $static, 'sm');
         $T->set_var('rating_bar', $rating_box);
     } else {
         $T->set_var('ratign_bar', '');
     }
     if ($this->isAdmin) {
         // Add the quick-edit link for administrators
         $T->set_var(array('pi_admin_url' => PAYPAL_ADMIN_URL, 'can_edit' => 'true'));
     }
     $retval .= $T->parse('output', 'product');
     // Update the hit counter
     DB_query("UPDATE {$_TABLES['paypal.products']}\n                SET views = views + 1\n                WHERE id = '{$prod_id}'");
     $retval .= COM_endBlock();
     return $retval;
 }