function display_form_add_product()
    {
        global $VM_LANG, $vmLogger;
        require_once CLASSPATH . 'ps_product_attribute.php';
        //require_once(CLASSPATH . 'ps_product.php');
        $ps_product_attribute = new ps_product_attribute();
        //$ps_product = new ps_product;
        $order_item_id = vmGet($_REQUEST, 'order_item_id');
        // Affichage de l'en-t�te
        $html_entete = '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
        $html_entete .= '<br /><br /><table class="adminlist"><tr><th>' . $VM_LANG->_('VM_ORDER_EDIT_ADD_PRODUCT') . '</th></tr></table>';
        $html_entete .= '<table class="adminlist"><tr>';
        $html_entete .= '<th>' . $VM_LANG->_('PHPSHOP_ORDER_PRINT_NAME') . '</th>';
        $html_pied = '<input type="hidden" name="add_product" value="1" />
		<input type="hidden" name="order_edit_page" value="1" />
		<input type="hidden" name="page" value="order.order_print" />
		<input type="hidden" name="option" value="com_virtuemart" />
		<input type="hidden" name="func" value="" />
		<input type="hidden" name="order_id" value="' . $this->order_id . '" /></form>';
        $html_return_parent = '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">
		<input type="submit" value="' . $VM_LANG->_('VM_ORDER_EDIT_RETURN_PARENTS') . '" />
		<input type="hidden" name="product_id" value="-1" />
		<input type="hidden" name="add_product_validate" value="0" />
		<input type="hidden" name="add_product_item" value="0" />
		<input type="hidden" name="add_product" value="1" />
		<input type="hidden" name="order_edit_page" value="1" />
		<input type="hidden" name="page" value="order.order_print" />
		<input type="hidden" name="option" value="com_virtuemart" />
		<input type="hidden" name="func" value="" />
		<input type="hidden" name="order_id" value="' . $this->order_id . '" /></form>';
        $product_id = vmGet($_REQUEST, 'product_id');
        if ($this->product_added == true) {
            $product_id = -1;
        }
        $d = $_REQUEST;
        $add_product_validate = vmGet($_REQUEST, 'add_product_validate');
        if ($product_id < 0 || $product_id == "") {
            $html_table = '<tr><td>' . $this->list_products($product_id) . '</td>';
            $html_entete .= '</tr>';
            $html_table .= '</tr></table><input type="hidden" name="add_product_validate" value="0" />';
            echo $html_entete . $html_table . $html_pied;
            return;
        }
        $db = new ps_DB();
        $q = "SELECT product_id FROM #__{vm}_product WHERE ";
        $q .= "product_parent_id = '" . $product_id . "'";
        $db->query($q);
        $item = false;
        // Elements fils s�lectionn�s
        if (vmGet($_REQUEST, 'add_product_item') == 1) {
            $item = true;
            $html_table = '<tr><td>' . $this->list_attribute($product_id, false) . '<input type="hidden" name="add_product_item" value="1" /></td>';
        } else {
            if ($db->num_rows()) {
                $html_entete .= '</tr>';
                $html_table = '<tr><td>' . $this->list_attribute($product_id) . '<input type="hidden" name="add_product_validate" value="0" /><input type="hidden" name="add_product_item" value="1" /></td></tr></table>';
                echo $html_entete . $html_table . $html_pied . $html_return_parent;
                return;
            } else {
                $html_table = '<tr><td>' . $this->list_products($product_id) . '</td>';
            }
        }
        $html_entete .= '<th>' . $VM_LANG->_('PHPSHOP_PRODUCT_FORM_CUSTOM_ATTRIBUTE_LIST') . '</th>';
        $html_entete .= '<th>' . $VM_LANG->_('PHPSHOP_PRODUCT_FORM_ATTRIBUTE_LIST') . '</th>';
        $html_entete .= '<th align="left">' . $VM_LANG->_('PHPSHOP_ORDER_PRINT_QUANTITY') . '</th>';
        $html_entete .= '<th align="left">Action</th></tr>';
        $html_table .= '<td>' . $ps_product_attribute->list_advanced_attribute($product_id) . '</td>';
        $html_table .= '<td>' . $ps_product_attribute->list_custom_attribute($product_id) . '</td>';
        $html_table .= '<td><input type="text" value="1" name="product_quantity" size="5" /><input type="hidden" name="add_product_validate" value="1" /></td>';
        $html_table .= '<td><input type="submit" value="' . $VM_LANG->_('VM_ORDER_EDIT_ADD') . '" /></td></tr></table>';
        if ($item) {
            $html_pied .= $html_return_parent;
        }
        echo $html_entete . $html_table . $html_pied;
        return;
    }
