/administrator/components/com_virtuemart/classes/ps_product.php
PHP | 2743 lines | 1976 code | 250 blank | 517 comment | 367 complexity | 912628defcddc12db09e6304fee92fb8 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
- /**
- *
- * @version $Id: ps_product.php 1475 2008-07-16 17:35:35Z soeren_nb $
- * @package VirtueMart
- * @subpackage classes
- * @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
- * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
- * VirtueMart is free software. This version may have been modified pursuant
- * to the GNU General Public License, and as distributed it includes or
- * is derivative of works licensed under the GNU General Public License or
- * other free or open source software licenses.
- * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
- *
- * http://virtuemart.net
- */
- /**
- * The class is is used to manage product repository.
- * @package virtuemart
- * @author pablo, jep, gday, soeren
- *
- */
- class ps_product extends vmAbstractObject {
- var $_key = 'product_id';
- var $_table_name = '#__{vm}_product';
-
- /**
- * Validates product fields and uploaded image files.
- *
- * @param array $d The input vars
- * @return boolean True when validation successful, false when not
- */
- function validate(&$d) {
- global $vmLogger, $database, $perm, $VM_LANG;
- require_once(CLASSPATH . 'imageTools.class.php' );
-
- $valid = true;
- $db = new ps_DB;
- $q = "SELECT product_id,product_thumb_image,product_full_image FROM #__{vm}_product WHERE product_sku='";
- $q .= $d["product_sku"] . "'";
- $db->setQuery($q); $db->query();
- if ($db->next_record()&&($db->f("product_id") != $d["product_id"])) {
- $vmLogger->err( "A Product with the SKU ".$d['product_sku']." already exists." );
- $valid = false;
- }
- if( !empty( $d['product_discount_id'] )) {
- if( $d['product_discount_id'] == "override" ) {
- $d['is_percent'] = "0";
-
- // If discount are applied before tax then base the discount on the untaxed price
- if( PAYMENT_DISCOUNT_BEFORE == '1' ) {
- $d['amount'] = (float)$d['product_price'] - (float)$d['discounted_price_override'];
- }
- // Otherwise, base the discount on the taxed price
- else {
- $d['amount'] = (float)$d['product_price_incl_tax'] - (float)$d['discounted_price_override'];
- }
-
- // Set the discount start date as today
- $d['start_date'] = date( 'Y-m-d' );
- require_once( CLASSPATH. 'ps_product_discount.php' );
- $ps_product_discount = new ps_product_discount;
- $ps_product_discount->add( $d );
- $d['product_discount_id'] = $database->insertid();
- vmRequest::setVar( 'product_discount_id', $d['product_discount_id'] );
- }
- }
- if (empty($d['manufacturer_id'])) {
- $d['manufacturer_id'] = "1";
- }
- if (empty( $d["product_sku"])) {
- $vmLogger->err( $VM_LANG->_('VM_PRODUCT_MISSING_SKU',false) );
- $valid = false;
- }
- if (!$d["product_name"]) {
- $vmLogger->err( $VM_LANG->_('VM_PRODUCT_MISSING_NAME',false) );
- $valid = false;
- }
- if (empty($d["product_available_date"])) {
- $vmLogger->err( $VM_LANG->_('VM_PRODUCT_MISSING_AVAILDATE',false) );
- $valid = false;
- }
- else {
- $day = (int) substr ( $d["product_available_date"], 8, 2);
- $month= (int) substr ( $d["product_available_date"], 5, 2);
- $year = (int) substr ( $d["product_available_date"], 0, 4);
- $d["product_available_date_timestamp"] = mktime(0,0,0,$month, $day, $year);
- }
- /** Validate Product Specific Fields **/
- if (!$d["product_parent_id"]) {
- if( empty( $d['product_categories']) || !is_array(@$d['product_categories'])) {
- $d['product_categories'] = explode('|', $d['category_ids'] );
- }
- if (sizeof(@$d["product_categories"]) < 1) {
- $vmLogger->err( $VM_LANG->_('VM_PRODUCT_MISSING_CATEGORY') );
- $valid = false;
- }
- }
- /** Image Upload Validation **/
- // do we have an image URL or an image File Upload?
- if (!empty( $d['product_thumb_image_url'] )) {
- // Image URL
- if (substr( $d['product_thumb_image_url'], 0, 4) != "http") {
- $vmLogger->err( $VM_LANG->_('VM_PRODUCT_IMAGEURL_MUSTBEGIN',false) );
- $valid = false;
- }
- // if we have an uploaded image file, prepare this one for deleting.
- if( $db->f("product_thumb_image") && substr( $db->f("product_thumb_image"), 0, 4) != "http") {
- $_REQUEST["product_thumb_image_curr"] = $db->f("product_thumb_image");
- $d["product_thumb_image_action"] = "delete";
- if (!vmImageTools::validate_image($d,"product_thumb_image","product")) {
- return false;
- }
- }
- $d["product_thumb_image"] = $d['product_thumb_image_url'];
- }
- else {
- // File Upload
- if (!vmImageTools::validate_image($d,"product_thumb_image","product")) {
- $valid = false;
- }
- }
- if (!empty( $d['product_full_image_url'] )) {
- // Image URL
- if (substr( $d['product_full_image_url'], 0, 4) != "http") {
- $vmLogger->err( $VM_LANG->_('VM_PRODUCT_IMAGEURL_MUSTBEGIN',false) );
- return false;
- }
- // if we have an uploaded image file, prepare this one for deleting.
- if( $db->f("product_full_image") && substr( $db->f("product_full_image"), 0, 4) != "http") {
- $_REQUEST["product_full_image_curr"] = $db->f("product_full_image");
- $d["product_full_image_action"] = "delete";
- if (!vmImageTools::validate_image($d,"product_full_image","product")) {
- return false;
- }
- }
- $d["product_full_image"] = $d['product_full_image_url'];
- }
- else {
- // File Upload
- if (!vmImageTools::validate_image($d,"product_full_image","product")) {
- $valid = false;
- }
- }
-
- // added for advanced attribute modification
- // strips the trailing semi-colon from an attribute
- if(isset($d["product_advanced_attribute"])) {
- if (';' == substr($d["product_advanced_attribute"], strlen($d["product_advanced_attribute"])-1,1) ) {
- $d["product_advanced_attribute"] =substr($d["product_advanced_attribute"], 0, strlen($d["product_advanced_attribute"])-1);
- }
- }
- // added for custom attribute modification
- // strips the trailing semi-colon from an attribute
- if(isset($d["product_custom_attribute"])) {
- if (';' == substr($d["product_custom_attribute"], strlen($d["product_custom_attribute"])-1,1) ) {
- $d["product_custom_attribute"] =substr($d["product_custom_attribute"], 0, strlen($d["product_custom_attribute"])-1);
- }
- }
- $d["clone_product"] = empty($d["clone_product"]) ? "N" : "Y";
- $d["product_publish"] = empty($d["product_publish"]) ? "N" : "Y";
- $d["product_special"] = empty($d["product_special"]) ? "N" : "Y";
- //parse quantity and child options
- $d['display_headers'] = vmGet($d,'display_headers', 'Y') =='Y' ? 'Y' : 'N';
- $d['product_list_child'] = vmGet($d,'product_list_child', 'Y') =='Y' ? 'Y' : 'N';
- $d['display_use_parent'] = vmGet($d,'display_use_parent', 'Y') =='Y' ? 'Y' : 'N';
- $d['product_list_type'] = vmGet($d,'product_list_type', 'Y') =='Y' ? 'Y' : 'N';
- $d['display_desc'] = vmGet($d,'display_desc', 'Y') =='Y' ? 'Y' : 'N';
-
- if (@$d['product_list'] =="Y") {
- if($d['list_style'] == "one")
- $d['product_list'] = "Y";
- else
- $d['product_list'] = "YM";
- }
- else {
- $d['product_list'] = "N";
- }
-
- $d['quantity_options'] = ps_product::set_quantity_options($d);
- $d['child_options'] = ps_product::set_child_options($d);
-
- $d['order_levels'] = vmRequest::getInt('min_order_level').",".vmRequest::getInt('max_order_level');
-
- return $valid;
- }
- /**
- * Validates that a product can be deleted
- *
- * @param array $d The input vars
- * @return boolean Validation sucessful?
- */
- function validate_delete( $product_id, &$d ) {
- global $vmLogger, $VM_LANG;
- require_once(CLASSPATH . 'imageTools.class.php' );
- /* Check that ps_vendor_id and product_id match
- if (!$this->check_vendor($d)) {
- $d["error"] = "ERROR: Cannot delete product. Wrong product or vendor." ;
- return false;
- }*/
- if (empty($product_id)) {
- $vmLogger->err( $VM_LANG->_('VM_PRODUCT_SPECIFY_DELETE',false) );
- return false;
- }
- /* Get the image filenames from the database */
- $db = new ps_DB;
- $q = "SELECT product_thumb_image,product_full_image ";
- $q .= "FROM #__{vm}_product ";
- $q .= "WHERE product_id='$product_id'";
- $db->setQuery($q); $db->query();
- $db->next_record();
- /* Prepare product_thumb_image for Deleting */
- if( !stristr( $db->f("product_thumb_image"), "http") ) {
- $_REQUEST["product_thumb_image_curr"] = $db->f("product_thumb_image");
- $d["product_thumb_image_action"] = "delete";
- if (!vmImageTools::validate_image($d,"product_thumb_image","product")) {
- $vmLogger->err( $VM_LANG->_('VM_PRODUCT_IMGDEL_FAILED',false) );
- return false;
- }
- }
- /* Prepare product_full_image for Deleting */
- if( !stristr( $db->f("product_full_image"), "http") ) {
- $_REQUEST["product_full_image_curr"] = $db->f("product_full_image");
- $d["product_full_image_action"] = "delete";
- if (!vmImageTools::validate_image($d,"product_full_image","product")) {
- return false;
- }
- }
- return true;
- }
- /**
- * Function to add a new product into the product table
- *
- * @param array $d The input vars
- * @return boolean True, when the product was added, false when not
- */
- function add( &$d ) {
- global $perm, $vmLogger, $VM_LANG;
- $database = new ps_DB();
- if (!$this->validate($d)) {
- return false;
- }
- if (!vmImageTools::process_images($d)) {
- return false;
- }
- $timestamp = time();
- $db = new ps_DB;
- $ps_vendor_id = $_SESSION["ps_vendor_id"];
- if( $perm->check( 'admin' )) {
- $vendor_id = $d['vendor_id'];
- }
- else {
- $vendor_id = $ps_vendor_id;
- }
- // Insert into DB
- $fields = array ( 'vendor_id' => $vendor_id,
- 'product_parent_id' => vmRequest::getInt('product_parent_id'),
- 'product_sku' => vmGet($d,'product_sku'),
- 'product_name' => vmGet($d,'product_name'),
- 'product_desc' => vmRequest::getVar('product_desc', '', 'default', '', VMREQUEST_ALLOWHTML),
- 'product_s_desc' => vmRequest::getVar('product_s_desc', '', 'default', '', VMREQUEST_ALLOWHTML),
- 'product_thumb_image' => vmGet($d,'product_thumb_image'),
- 'product_full_image' => vmGet($d,'product_full_image'),
- 'product_publish' => $d['product_publish'],
- 'product_weight' => vmRequest::getFloat('product_weight'),
- 'product_weight_uom' => vmGet($d,'product_weight_uom'),
- 'product_length' => vmRequest::getFloat('product_length'),
- 'product_width' => vmRequest::getFloat('product_width'),
- 'product_height' => vmRequest::getFloat('product_height'),
- 'product_lwh_uom' => vmGet($d,'product_lwh_uom'),
- 'product_unit' => vmGet($d,'product_unit'),
- 'product_packaging' => (($d["product_box"] << 16) | ($d["product_packaging"]&0xFFFF)),
- 'product_url' => vmGet($d,'product_url'),
- 'product_in_stock' => vmRequest::getInt('product_in_stock'),
- 'attribute' => ps_product_attribute::formatAttributeX(),
- 'custom_attribute' => vmGet($d,'product_custom_attribute'),
- 'product_available_date' => $d['product_available_date_timestamp'],
- 'product_availability' => vmGet($d,'product_availability'),
- 'product_special' => $d['product_special'],
- 'child_options' => $d['child_options'],
- 'quantity_options' => $d['quantity_options'],
- 'product_discount_id' => vmRequest::getInt('product_discount_id'),
- 'cdate' => $timestamp,
- 'mdate' => $timestamp,
- 'product_tax_id' => vmRequest::getInt('product_tax_id'),
- 'child_option_ids' => vmGet($d,'included_product_id'),
- 'product_order_levels' => $d['order_levels'] );
- $db->buildQuery('INSERT', '#__{vm}_product', $fields );
- if( $db->query() === false ) {
- $vmLogger->err( $VM_LANG->_('VM_PRODUCT_ADDING_FAILED',false) );
- return false;
- }
- $d["product_id"] = $_REQUEST['product_id'] = $db->last_insert_id();
- // If is Item, add attributes from parent //
- if ($d["product_parent_id"]) {
- $q = "SELECT attribute_name FROM #__{vm}_product_attribute_sku ";
- $q .= "WHERE product_id='" . vmRequest::getInt('product_parent_id') . "' ";
- $q .= "ORDER BY attribute_list,attribute_name";
- $db->query($q);
- $db2 = new ps_DB;
- $i = 0;
- while($db->next_record()) {
- $i++;
-
- $q = "INSERT INTO #__{vm}_product_attribute (`product_id`,`attribute_name`,`attribute_value`) VALUES ";
- $q .= "('".$d["product_id"]."', '".$db->f("attribute_name", false)."', '".vmGet($d,'attribute_'.$i )."')";
- $db2->query( $q );
- }
- }
- else {
- // If is Product, Insert category ids
- if( empty( $d['product_categories']) || !is_array(@$d['product_categories'])) {
- $d['product_categories'] = explode('|', $d['category_ids'] );
- }
- foreach( $d["product_categories"] as $category_id ) {
- $db->query('SELECT MAX(`product_list`) as list_order FROM `#__{vm}_product_category_xref` WHERE `category_id`='.$category_id );
- $db->next_record();
- $q = "INSERT INTO #__{vm}_product_category_xref ";
- $q .= "(category_id,product_id,product_list) ";
- $q .= "VALUES ('$category_id','". $d["product_id"] . "', ".intval($db->f('max') +1 ) . ")";
- $db->setQuery($q); $db->query();
- }
- }
- $q = "INSERT INTO #__{vm}_product_mf_xref VALUES (";
- $q .= "'".$d['product_id']."', '".vmRequest::getInt('manufacturer_id')."')";
- $db->setQuery($q); $db->query();
- if( !empty($d["related_products"])) {
- /* Insert Pipe separated Related Product IDs */
- $related_products = vmGet( $d, "related_products" );
- $q = "INSERT INTO #__{vm}_product_relations ";
- $q .= "(product_id, related_products) ";
- $q .= "VALUES ('".$d["product_id"]."','".$db->getEscaped($related_products)."')";
- $db->setQuery($q); $db->query();
- }
- // ADD A PRICE, IF NOT EMPTY ADD 0
- if (!empty($d['product_price'])) {
- if(empty($d['product_currency'])) {
- $d['product_currency'] = $_SESSION['vendor_currency'];
- }
- $d["price_quantity_start"] = 0;
- $d["price_quantity_end"] = "";
- require_once ( CLASSPATH. 'ps_product_price.php');
- $my_price = new ps_product_price;
- $my_price->add($d);
- }
-
- if( !empty( $d['product_type_id'])) {
- require_once( CLASSPATH.'ps_product_product_type.php' );
- $ps_product_product_type = new ps_product_product_type();
- $ps_product_product_type->add( $d );
-
- // Product Type Parameters!
- $this->handleParameters( $d );
- }
-
- // CLONE PRODUCT additional code
- if( $d["clone_product"] == "Y" ) {
- // Clone Parent Product's Attributes
- $q = "INSERT INTO #__{vm}_product_attribute_sku
- SELECT '".$d["product_id"]."', attribute_name, attribute_list
- FROM #__{vm}_product_attribute_sku WHERE product_id='" . (int)$d["old_product_id"] . "' ";
- $db->query( $q );
- if( !empty( $d["child_items"] )) {
- $database->query( "SHOW COLUMNS FROM #__{vm}_product" );
- $rows = $database->record;
- while(list(,$Field) = each( $rows) ) {
- $product_fields[$Field->Field] = $Field->Field;
- }
- // Change the Field Names
- // leave empty for auto_increment
- $product_fields["product_id"] = "''";
- // Update Product Parent ID to the new one
- $product_fields["product_parent_id"] = "'".$d["product_id"]."'";
- // Rename the SKU
- $product_fields["product_sku"] = "CONCAT(product_sku,'_".$d["product_id"]."')";
- $rows = Array();
- $database->query( "SHOW COLUMNS FROM #__{vm}_product_price" );
- $rows = $database->record;
- while(list(,$Field) = each( $rows) ) {
- $price_fields[$Field->Field] = $Field->Field;
- }
- foreach( $d["child_items"] as $child_id ) {
- $q = "INSERT INTO #__{vm}_product ";
- $q .= "SELECT ".implode(",", $product_fields )." FROM #__{vm}_product WHERE product_id='$child_id'";
- $db->query( $q );
- $new_product_id = $db->last_insert_id();
- $q = "INSERT INTO #__{vm}_product_attribute
- SELECT NULL, '$new_product_id', attribute_name, attribute_value
- FROM #__{vm}_product_attribute WHERE product_id='$child_id'";
- $db->query( $q );
- $price_fields["product_price_id"] = "''";
- $price_fields["product_id"] = "'$new_product_id'";
- $q = "INSERT INTO #__{vm}_product_price ";
- $q .= "SELECT ".implode(",", $price_fields )." FROM #__{vm}_product_price WHERE product_id='$child_id'";
- $db->query( $q );
- }
- }
- // End Cloning
- }
- if( $d['clone_product'] == 'Y') {
- $vmLogger->info( $VM_LANG->_('VM_PRODUCT_CLONED',false) );
- }
- else {
- $vmLogger->info( $VM_LANG->_('VM_PRODUCT_ADDED',false) );
- }
- return true;
- }
- /**
- * Function to update product $d['product_id'] in the product table
- *
- * @param array $d The input vars
- * @return boolean True, when the product was updated, false when not
- */
- function update( &$d ) {
- global $vmLogger, $perm, $VM_LANG;
- require_once(CLASSPATH.'ps_product_attribute.php');
-
- if (!$this->validate($d)) {
- return false;
- }
- if (!vmImageTools::process_images($d)) {
- return false;
- }
- $timestamp = time();
- $db = new ps_DB;
- $ps_vendor_id = $_SESSION["ps_vendor_id"];
- if( $perm->check( 'admin' )) {
- $vendor_id = $d['vendor_id'];
- }
- else {
- $vendor_id = $ps_vendor_id;
- }
- $old_vendor_id = $this->get_field($d['product_id'], 'vendor_id');
-
- // Insert into DB
- $fields = array ( 'vendor_id' => $vendor_id,
- 'product_sku' => vmGet($d,'product_sku'),
- 'product_name' => vmGet($d,'product_name'),
- 'product_desc' => vmRequest::getVar('product_desc', '', 'default', '', VMREQUEST_ALLOWHTML),
- 'product_s_desc' => vmRequest::getVar('product_s_desc', '', 'default', '', VMREQUEST_ALLOWHTML),
- 'product_thumb_image' => vmGet($d,'product_thumb_image'),
- 'product_full_image' => vmGet($d,'product_full_image'),
- 'product_publish' => $d['product_publish'],
- 'product_weight' => vmRequest::getFloat('product_weight'),
- 'product_weight_uom' => vmGet($d,'product_weight_uom'),
- 'product_length' => vmRequest::getFloat('product_length'),
- 'product_width' => vmRequest::getFloat('product_width'),
- 'product_height' => vmRequest::getFloat('product_height'),
- 'product_lwh_uom' => vmGet($d,'product_lwh_uom'),
- 'product_unit' => vmGet($d,'product_unit'),
- 'product_packaging' => (($d["product_box"] << 16) | ($d["product_packaging"]&0xFFFF)),
- 'product_url' => vmGet($d,'product_url'),
- 'product_in_stock' => vmRequest::getInt('product_in_stock'),
- 'attribute' => ps_product_attribute::formatAttributeX(),
- 'custom_attribute' => vmGet($d,'product_custom_attribute'),
- 'product_available_date' => $d['product_available_date_timestamp'],
- 'product_availability' => vmGet($d,'product_availability'),
- 'product_special' => $d['product_special'],
- 'child_options' => $d['child_options'],
- 'quantity_options' => $d['quantity_options'],
- 'product_discount_id' => vmRequest::getInt('product_discount_id'),
- 'mdate' => $timestamp,
- 'product_tax_id' => vmRequest::getInt('product_tax_id'),
- 'child_option_ids' => vmGet($d,'included_product_id'),
- 'product_order_levels' => $d['order_levels'] );
-
- $db->buildQuery( 'UPDATE', '#__{vm}_product', $fields, 'WHERE product_id='. (int)$d["product_id"] . ' AND vendor_id=' . (int)$old_vendor_id );
- $db->query();
- /* notify the shoppers that the product is here */
- /* see zw_waiting_list */
- if ($d["product_in_stock"] > "0" && @$d['notify_users'] == '1' && $d['product_in_stock_old'] == '0') {
- require_once( CLASSPATH . 'zw_waiting_list.php');
- $zw_waiting_list = new zw_waiting_list;
- $zw_waiting_list->notify_list($d["product_id"]);
- }
- $q = "UPDATE #__{vm}_product_mf_xref SET ";
- $q .= 'manufacturer_id='.vmRequest::getInt('manufacturer_id').' ';
- $q .= 'WHERE product_id = '.$d['product_id'];
- $db->query($q);
- /* If is Item, update attributes */
- if( !empty($d["product_parent_id"])) {
- $q = "SELECT attribute_name FROM #__{vm}_product_attribute_sku ";
- $q .= 'WHERE product_id=' .(int)$d["product_parent_id"] . ' ';
- $q .= "ORDER BY attribute_list,attribute_name";
- $db->query($q);
- $db2 = new ps_DB;
- $i = 0;
- while($db->next_record()) {
- $i++;
- $q2 = "UPDATE #__{vm}_product_attribute SET ";
- $q2 .= "attribute_value='" .vmGet($d,'attribute_'.$i ) . "' ";
- $q2 .= "WHERE product_id = '" . $d["product_id"] . "' ";
- $q2 .= "AND attribute_name = '" . $db->f("attribute_name", false ) . "' ";
- $db2->setQuery($q2); $db2->query();
- }
- /* If it is a Product, update Category */
- }
- else {
- // Handle category selection: product_category_xref
- $q = "SELECT `category_id` FROM `#__{vm}_product_category_xref` ";
- $q .= "WHERE `product_id` = '" . $d["product_id"] . "' ";
- $db->setQuery($q);
- $db->query();
- $old_categories = array();
- while( $db->next_record()) {
- $old_categories[$db->f('category_id')] = $db->f('category_id');
- }
- // NOW Insert new categories
- $new_categories = array();
-
- if( empty( $d['product_categories']) || !is_array(@$d['product_categories'])) {
- $d['product_categories'] = explode('|', $d['category_ids'] );
- }
-
- foreach( $d["product_categories"] as $category_id ) {
- if( !in_array( $category_id, $old_categories ) ) {
- $db->query('SELECT MAX(`product_list`) as list_order FROM `#__{vm}_product_category_xref` WHERE `category_id`='.(int)$category_id );
- $db->next_record();
- $q = "INSERT INTO #__{vm}_product_category_xref ";
- $q .= "(category_id,product_id,product_list) ";
- $q .= "VALUES ('".(int)$category_id."','". $d["product_id"] . "', ".intval($db->f('max') +1 ) . ")";
- $db->setQuery($q); $db->query();
- $new_categories[$category_id] = $category_id;
- }
- else {
- unset( $old_categories[$category_id]);
- }
- }
- // The rest of the old categories can be deleted
- foreach( $old_categories as $category_id ) {
- $q = "DELETE FROM `#__{vm}_product_category_xref` ";
- $q .= "WHERE `product_id` = '" . $d["product_id"] . "' ";
- $q .= "AND `category_id` = '" . $category_id . "' ";
- $db->query($q);
- }
- }
- if( !empty($d["related_products"])) {
- /* Insert Pipe separated Related Product IDs */
- $related_products = vmGet( $d, "related_products" );
- $q = "REPLACE INTO #__{vm}_product_relations (product_id, related_products)";
- $q .= " VALUES( '".$d["product_id"]."', '$related_products') ";
- $db->query($q);
- }
- else{
- $q = "DELETE FROM #__{vm}_product_relations WHERE product_id='".$d["product_id"]."'";
- $db->query($q);
- }
- // UPDATE THE PRICE, IF EMPTY ADD 0
- if(empty($d['product_currency'])) {
- $d['product_currency'] = $_SESSION['vendor_currency'];
- }
- // look if we have a price for this product
- $q = "SELECT product_price_id, price_quantity_start, price_quantity_end FROM #__{vm}_product_price ";
- $q .= "WHERE shopper_group_id=" . vmRequest::getInt('shopper_group_id');
- $q .= ' AND product_id = ' . $d["product_id"];
- $db->query($q);
- if ($db->next_record()) {
- $d["product_price_id"] = $db->f("product_price_id");
- require_once ( CLASSPATH. 'ps_product_price.php');
- $my_price = new ps_product_price;
- if (@$d['product_price'] != '') {
- // update prices
- $d["price_quantity_start"] = $db->f("price_quantity_start");
- $d["price_quantity_end"] = $db->f("price_quantity_end");
- $my_price->update($d);
- }
- else {
- // delete the price
- $my_price->delete( $d );
- }
- }
- else {
- if ( $d['product_price'] != '' ) {
- // add the price
- $d["price_quantity_start"] = 0;
- $d["price_quantity_end"] = "";
- require_once ( CLASSPATH. 'ps_product_price.php');
- $my_price = new ps_product_price;
- $my_price->add($d);
- }
- }
- // Product Type Parameters!
- $this->handleParameters( $d );
-
- $vmLogger->info( $VM_LANG->_('VM_PRODUCT_UPDATED',false) );
- return true;
- }
-
- /**
- * Handles adding or updating parameter values for a product an its product types
- * @since VirtueMart 1.1.0
- * @param array $d
- */
- function handleParameters( &$d ) {
- global $db;
-
- $product_id= intval( $d["product_id"] );
- $q = "SELECT `product_type_id` FROM `#__{vm}_product_product_type_xref` WHERE ";
- $q .= "`product_id`=$product_id";
- $db->query($q);
- $dbpt = new ps_DB;
- $dbp = new ps_DB;
- // For every Product Type
- while ($db->next_record()) {
- $product_type_id = $db->f("product_type_id");
- $q = "SELECT * FROM #__{vm}_product_type_parameter WHERE ";
- $q .= "product_type_id='$product_type_id' ";
- $q .= "ORDER BY parameter_list_order";
- $dbpt->query($q);
- $q = "SELECT COUNT(`product_id`) as num_rows FROM `#__{vm}_product_type_$product_type_id` WHERE ";
- $q .= "product_id='$product_id'";
- $dbp->query($q); $dbp->next_record();
-
- if ( $dbp->f('num_rows') == 0 ) { // Add record if not exist (Items)
- $q = "INSERT INTO #__{vm}_product_type_$product_type_id (product_id) ";
- $q .= "VALUES ('$product_id')";
- $dbp->query($q);
- }
- // Update record
- $q = "UPDATE #__{vm}_product_type_$product_type_id SET ";
- $q .= "product_id='$product_id'";
- while ($dbpt->next_record()) {
- if ($dbpt->f("parameter_type")!="B") { // if it is not breaker
- $value=$d["product_type_".$product_type_id."_".$dbpt->f("parameter_name")];
- if ($dbpt->f("parameter_type")=="V" && is_array($value)) {
- $value = join(';',$value);
- }
- if ($value=="") {
- $value='NULL';
- }
- else {
- $value="'".$dbpt->getEscaped($value)."'";
- }
- $q .= ',`'.$dbpt->f('parameter_name', false).'`='.$value;
- }
- }
- $q .= ' WHERE product_id = '.$d['product_id'];
- $dbp->query($q);
- }
- }
-
- /**
- * Function to delete product(s) $d['product_id'] from the product table
- *
- * @param array $d The input vars
- * @return boolean True, when the product was deleted, false when not
- */
- function delete(&$d) {
- $product_id = $d["product_id"];
- if( is_array( $product_id)) {
- foreach( $product_id as $product) {
- if( !$this->delete_product( $product, $d ))
- return false;
- }
- return true;
- }
- else {
- return $this->delete_product( $product_id, $d );
- }
- }
- /**
- * Move a product from one category to another
- *
- * @param array $d
- * @return boolean True on sucess, false on failure
- */
- function move( &$d ) {
- global $db, $vmLogger, $VM_LANG;
- if( !is_array( $d['product_id'])) {
- $vmLogger->err( $VM_LANG->_('VM_PRODUCT_MOVE_NOTFOUND',false));
- return false;
- }
- if( empty( $d['category_id'])) {
- $vmLogger->err( $VM_LANG->_('VM_PRODUCT_MUSTSELECT_ONE_CAT',false));
- return false;
- }
- // Loop though each product
- foreach( $d['product_id'] as $product_id ) {
- // check if the product is already assigned to the category it should be moved to
- $db->query( 'SELECT product_id FROM `#__{vm}_product_category_xref` WHERE `product_id`='.intval($product_id).' AND `category_id`='.intval($d['category_id']));
- if( !$db->next_record()) {
- // If the product is not yet in this category, move it!
- $db->query( 'SELECT MAX(`product_list`) as max FROM `#__{vm}_product_category_xref` WHERE `category_id`='.intval($d['category_id']));
- $db->next_record();
- $db->query('INSERT INTO `#__{vm}_product_category_xref` VALUES ('.intval($d['category_id']).', '.intval($product_id).', '.intval( $db->f('max') + 1) .') ');
- }
- $db->query('DELETE FROM `#__{vm}_product_category_xref` WHERE `product_id`='.intval($product_id).' AND `category_id`='.intval($d['old_category_id']));
- }
- return true;
- }
- /**
- * The function that holds the code for deleting
- * one product from the database and all related tables
- * plus deleting files related to the product
- *
- * @param int $product_id
- * @param array $d The input vars
- * @return boolean True on success, false on error
- */
- function delete_product( $product_id, &$d ) {
- global $vmLogger, $VM_LANG;
- $db = new ps_DB;
- if (!$this->validate_delete($product_id, $d)) {
- return false;
- }
- /* If is Product */
- if ($this->is_product($product_id)) {
- /* Delete all items first */
- $q = "SELECT product_id FROM #__{vm}_product WHERE product_parent_id='$product_id'";
- $db->setQuery($q); $db->query();
- while($db->next_record()) {
- $d2["product_id"] = $db->f("product_id");
- if (!$this->delete($d2)) {
- return false;
- }
- }
- /* Delete attributes */
- $q = "DELETE FROM #__{vm}_product_attribute_sku WHERE product_id='$product_id' ";
- $db->setQuery($q); $db->query();
- /* Delete categories xref */
- $q = "DELETE FROM #__{vm}_product_category_xref WHERE product_id = '$product_id' ";
- $db->setQuery($q); $db->query();
- }
- /* If is Item */
- else {
- /* Delete attribute values */
- $q = "DELETE FROM #__{vm}_product_attribute WHERE product_id='$product_id'";
- $db->setQuery($q); $db->query();
- }
- /* For both Product and Item */
- /* Delete product - manufacturer xref */
- $q = "DELETE FROM #__{vm}_product_mf_xref WHERE product_id='$product_id'";
- $db->setQuery($q); $db->query();
- /* Delete Product - ProductType Relations */
- $q = "DELETE FROM `#__{vm}_product_product_type_xref` WHERE `product_id`=$product_id";
- $db->setQuery($q); $db->query();
- /* Delete product votes */
- $q = "DELETE FROM #__{vm}_product_votes WHERE product_id='$product_id'";
- $db->setQuery($q); $db->query();
- /* Delete product reviews */
- $q = "DELETE FROM #__{vm}_product_reviews WHERE product_id='$product_id'";
- $db->setQuery($q); $db->query();
- /* Delete Image files */
- if (!vmImageTools::process_images($d)) {
- return false;
- }
- /* Delete other Files and Images files */
- require_once( CLASSPATH.'ps_product_files.php' );
- $ps_product_files = new ps_product_files();
- $db->query( "SELECT file_id FROM #__{vm}_product_files WHERE file_product_id='$product_id'" );
- while($db->next_record()) {
- $d["file_id"] = $db->f("file_id");
- $ps_product_files->delete( $d );
- }
- /* Delete Product Relations */
- $q = "DELETE FROM #__{vm}_product_relations WHERE product_id = '$product_id'";
- $db->setQuery($q); $db->query();
- /* Delete Prices */
- $q = "DELETE FROM #__{vm}_product_price WHERE product_id = '$product_id'";
- $db->setQuery($q); $db->query();
- /* Delete entry FROM #__{vm}_product table */
- $q = "DELETE FROM #__{vm}_product WHERE product_id = '$product_id'";
- $db->setQuery($q); $db->query();
- /* If only deleting an item, go to the parent product page after
- ** the deletion. This had to be done here because the product id
- ** of the item to be deleted had to be passed as product_id */
- if (!empty($d["product_parent_id"])) {
- $d["product_id"] = $d["product_parent_id"];
- $d["product_parent_id"] = "";
- }
- $vmLogger->info( str_replace('{product_id}',$product_id,$VM_LANG->_('VM_PRODUCT_DELETED',false)) );
- return true;
- }
- /**
- * Function to check if the vendor_id of the product
- * $d['product_id'] matches the vendor_id associated with the
- * user that calls this function
- *
- * @param array $d
- * @return boolean True, when vendor_id matches, false when not
- */
- function check_vendor($d) {
- $ps_vendor_id = $_SESSION["ps_vendor_id"];
- $db = new ps_DB;
- $q = "SELECT vendor_id FROM #__{vm}_product ";
- $q .= "WHERE vendor_id = '$ps_vendor_id' ";
- $q .= "AND product_id = '" . $d["product_id"] . "' ";
- $db->query($q);
- if ($db->next_record()) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * Function to create a ps_DB object holding the data of product $d['product_id']
- * from the table #__{vm}_product
- *
- * @param int $product_id
- * @return ps_DB DB object holding all data for product $product_id
- */
- function sql($product_id) {
- $db = new ps_DB;
- if( !empty( $product_id )) {
- $q = 'SELECT * FROM #__{vm}_product WHERE product_id=' . (int)$product_id;
- $db->setQuery($q); $db->query();
- }
- return $db;
- }
- /**
- * Function to create a db object holding the data of all child items of
- * product $product_id
- *
- * @param int $product_id
- * @return ps_DB object that holds all items of product $product_id
- */
- function items_sql($product_id) {
- $db = new ps_DB;
- if( !empty($product_id) ) {
- $q = "SELECT * FROM #__{vm}_product ";
- $q .= "WHERE product_parent_id=".(int)$product_id.' ';
- $q .= "ORDER BY product_name";
-
- $db->setQuery($q); $db->query();
- }
- return $db;
- }
- /**
- * Function to check whether a product is a parent product or not
- * If is is a child product, it has a non-empty value for "product_parent_id"
- *
- * @param int $product_id
- * @return boolean True when the product is a parent product, false when product is a child item
- */
- function is_product($product_id) {
- $product_parent_id = ps_product::get_field($product_id, 'product_parent_id');
- return $product_parent_id == 0;
- }
- /**
- * Function to check whether a product is published
- *
- *
- * @param int $product_id
- * @return boolean True when the product is a parent product, false when product is a child item
- */
- function is_published($product_id, $check_stock=false) {
- if( CHECK_STOCK != '1') $check_stock=false;
- return ps_product::get_field($product_id, 'product_publish') == 'Y';
- }
- /**
- * Checks if a product is a downloadable product
- *
- * @param int $product_id
- * @return boolean
- */
- function is_downloadable($product_id) {
- if( empty( $GLOBALS['product_info'][$product_id]['is_downloadable'] )) {
- $db_check = new ps_DB;
- $q_dl = "SELECT attribute_name,attribute_value
- FROM #__{vm}_product_attribute WHERE
- product_id=".(int)$product_id." AND attribute_name='download'";
- $db_check->query($q_dl);
- $db_check->next_record();
- if( $db_check->num_rows() > 0 ) {
- $GLOBALS['product_info'][$product_id]['is_downloadable'] = 'Y';
- } else {
- $GLOBALS['product_info'][$product_id]['is_downloadable'] = 'N';
- }
- }
- return $GLOBALS['product_info'][$product_id]['is_downloadable'] == 'Y';
- }
- /**
- * Function to create a DB object that holds all information
- * from the attribute tables about item $item_id AND/OR product $product_id
- *
- * @param int $item_id The product_id of the item
- * @param int $product_id The product_id of the parent product
- * @param string $attribute_name The name of the attribute to filter
- * @return ps_DB The db object...
- */
- function attribute_sql($item_id="",$product_id="",$attribute_name="") {
- $db = new ps_DB;
- if ($item_id and $product_id) {
- $q = "SELECT * FROM #__{vm}_product_attribute,#__{vm}_product_attribute_sku ";
- $q .= "WHERE #__{vm}_product_attribute.product_id = '$item_id' ";
- $q .= "AND #__{vm}_product_attribute_sku.product_id ='$product_id' ";
- if ($attribute_name) {
- $q .= "AND #__{vm}_product_attribute.attribute_name = $attribute_name ";
- }
- $q .= "AND #__{vm}_product_attribute.attribute_name = ";
- $q .= "#__{vm}_product_attribute_sku.attribute_name ";
- $q .= "ORDER BY attribute_list,#__{vm}_product_attribute.attribute_name";
- } elseif ($item_id) {
- $q = "SELECT * FROM #__{vm}_product_attribute ";
- $q .= "WHERE product_id=$item_id ";
- if ($attribute_name) {
- $q .= "AND attribute_name = '$attribute_name' ";
- }
- } elseif ($product_id) {
- $q = "SELECT * FROM #__{vm}_product_attribute_sku ";
- $q .= "WHERE product_id =".(int)$product_id.' ';
- if ($attribute_name) {
- $q .= "AND #__{vm}_product_attribute.attribute_name = $attribute_name ";
- }
- $q .= "ORDER BY attribute_list,attribute_name";
- } else {
- /* Error: no arguments were provided. */
- return 0;
- }
- $db->setQuery($q); $db->query();
- return $db;
- }
- /**
- * Function to return the product ids of all child items of product $pid
- *
- * @param int $pid The ID of the parent product
- * @return array $list
- */
- function get_child_product_ids($pid) {
- $db = new ps_DB;
- $q = "SELECT product_id FROM #__{vm}_product ";
- $q .= "WHERE product_parent_id='$pid' ";
- $db->setQuery($q); $db->query();
- $i = 0;
- $list = Array();
- while($db->next_record()) {
- $list[$i] = $db->f("product_id");
- $i++;
- }
- return $list;
- }
- /**
- * Function to quickly check whether a product has child products or not
- *
- * @param int $pid The id of the product to check
- * @return boolean True when the product has childs, false when not
- */
- function parent_has_children($pid) {
- $db = new ps_DB;
- if( empty($GLOBALS['product_info'][$pid]["parent_has_children"] )) {
- $q = "SELECT COUNT(product_id) as num_rows FROM #__{vm}_product WHERE product_parent_id='$pid' ";
- $db->query($q);
- $db->next_record();
- if( $db->f('num_rows') > 0 ) {
- $GLOBALS['product_info'][$pid]["parent_has_children"] = True;
- }
- else {
- $GLOBALS['product_info'][$pid]["parent_has_children"] = False;
- }
- }
- return $GLOBALS['product_info'][$pid]["parent_has_children"];
- }
- /**
- * Function to quickly check whether a product has attributes or not
- *
- * @param int $pid The id of the product to check
- * @return boolean True when the product has attributes, false when not
- */
- function product_has_attributes($pid, $checkSimpleAttributes=false ) {
- if( is_array($pid) || empty($pid)) {
- return false;
- }
- $pid = intval( $pid );
- $db = new ps_DB;
- if( empty($GLOBALS['product_info'][$pid]["product_has_attributes"] )) {
- $db->query( "SELECT `product_id` FROM `#__{vm}_product_attribute_sku` WHERE `product_id`=$pid");
- if ($db->next_record()) {
- $GLOBALS['product_info'][$pid]["product_has_attributes"] = True;
- }
- elseif( $checkSimpleAttributes ) {
- $db->query( "SELECT `attribute`,`custom_attribute` FROM `#__{vm}_product` WHERE `product_id`=$pid");
- $db->next_record();
- if( $db->f('attribute') || $db->f('custom_attribute')) {
- $GLOBALS['product_info'][$pid]["product_has_attributes"] = True;
- }
- else {
- $GLOBALS['product_info'][$pid]["product_has_attributes"] = False;
- }
- }
- else {
- $GLOBALS['product_info'][$pid]["product_has_attributes"] = False;
- }
- }
- return $GLOBALS['product_info'][$pid]["product_has_attributes"];
- }
- /**
- * Get the value of the field $field_name for product $product_id from the product table
- *
- * @param int $product_id
- * @param string $field_name
- * @return string The value of the field $field_name for that product
- */
- function get_field( $product_id, $field_name, $force = false ) {
- if( $product_id == 0 ) return '';
- $db = new ps_DB;
-
- if( !isset($GLOBALS['product_info'][$product_id][$field_name] ) || $force ) {
- $q = 'SELECT product_id, `#__{vm}_product`.* FROM `#__{vm}_product` WHERE `product_id`='.(int)$product_id;
- $db->query($q);
- if ($db->next_record()) {
- $values = get_object_vars( $db->getCurrentRow() );
-
- foreach( $values as $key => $value ) {
- $GLOBALS['product_info'][$product_id][$key] = $value;
- }
- if( !isset( $GLOBALS['product_info'][$product_id][$field_name] ) && !is_null($GLOBALS['product_info'][$product_id][$field_name])) {
- $GLOBALS['vmLogger']->debug( 'The Field '.$field_name. ' does not exist in the product table!');
- $GLOBALS['product_info'][$product_id][$field_name] = true;
- }
- }
- else {
- $GLOBALS['product_info'][$product_id][$field_name] = false;
- }
- }
- return $GLOBALS['product_info'][$product_id][$field_name];
- }
- /**
- * Sets a global value for a fieldname for a specific product
- * Is to be used by other scripts to populate a field value for a prodct
- * that was already fetched from the database - so it doesn't need to e fetched again
- * Can be also used to override a value
- *
- * @param int $product_id
- * @param string $field_name
- * @param mixed $value
- */
- function set_field( $product_id, $field_name, $value ) {
- $GLOBALS['product_info'][$product_id][$field_name] = $value;
- }
- /**
- * This is a very time consuming function.
- * It fetches the category flypage for a specific product id
- *
- * @param int $product_id
- * @return string The flypage value for that product
- */
- function get_flypage($product_id) {
- if( empty( $_SESSION['product_sess'][$product_id]['flypage'] )) {
- $db = new ps_DB;
- $productParentId = (int)$product_id;
- do {
- $q = "SELECT
- `#__{vm}_product`.`product_parent_id` AS product_parent_id,
- `#__{vm}_category`.`category_flypage`
- FROM
- `#__{vm}_product`
- LEFT JOIN `#__{vm}_product_category_xref` ON `#__{vm}_product_category_xref`.`product_id` = `#__{vm}_product`.`product_id`
- LEFT JOIN `#__{vm}_category` ON `#__{vm}_product_category_xref`.`category_id` = `#__{vm}_category`.`category_id`
- WHERE `#__{vm}_product`.`product_id`='$productParentId'
- ";
- $productParentId = $db->f("product_parent_id");
- $db->query($q);
- $db->next_record();
- }
- while( $db->f("product_parent_id") && !$db->f("category_flypage"));
- if ($db->f("category_flypage")) {
- $_SESSION['product_sess'][$product_id]['flypage'] = $db->f("category_flypage");
- } else {
- $_SESSION['product_sess'][$product_id]['flypage'] = FLYPAGE;
- }
- }
- return $_SESSION['product_sess'][$product_id]['flypage'];
- }
- /**
- * Function to get the name of the vendor the product is associated with
- *
- * @param int $product_id
- * @return string The name of the vendor
- */
- function get_vendorname($product_id) {
- $db = new ps_DB;
- $q = "SELECT #__{vm}_vendor.vendor_name FROM #__{vm}_product, #__{vm}_vendor ";
- $q .= "WHERE #__{vm}_product.product_id='$product_id' ";
- $q .= "AND #__{vm}_vendor.vendor_id=#__{vm}_product.vendor_id";
- $db->query($q);
- $db->next_record();
- if ($db->f("vendor_name")) {
- return $db->f("vendor_name");
- }
- else {
- return "";
- }
- }
- /**
- * Function to get the name of a vendor by its id
- * @author pablo
- * @param int $vendor_id
- * @return string The name of the vendor
- */
- function get_vend_idname($vendor_id) {
- $db = new ps_DB;
- $q = "SELECT vendor_name,vendor_id FROM #__{vm}_vendor ";
- $q .= "WHERE vendor_id='$vendor_id'";
- $db->query($q);
- $db->next_record();
- if ($db->f("vendor_name")) {
- return $db->f("vendor_name");
- }
- else {
- return "";
- }
- }
- /**
- * Function to get the vendor_id of a product
- * @author pablo
- * @param int $product_id
- * @return int The vendor id
- */
- function get_vendor_id($product_id) {
- $db = new ps_DB;
- if( empty( $_SESSION['product_sess'][$product_id]['vendor_id'] )) {
- $q = "SELECT vendor_id FROM #__{vm}_product ";
- $q .= "WHERE product_id='$product_id' ";
- $db->query($q);
- $db->next_record();
- if ($db->f("vendor_id")) {
- $_SESSION['product_sess'][$product_id]['vendor_id'] = $db->f("vendor_id");
- }
- else {
- $_SESSION['product_sess'][$product_id]['vendor_id'] = "";
- }
- }
- return $_SESSION['product_sess'][$product_id]['vendor_id'];
- }
- /**
- * Function to get the manufacturer id the product $product_id is assigned to
- * @author soeren
- * @param int $product_id
- * @return int The manufacturer id
- */
- function get_manufacturer_id($product_id) {
- $db = new ps_DB;
- $q = "SELECT manufacturer_id FROM #__{vm}_product_mf_xref ";
- $q .= "WHERE product_id='$product_id' ";
- $db->query($q);
- $db->next_record();
- if ($db->f("manufacturer_id")) {
- return $db->f("manufacturer_id");
- }
- else {
- return false;
- }
- }
- /**
- * Functon to get the name of the manufacturer this product is assigned to
- *
- * @param int $product_id
- * @return string the manufacturer name
- */
- function get_mf_name($product_id) {
- $db = new ps_DB;
- $q = "SELECT mf_name,#__{vm}_manufacturer.manufacturer_id FROM #__{vm}_product_mf_xref,#__{vm}_manufacturer ";
- $q .= "WHERE product_id='$product_id' ";
- $q .= "AND #__{vm}_manufacturer.manufacturer_id=#__{vm}_product_mf_xref.manufacturer_id";
- $db->query($q);
- $db->next_record();
- if ($db->f("mf_name")) {
- return $db->f("mf_name");
- }
- else {
- return "";
- }
- }
- /**
- * This function retrieves the "neighbor" products of a product specified by $product_id
- * Neighbors are the previous and next product in the current list
- *
- * @param int $product_id
- * @return array
- */
- function get_neighbor_products( $product_id ) {
- global $perm, $orderby, $my, $auth, $keyword, $DescOrderBy, $limit, $limitstart, $search_limiter, $search_op,
- $category_id, $manufacturer_id, $vm_mainframe, $vmInputFilter, $product_type_id, $keyword1, $keyword2;
- $limit = 2000;
- $limitstart = 0;
- if( !empty( $_SESSION['last_browse_parameters'])) {
- foreach( $_SESSION['last_browse_parameters'] as $paramName => $paramValue ) {
- $$paramName = $paramValue;
- }
- }
- $db = new ps_DB();
- $db_browse = new ps_DB();
- include( PAGEPATH . 'shop_browse_queries.php' );
-
- $db->query( $list );
-
- $neighbors = array('previous'=>'',
- 'next'=>'');
-
- while( $db->next_record() ) {
- if( $db->f( 'product_id' ) == $product_id ) {
- $previous_row = $db->previousRow();
- $next_row = $db->nextRow();
-
- if( !empty( $previous_row->product_id )) {
- $neighbors['previous']['product_id'] = $previous_row->product_id;
- $neighbors['previous']['product_name'] = $previous_row->product_name;
- }
- if( !empty( $next_row->product_id )) {
- $neighbors['next']['product_id'] = $next_row->product_id;
- $neighbors['next']['product_name'] = $next_row->product_name;
- }
- }
- }
- return $neighbors;
- }
- /**
- * Prints the img tag for the given product image
- *
- * @param string $image The name of the imahe OR the full URL to the image
- * @param string $args Additional attributes for the img tag
- * @param int $resize
- * (1 = resize the image by using height and width attributes,
- * 0 = do not resize the image)
- * @param string $path_appendix The path to be appended to IMAGEURL / IMAGEPATH
- */
- function show_image($image, $args="", $resize=1, $path_appendix="product") {
- echo $this->image_tag($image, $args, $resize, $path_appendix);
- }
- /**
- * Returns the img tag for the given product image
- *
- * @param string $image The name of the imahe OR the full URL to the image
- * @param string $args Additional attributes for the img tag
- * @param int $resize
- * (1 = resize the image by using height and width attributes,
- * 0 = do not resize the image)
- * @param string $path_appendix The path to be appended to IMAGEURL / IMAGEPATH
- * @return The HTML code of the img tag
- */
- function image_tag($image, $args="", $resize=1, $path_appendix='product', $thumb_width=0, $thumb_height=0 ) {
- global $mosConfig_live_site, $mosConfig_absolute_path;
- require_once( CLASSPATH . 'imageTools.class.php');
-
- $border="";
- if( strpos( $args, "border=" )===false ) {
- $border = 'border="0"';
- }
- $height = $width = '';
-
- if ($image != "") {
- // URL
- if( substr( $image, 0, 4) == "http" ) {
- $url = $image;
- }
- // local image file
- else {
- if(PSHOP_IMG_RESIZE_ENABLE == '1' || $resize==1) {
- $url = $mosConfig_live_site."/components/com_virtuemart/show_image_in_imgtag.php?filename=".urlencode($image)."&newxsize=".PSHOP_IMG_WIDTH."&newysize=".PSHOP_IMG_HEIGHT."&fileout=";
- if( !strpos( $args, "height=" )) {
- $arr = @getimagesize( vmImageTools::getresizedfilename( $image, $path_appendix, '', $thumb_width, $thumb_height ) );
- $width = $arr[0]; $height = $arr[1];
- }
- }
- else {
- $url = IMAGEURL.$path_appendix.'/'.$image;
- if( file_exists($image)) {
- $url = str_replace( $mosConfig_absolute_path, $mosConfig_live_site, $image );
- } elseif( file_exists($mosConfig_absolute_path.'/'.$image)) {
- $url = $mosConfig_live_site.'/'.$image;
- }
-
- if( !strpos( $args, "height=" ) ) {
- $arr = getimagesize( str_replace( IMAGEURL, IMAGEPATH, $url ) );
- $width = $arr[0]; $height = $arr[1];
-
- }
- if( $resize ) {
- if( $height < $width ) {
- $width = round($width / ($height / PSHOP_IMG_HEIGHT));
- $height = PSHOP_IMG_HEIGHT;
- } else {
- $height = round($height / ($width / PSHOP_IMG_WIDTH ));
- $width = PSHOP_IMG_WIDTH;
- }
- }
- }
- $url = str_replace( basename( $url ), $GLOBALS['VM_LANG']->convert(basename($url)), $url );
- }
- }
- else {
- $url = VM_THEMEURL.'images/'.NO_IMAGE;
- }
-
- return vmCommonHTML::imageTag( $url, '', '', $height, $width, '', '', $args.' '.$border );
- }
- /**
- * Get the tax rate...
- * @author soeren
- * @return int The tax rate found
- */
- function get_taxrate() {
- global $page;
- $ps_vendor_id = $_SESSION["ps_vendor_id"];
- $auth = $_SESSION['auth'];
- if( !defined('_PSHOP_ADMIN' ) || $page == 'product.product_list') {
- $db = new ps_DB;
- if ($auth["show_price_including_tax"] == 1) {
- require_once( CLASSPATH . 'ps_checkout.php' );
- if (! ps_checkout::tax_based_on_vendor_address ()) {
- if( $auth["user_id"] > 0 ) {
- $q = "SELECT state, country FROM #__{vm}_user_info WHERE user_id='". $auth["user_id"] . "'";
- $db->query($q);
- $db->next_record();
- $state = $db->f("state");
- $country = $db->f("country");
- $q = "SELECT tax_rate FROM #__{vm}_tax_rate WHERE tax_country='$country' ";
- if( !empty($state)) {
- $q .= "AND tax_state='$state'";
- }
- $db->query($q);
- if ($db->next_record()) {
- $_SESSION['taxrate'][$ps_vendor_id] = $db->f("tax_rate");
- }
- else {
- $_SESSION['taxrate'][$ps_vendor_id] = 0;
- }
- }
- else {
- $_SESSION['taxrate'][$ps_vendor_id] = 0;
- }
- }
- else {
- if( empty( $_SESSION['taxrate'][$ps_vendor_id] )) {
- // let's get the store's tax rate
- $q = "SELECT `tax_rate` FROM #__{vm}_vendor, #__{vm}_tax_rate ";
- $q .= "WHERE tax_country=vendor_country AND #__{vm}_vendor.vendor_id=1 ";
- // !! Important !! take the highest available tax rate for the store's country
- $q .= "ORDER BY `tax_rate` DESC";
- $db->query($q);
- if ($db->next_record()) {
- $_SESSION['taxrate'][$ps_vendor_id] = $db->f("tax_rate");
- }…
Large files files are truncated, but you can click here to view the full file