示例#2
0
 /**
  * This function can parse an "advanced / custom attribute"
  * description like
  * Size:big[+2.99]; Color:red[+0.99]
  * and return the same string with values, tax added
  * Size: big (+3.47), Color: red (+1.15)
  * 
  * @param string $description
  * @param int $product_id
  * @return string The reformatted description
  */
 function getDescriptionWithTax($description, $product_id = 0)
 {
     global $CURRENCY_DISPLAY, $mosConfig_secret;
     require_once CLASSPATH . 'ps_product_attribute.php';
     $auth = $_SESSION['auth'];
     $description = stripslashes($description);
     // if we've been given a description to deal with, get the adjusted price
     if ($description != '' && $auth["show_price_including_tax"] == 1 && $product_id != 0) {
         $my_taxrate = $this->get_product_taxrate($product_id);
         $price = $this->get_price($product_id);
         $product_currency = $price['product_currency'];
     } else {
         $my_taxrate = 0.0;
         $product_currency = '';
     }
     // We must care for custom attribute fields! Their value can be freely given
     // by the customer, so we mustn't include them into the price calculation
     // Thanks to AryGroup@ua.fm for the good advice
     if (empty($_REQUEST["custom_attribute_fields"])) {
         if (!empty($_SESSION["custom_attribute_fields"])) {
             $custom_attribute_fields = vmGet($_SESSION, "custom_attribute_fields", array());
             $custom_attribute_fields_check = vmGet($_SESSION, "custom_attribute_fields_check", array());
         } else {
             $custom_attribute_fields = $custom_attribute_fields_check = array();
         }
     } else {
         $custom_attribute_fields = $_SESSION["custom_attribute_fields"] = vmGet($_REQUEST, "custom_attribute_fields", array());
         $custom_attribute_fields_check = $_SESSION["custom_attribute_fields_check"] = vmGet($_REQUEST, "custom_attribute_fields_check", array());
     }
     $product_attributes = ps_product_attribute::getAdvancedAttributes($product_id);
     $attribute_keys = explode(";", $description);
     foreach ($attribute_keys as $temp_desc) {
         $finish = strpos($temp_desc, "]");
         $temp_desc = trim($temp_desc);
         // Get the key name (e.g. "Color" )
         $this_key = substr($temp_desc, 0, strpos($temp_desc, ":"));
         $this_value = substr($temp_desc, strpos($temp_desc, ":") + 1);
         if (in_array($this_key, $custom_attribute_fields)) {
             if (@$custom_attribute_fields_check[$this_key] == md5($mosConfig_secret . $this_key)) {
                 // the passed value is valid, don't use it for calculating prices
                 continue;
             }
         }
         if (isset($product_attributes[$this_key]['values'][$this_value])) {
             $modifier = $product_attributes[$this_key]['values'][$this_value]['adjustment'];
             $operand = $product_attributes[$this_key]['values'][$this_value]['operand'];
             $value_notax = $GLOBALS['CURRENCY']->convert($modifier, $product_currency);
             if (abs($value_notax) > 0) {
                 $value_taxed = $value_notax * ($my_taxrate + 1);
                 $temp_desc_new = str_replace($operand . $modifier, $operand . ' ' . $CURRENCY_DISPLAY->getFullValue($value_taxed), $temp_desc);
                 $description = str_replace($this_key . ':' . $this_value, $this_key . ':' . $this_value . ' (' . $operand . ' ' . $CURRENCY_DISPLAY->getFullValue($value_taxed) . ')', $description);
             }
             $temp_desc = substr($temp_desc, $finish + 1);
         }
     }
     $description = str_replace($CURRENCY_DISPLAY->symbol, '@saved@', $description);
     $description = str_replace("[", " (", $description);
     $description = str_replace("]", ")", $description);
     $description = str_replace(":", ": ", $description);
     $description = str_replace(";", "<br/>", $description);
     $description = str_replace('@saved@', $CURRENCY_DISPLAY->symbol, $description);
     return $description;
 }
    function html_change_add_item()
    {
        global $VM_LANG, $vmLogger;
        require_once CLASSPATH . 'ps_product_attribute.php';
        $ps_product_attribute = new ps_product_attribute();
        // Get product_id
        $product_id = vmGet($_REQUEST, 'product_id');
        $product_id_bysku = vmGet($_REQUEST, 'product_id_bysku');
        // If sku was selected it overwrites the product_id
        if ($product_id_bysku > 0) {
            $product_id = $product_id_bysku;
        }
        // Output to generate a "return to parant"-button
        $html_return_parent = '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">
		<input type="submit" value="' . $VM_LANG->_('PHPSHOP_ORDER_EDIT_RETURN_PARENTS') . '" />
		<input type="hidden" name="product_id" value="-1" />
		<input type="hidden" name="add_product_validate" value="0" />
		<input type="hidden" name="add_product_item" value="0" />
		<input type="hidden" name="add_product" value="1" />
		<input type="hidden" name="order_edit_page" value="1" />
		<input type="hidden" name="page" value="order.order_print" />
		<input type="hidden" name="option" value="com_virtuemart" />
		<input type="hidden" name="func" value="" />
		<input type="hidden" name="order_id" value="' . $this->order_id . '" /></form>';
        // Page reseted = -1 or called first time = ""
        if ($product_id < 0 || $product_id == "") {
            // Generate product list
            ?>
  		<form method="post" action="<?php 
            echo $_SERVER['PHP_SELF'];
            ?>
">
  		  <br /><br />
        <table class="adminlist">
          <tr>
            <th> <?php 
            echo $VM_LANG->_('PHPSHOP_ORDER_EDIT_ADD_PRODUCT');
            ?>
</th>
          </tr>
          <tr>
            <td align="left"><?php 
            echo $this->list_products($product_id, true);
            echo $this->list_products($product_id);
            ?>
</td>
          </tr>
        </table>
    		<input type="hidden" name="add_product_validate" value="0" />
    		<input type="hidden" name="add_product_item" value="0" />
		    <input type="hidden" name="add_product" value="1" />

    		<input type="hidden" name="page" value="order.order_print" />
    		<input type="hidden" name="option" value="com_virtuemart" />
    		<input type="hidden" name="func" value="" />
    		<input type="hidden" name="order_id" value="<?php 
            echo $this->order_id;
            ?>
" />
      </form>
      <?php 
        } else {
            // Query child products
            $db = new ps_DB();
            $q = "SELECT product_id FROM #__{vm}_product WHERE ";
            $q .= "product_parent_id = '" . $product_id . "'";
            $db->query($q);
            // Are there childs?
            if ($db->num_rows()) {
                // Yes! Drop down list to select the child
                ?>
    		<form method="post" action="<?php 
                echo $_SERVER['PHP_SELF'];
                ?>
">
    		  <br /><br />
          <table class="adminlist">
            <tr>
              <th><?php 
                echo $VM_LANG->_('PHPSHOP_ORDER_EDIT_ADD_PRODUCT');
                ?>
</th>
            </tr>
          </table>
          <table class="adminlist">
            <tr>
              <th><?php 
                echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_NAME');
                ?>
</th>
            </tr>
            <tr>
              <td>
                <input type="hidden" name="add_product" value="1" />
            		<input type="hidden" name="add_product_validate" value="0" />
                <input type="hidden" name="add_product_item" value="1" />
                <?php 
                echo $this->list_attribute($product_id);
                ?>
              </td>
            </tr>
          </table>
      		<input type="hidden" name="page" value="order.order_print" />
      		<input type="hidden" name="option" value="com_virtuemart" />
      		<input type="hidden" name="func" value="" />
      		<input type="hidden" name="order_id" value="<?php 
                echo $this->order_id;
                ?>
" />
        </form>
      <?php 
                echo $html_return_parent;
            } else {
                // No Childs or selected child product! Form to add a product that has no childs
                ?>
    		<form method="post" action="<?php 
                echo $_SERVER['PHP_SELF'];
                ?>
">
    		  <br /><br />
          <table class="adminlist">
            <tr>
              <th><?php 
                echo $VM_LANG->_('PHPSHOP_ORDER_EDIT_ADD_PRODUCT');
                ?>
</th>
            </tr>
          </table>
          <table class="adminlist">
            <tr>
              <th><?php 
                echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_NAME');
                ?>
</th>
              <th><?php 
                echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_CUSTOM_ATTRIBUTE_LIST');
                ?>
</th>
              <th><?php 
                echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_ATTRIBUTE_LIST');
                ?>
</th>
              <th align="left"><?php 
                echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_QUANTITY');
                ?>
</th>
              <th align="left">Action</th>
            </tr>
            <tr>
            <?php 
                if (vmGet($_REQUEST, 'add_product_item') == 1) {
                    echo '<td>' . $this->list_attribute($product_id, false) . '</td>';
                    echo '<input type="hidden" name="add_product_item" value="1" />';
                } else {
                    echo '<td>' . $this->list_products($product_id, true) . $this->list_products($product_id) . '</td>';
                }
                ?>
              <td><?php 
                echo $ps_product_attribute->list_advanced_attribute($product_id);
                ?>
</td>
              <td><?php 
                echo $ps_product_attribute->list_custom_attribute($product_id);
                ?>
</td>
              <td>
                <input type="text" value="1" name="product_quantity" size="5" />
            		<input type="hidden" name="add_product_validate" value="1" />
        		    <input type="hidden" name="add_product" value="1" />

              </td>
              <td><input type="submit" value="<?php 
                echo $VM_LANG->_('PHPSHOP_ORDER_EDIT_ADD');
                ?>
" /></td>
            </tr>
          </table>
      		<input type="hidden" name="page" value="order.order_print" />
      		<input type="hidden" name="option" value="com_virtuemart" />
      		<input type="hidden" name="func" value="" />
      		<input type="hidden" name="order_id" value="<?php 
                echo $this->order_id;
                ?>
" />
        </form>
      <?php 
                if (vmGet($_REQUEST, 'add_product_item') == 1) {
                    echo $html_return_parent;
                }
            }
        }
        return;
    }
示例#4
0
 function get_adjusted_attribute_price($product_id, $quantity = 0, $description = '', $result_attributes = '')
 {
     global $mosConfig_secret;
     $auth = $_SESSION['auth'];
     $price = $this->get_price($product_id, $quantity, true, $result_attributes);
     $base_price = $price["product_price"];
     $setprice = 0;
     $set_price = false;
     $adjustment = 0;
     // We must care for custom attribute fields! Their value can be freely given
     // by the customer, so we mustn't include them into the price calculation
     // Thanks to AryGroup@ua.fm for the good advice
     if (empty($_REQUEST["custom_attribute_fields"])) {
         if (!empty($_SESSION["custom_attribute_fields"])) {
             $custom_attribute_fields = vmGet($_SESSION, "custom_attribute_fields", array());
             $custom_attribute_fields_check = vmGet($_SESSION, "custom_attribute_fields_check", array());
         } else {
             $custom_attribute_fields = $custom_attribute_fields_check = array();
         }
     } else {
         $custom_attribute_fields = $_SESSION["custom_attribute_fields"] = vmGet($_REQUEST, "custom_attribute_fields", array());
         $custom_attribute_fields_check = $_SESSION["custom_attribute_fields_check"] = vmGet($_REQUEST, "custom_attribute_fields_check", array());
     }
     // if we've been given a description to deal with, get the adjusted price
     if ($description != '') {
         // description is safe to use at this point cause it's set to ''
         require_once CLASSPATH . 'ps_product_attribute.php';
         $product_attributes = ps_product_attribute::getAdvancedAttributes($product_id, true);
         $attribute_keys = explode(";", $description);
         for ($i = 0; $i < sizeof($attribute_keys); $i++) {
             $temp_desc = $attribute_keys[$i];
             $temp_desc = trim($temp_desc);
             // Get the key name (e.g. "Color" )
             $this_key = substr($temp_desc, 0, strpos($temp_desc, ":"));
             $this_value = substr($temp_desc, strpos($temp_desc, ":") + 1);
             if (in_array($this_key, $custom_attribute_fields)) {
                 if (@$custom_attribute_fields_check[$this_key] == md5($mosConfig_secret . $this_key)) {
                     // the passed value is valid, don't use it for calculating prices
                     continue;
                 }
             }
             if (isset($product_attributes[$this_key]['values'][$this_value])) {
                 $modifier = $product_attributes[$this_key]['values'][$this_value]['adjustment'];
                 $operand = $product_attributes[$this_key]['values'][$this_value]['operand'];
                 // if we have a number, allow the adjustment
                 if (true == is_numeric($modifier)) {
                     //			$modifier = $GLOBALS['CURRENCY']->convert( $modifier, $price['product_currency'], $GLOBALS['product_currency'] );
                     // Now add or sub the modifier on
                     if ($operand == "+") {
                         $adjustment += $modifier;
                     } else {
                         if ($operand == "-") {
                             $adjustment -= $modifier;
                         } else {
                             if ($operand == '=') {
                                 // NOTE: the +=, so if we have 2 sets they get added
                                 // this could be moded to say, if we have a set_price, then
                                 // calc the diff from the base price and start from there if we encounter
                                 // another set price... just a thought.
                                 $setprice += $modifier;
                                 $set_price = true;
                             }
                         }
                     }
                 }
             } else {
                 continue;
             }
         }
     }
     // no set price was set from the attribs
     if ($set_price == false) {
         $price["product_price"] = $base_price + $adjustment * (1 - $auth["shopper_group_discount"] / 100);
     } else {
         // otherwise, set the price
         // add the base price to the price set in the attributes
         // then subtract the adjustment amount
         // we could also just add the set_price to the adjustment... not sure on that one.
         if (!empty($adjustment)) {
             $setprice += $adjustment;
         }
         $setprice *= 1 - $auth["shopper_group_discount"] / 100;
         $price["product_price"] = $setprice;
     }
     // don't let negative prices get by, set to 0
     if ($price["product_price"] < 0) {
         $price["product_price"] = 0;
     }
     // Get the DISCOUNT AMOUNT
     $ps_product = new ps_product();
     $discount_info = $ps_product->get_discount($product_id);
     // Read user_info_id from db
     $dbu = new ps_DB();
     $q = "SELECT user_info_id FROM #__{vm}_orders WHERE order_id = '" . $this->order_id . "' ";
     $dbu->query($q);
     $dbu->next_record();
     $user_info_id = $dbu->f("user_info_id");
     $prod_weight = $ps_product->get_weight($product_id);
     $my_taxrate = $ps_product->get_product_taxrate($product_id, $prod_weight, $user_info_id);
     // If discounts are applied after tax, but prices are shown without tax,
     // AND tax is EU mode and shopper is not in the EU,
     // then ps_product::get_product_taxrate() returns 0, so $my_taxrate = 0.
     // But, the discount still needs to be reduced by the shopper's tax rate, so we obtain it here:
     if (PAYMENT_DISCOUNT_BEFORE != '1' && $auth["show_price_including_tax"] != 1 && !ps_checkout::tax_based_on_vendor_address($user_info_id)) {
         $db = new ps_DB();
         $ps_vendor_id = $_SESSION["ps_vendor_id"];
         require_once CLASSPATH . 'ps_checkout.php';
         if (!ps_checkout::tax_based_on_vendor_address($user_info_id)) {
             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}' OR tax_state=' {$state} ' OR tax_state='-')";
                 }
                 $db->query($q);
                 if ($db->next_record()) {
                     $my_taxrate = $db->f("tax_rate");
                 } else {
                     $my_taxrate = 0;
                 }
             } else {
                 $my_taxrate = 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()) {
                     $my_taxrate = $db->f("tax_rate");
                 } else {
                     $my_taxrate = 0;
                 }
             } else {
                 $my_taxrate = $_SESSION['taxrate'][$ps_vendor_id];
             }
         }
     }
     // Apply the discount
     if (!empty($discount_info["amount"])) {
         $undiscounted_price = $base_price;
         switch ($discount_info["is_percent"]) {
             case 0:
                 if (PAYMENT_DISCOUNT_BEFORE == '1') {
                     // If we subtract discounts BEFORE tax
                     // Subtract the whole discount
                     $price["product_price"] -= $discount_info["amount"];
                 } else {
                     // But, if we subtract discounts AFTER tax
                     // Subtract the untaxed portion of the discount
                     $price["product_price"] -= $discount_info["amount"] / ($my_taxrate + 1);
                 }
                 break;
             case 1:
                 $price["product_price"] -= $price["product_price"] * ($discount_info["amount"] / 100);
                 break;
         }
     }
     return $price;
 }
示例#5
0
}
?>
 </td>
    </tr>
    <tr class="row0">
    <td colspan="2">&nbsp;</td>
    </tr>
    <tr class="row0">
        <td align="right" width="21%" valign="top"><div style="text-align:right;font-weight:bold;"><?php 
echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_ATTRIBUTE_LIST');
?>
:</div></td> 
		<td width="79%" id="attribute_container">
			<?php 
// ATTRIBUTE EXTENSION by Tobias (eaxs)
ps_product_attribute::loadAttributeExtension($db->sf("attribute"));
?>
    </tr>
    <tr class="row0">
    <td>&nbsp;</td>
        <td><?php 
echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_ATTRIBUTE_LIST_EXAMPLES');
?>
</td>
    </tr>
    <tr class="row0">
    <td colspan="2">&nbsp;</td>
    </tr>
    <tr class="row1">
        <td align="right" width="21%" valign="top"><div style="text-align:right;font-weight:bold;"><?php 
echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_CUSTOM_ATTRIBUTE_LIST');
示例#6
0
 /**
  * adds an item to the shopping cart
  * @author pablo
  * @param array $d
  */
 function add(&$d)
 {
     global $sess, $VM_LANG, $cart, $vmLogger, $func;
     $d = $GLOBALS['vmInputFilter']->process($d);
     include_class("product");
     $db = new ps_DB();
     $ci = 0;
     $request_stock = "";
     $total_quantity = 0;
     $total_updated = 0;
     $total_deleted = 0;
     $_SESSION['last_page'] = "shop.product_details";
     if (!empty($d['product_id']) && !isset($d["prod_id"])) {
         if (empty($d['prod_id'])) {
             $d['prod_id'] = array();
         }
         if (is_array($d['product_id'])) {
             $d['prod_id'] = array_merge($d['prod_id'], $d['product_id']);
         } else {
             $d['prod_id'] = array_merge($d['prod_id'], array($d['product_id']));
         }
     }
     //Check to see if a prod_id has been set
     if (!isset($d["prod_id"])) {
         return true;
     }
     $multiple_products = sizeof($d["prod_id"]);
     //Iterate through the prod_id's and perform an add to cart for each one
     for ($ikey = 0; $ikey < $multiple_products; $ikey++) {
         // Create single array from multi array
         $key_fields = array_keys($d);
         foreach ($key_fields as $key) {
             if (is_array($d[$key])) {
                 $e[$key] = @$d[$key][$ikey];
             } else {
                 $e[$key] = $d[$key];
             }
         }
         if ($multiple_products > 1) {
             $func = "cartUpdate";
         }
         $e['product_id'] = $d['product_id'];
         $e['Itemid'] = $d['Itemid'];
         if (is_array($d["prod_id"])) {
             $product_id = $d["prod_id"][$ikey];
         } else {
             $product_id = $e["prod_id"];
         }
         if (is_array($d["quantity"])) {
             $quantity = @$d['quantity'][$ikey];
         } else {
             $quantity = @$e['quantity'];
         }
         // Check for negative quantity
         if ($quantity < 0) {
             vmRequest::setVar('product_id', $product_id);
             $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_NEGATIVE', false));
             return False;
         }
         if (!is_numeric($quantity)) {
             vmRequest::setVar('product_id', $product_id);
             $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_VALID_QUANTITY', false));
             return False;
         }
         $quantity = intval($quantity);
         // Check to see if checking stock quantity
         if (CHECK_STOCK) {
             $product_in_stock = ps_product::get_field($product_id, 'product_in_stock');
             if (empty($product_in_stock)) {
                 $product_in_stock = 0;
             }
             if ($quantity > $product_in_stock) {
                 //Create an array for out of stock items and continue to next item
                 $request_stock[$ci]['product_id'] = $product_id;
                 $request_stock[$ci]['quantity'] = $quantity;
                 $ci++;
                 continue;
             }
         }
         // Check if product exists and is published
         if (!ps_product::product_exists($product_id)) {
             $vmLogger->tip($VM_LANG->_('VM_CART_PRODUCT_NOTEXIST', false));
             return false;
         }
         // Quick add of item
         $q = "SELECT product_id FROM #__{vm}_product WHERE ";
         $q .= "product_parent_id = " . (int) $product_id;
         $db->query($q);
         if ($db->num_rows()) {
             vmRequest::setVar('product_id', $e["product_id"]);
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false));
             $_REQUEST['flypage'] = ps_product::get_flypage($e["product_id"]);
             $GLOBALS['page'] = 'shop.product_details';
             return true;
         }
         // Check to see if we already have it
         $updated = 0;
         $result = ps_product_attribute::cartGetAttributes($e);
         if ($result["attribute_given"] == false && !empty($result["advanced_attribute_list"]) || $multiple_products == 1 && ($result["custom_attribute_given"] == false && !empty($result["custom_attribute_list"]))) {
             $_REQUEST['flypage'] = ps_product::get_flypage($product_id);
             $GLOBALS['page'] = 'shop.product_details';
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false));
             return true;
         }
         //Check for empty custom field and quantity>0 for multiple addto
         //Normally means no info added to a custom field, but once added to a cart the quantity is automatically placed
         //If another item is added and the custom field is left blank for another product already added this will just ignore that item
         if ($multiple_products != 1 && $quantity != 0 && ($result["custom_attribute_given"] == false && !empty($result["custom_attribute_list"]))) {
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false));
             continue;
         }
         // Check for duplicate and do not add to current quantity
         for ($i = 0; $i < $_SESSION["cart"]["idx"]; $i++) {
             // modified for advanced attributes
             if ($_SESSION['cart'][$i]["product_id"] == $product_id && $_SESSION['cart'][$i]["description"] == $e["description"]) {
                 $updated = 1;
             }
         }
         list($min, $max) = ps_product::product_order_levels($product_id);
         if ($min != 0 && $quantity != 0 && $quantity < $min) {
             eval("\$msg = \"" . $VM_LANG->_('VM_CART_MIN_ORDER', false) . "\";");
             $vmLogger->warning($msg);
             continue;
         }
         if ($max != 0 && $quantity != 0 && $quantity > $max) {
             eval("\$msg = \"" . $VM_LANG->_('VM_CART_MAX_ORDER', false) . "\";");
             $vmLogger->warning($msg);
             continue;
         }
         // If we did not update then add the item
         if (!$updated && $quantity) {
             $k = $_SESSION['cart']["idx"];
             $_SESSION['cart'][$k]["quantity"] = $quantity;
             $_SESSION['cart'][$k]["product_id"] = $product_id;
             $_SESSION['cart'][$k]["parent_id"] = $e["product_id"];
             $_SESSION['cart'][$k]["category_id"] = vmGet($e, 'category_id', 0);
             // added for the advanced attribute modification
             $_SESSION['cart'][$k]["description"] = $e["description"];
             $_SESSION['cart']["idx"]++;
             $total_quantity += $quantity;
         } else {
             list($updated_prod, $deleted_prod) = $this->update($e);
             $total_updated += $updated_prod;
             $total_deleted += $deleted_prod;
         }
         /* next 3 lines added by Erich for coupon code */
         /* if the cart was updated we gotta update any coupon discounts to avoid ppl getting free stuff */
         if (!empty($_SESSION['coupon_discount'])) {
             // Update the Coupon Discount !!
             require_once CLASSPATH . 'ps_coupon.php';
             ps_coupon::process_coupon_code($d);
         }
     }
     // End Iteration through Prod id's
     $cart = $_SESSION['cart'];
     ps_cart::saveCart();
     // Ouput info message with cart update details /*
     if ($total_quantity != 0 || $total_updated != 0 || $total_deleted != 0) {
         if ($total_quantity > 0 && $total_updated == 0) {
             $msg = $VM_LANG->_('VM_CART_PRODUCT_ADDED', false);
         } else {
             $msg = $VM_LANG->_('VM_CART_PRODUCT_UPDATED', false);
         }
         // Comment out the following line to turn off msg i.e. //$vmLogger->tip( $msg );
         $vmLogger->info($msg);
     } else {
         if (@$request_stock) {
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_GOTO_WAITING_LIST', false));
         } elseif ($total_quantity == 0) {
             vmRequest::setVar('product_id', $product_id);
             $GLOBALS['last_page'] = 'shop.product_details';
             $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_VALID_QUANTITY', false));
             return false;
         } else {
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_QUANTITY_EXCEEDED', false));
         }
     }
     // end cart update message */
     // Perform notification of out of stock items
     if (@$request_stock) {
         global $notify;
         $_SESSION['notify'] = array();
         $_SESSION['notify']['idx'] = 0;
         $k = 0;
         $notify = $_SESSION['notify'];
         foreach ($request_stock as $request) {
             $_SESSION['notify'][$k]["prod_id"] = $request['product_id'];
             $_SESSION['notify'][$k]["quantity"] = $request['quantity'];
             $_SESSION['notify']['idx']++;
             $k++;
         }
         if (vmIsXHR()) {
             $GLOBALS['vm_mainframe']->scriptRedirect($sess->url('index.php?page=shop.waiting_list&product_id=' . $product_id, true, false));
         } else {
             vmRedirect($sess->url('index.php?page=shop.waiting_list&product_id=' . $product_id, true, false));
         }
     }
     return True;
 }
示例#7
0
 function add_product()
 {
     global $VM_LANG, $vmLogger;
     require_once CLASSPATH . 'ps_product_attribute.php';
     require_once CLASSPATH . 'ps_product.php';
     $ps_product_attribute = new ps_product_attribute();
     $ps_product = new ps_product();
     $product_id = vmGet($_REQUEST, 'product_id');
     $order_item_id = vmGet($_REQUEST, 'order_item_id');
     $add_product_validate = vmGet($_REQUEST, 'add_product_validate');
     $d = $_REQUEST;
     // Check if quantity is a numeric value
     if ($add_product_validate == 1) {
         $quantity = trim(vmGet($_REQUEST, 'product_quantity'));
         if (!is_numeric($quantity) || $quantity < 1) {
             $vmLogger->err($VM_LANG->_('PHPSHOP_ORDER_EDIT_ERROR_QUANTITY_MUST_BE_HIGHER_THAN_0'));
             $add_product_validate = 0;
         }
     }
     if ($add_product_validate == 1) {
         $result_attributes = $ps_product_attribute->cartGetAttributes($d);
         $dbp = new ps_DB();
         $q = "SELECT vendor_id, product_in_stock,product_sales,product_parent_id, product_sku, product_name FROM #__{vm}_product WHERE product_id='{$product_id}'";
         $dbp->query($q);
         $dbp->next_record();
         $vendor_id = $dbp->f("vendor_id");
         $product_sku = $dbp->f("product_sku");
         $product_name = $dbp->f("product_name");
         $product_parent_id = $dbp->f("product_parent_id");
         // On r�cup�re le prix exact du produit
         $product_price_arr = $this->get_adjusted_attribute_price($product_id, $quantity, $d["description"], $result_attributes);
         $product_price = $product_price_arr["product_price"];
         $my_taxrate = $ps_product->get_product_taxrate($product_id);
         $description = $d["description"];
         $product_final_price = round($product_price * ($my_taxrate + 1), 2);
         $product_currency = $product_price_arr["product_currency"];
         $db = new ps_DB();
         if ($product_parent_id > 0) {
             $q = "SELECT attribute_name, attribute_value, product_id ";
             $q .= "FROM #__{vm}_product_attribute WHERE ";
             $q .= "product_id='" . $product_id . "'";
             $db->setQuery($q);
             $db->query();
             while ($db->next_record()) {
                 $description .= $db->f("attribute_name") . ": " . $db->f("attribute_value") . "; ";
             }
         }
         $q = "SELECT * FROM #__{vm}_order_item ";
         $q .= " WHERE order_id=" . $this->order_id;
         $db->query($q);
         $db->next_record();
         $user_info_id = $db->f("user_info_id");
         $order_status = $db->f("order_status");
         $timestamp = time() + $mosConfig_offset * 60 * 60;
         $q = "SELECT order_item_id, product_quantity ";
         $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $this->order_id . "' ";
         $q .= "AND product_id = '" . $product_id . "' ";
         $q .= "AND product_attribute = '" . addslashes($description) . "'";
         $db->query($q);
         if ($db->next_record()) {
             $this->change_item_quantity($this->order_id, $db->f('order_item_id'), $quantity + (int) $db->f('product_quantity'));
         } else {
             $q = "INSERT INTO #__{vm}_order_item ";
             $q .= "(order_id, user_info_id, vendor_id, product_id, order_item_sku, order_item_name, ";
             $q .= "product_quantity, product_item_price, product_final_price, ";
             $q .= "order_item_currency, order_status, product_attribute, cdate, mdate) ";
             $q .= "VALUES ('";
             $q .= $this->order_id . "', '";
             $q .= $user_info_id . "', '";
             $q .= $vendor_id . "', '";
             $q .= $product_id . "', '";
             $q .= $product_sku . "', '";
             $q .= $product_name . "', '";
             $q .= $quantity . "', '";
             $q .= $product_price . "', '";
             $q .= $product_final_price . "', '";
             $q .= $product_currency . "', '";
             $q .= $order_status . "', '";
             // added for advanced attribute storage
             $q .= addslashes($description) . "', '";
             // END advanced attribute modifications
             $q .= $timestamp . "','";
             $q .= $timestamp . "'";
             $q .= ")";
             $db->query($q);
             $db->next_record();
         }
         // Update Stock Level and Product Sales
         $q = "UPDATE #__{vm}_product ";
         $q .= "SET product_in_stock = product_in_stock - " . $quantity . ",\r\n\t\t\t\t\t\t\tproduct_sales= product_sales + " . $quantity;
         $q .= " WHERE product_id='" . $product_id . "'";
         $db->query($q);
         $this->recalc_order($this->order_id);
         $this->reload_from_db = 1;
         $vmLogger->info($VM_LANG->_('PHPSHOP_ORDER_EDIT_PRODUCT_ADDED'));
     }
 }