Exemplo n.º 1
0
 function loadproductinfo()
 {
     $jshopConfig = JSFactory::getConfig();
     $db = JFactory::getDBO();
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onLoadInfoProduct', array());
     $id_vendor_cuser = getIdVendorForCUser();
     $product_id = JRequest::getInt('product_id');
     $currency_id = JRequest::getInt('currency_id');
     $layout = JRequest::getVar('layout', 'productinfo_json');
     if ($id_vendor_cuser && $product_id) {
         checkAccessVendorToProduct($id_vendor_cuser, $product_id);
     }
     $products = JSFactory::getModel("products");
     $product = JSFactory::getTable('product', 'jshop');
     $product->load($product_id);
     $product->getDescription();
     $currency = JSFactory::getTable('currency', 'jshop');
     $currency->load($currency_id);
     if ($currency_id) {
         $currency_value = $currency->currency_value;
     } else {
         $currency_value = 1;
     }
     $product_price = getPriceFromCurrency($product->product_price, $product->currency_id, $currency_value);
     $res = array();
     $res['product_id'] = $product->product_id;
     $res['product_ean'] = $product->product_ean;
     $res['product_price'] = $product_price;
     $res['delivery_times_id'] = $product->delivery_times_id;
     $res['vendor_id'] = fixRealVendorId($product->vendor_id);
     $res['product_weight'] = $product->product_weight;
     $res['product_tax'] = $product->getTax();
     $res['product_name'] = $product->name;
     $res['thumb_image'] = $product->product_thumb_image;
     $view = $this->getView("product_edit", 'html');
     $view->setLayout($layout);
     $view->assign('res', $res);
     $view->assign('product', $product);
     $dispatcher->trigger('onBeforeDisplayLoadInfoProduct', array(&$view));
     $view->display();
     die;
 }
Exemplo n.º 2
0
 function loadproductinfo()
 {
     $jshopConfig = JSFactory::getConfig();
     $db = JFactory::getDBO();
     JPluginHelper::importPlugin('jshoppingadmin');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onLoadInfoProduct', array());
     $id_vendor_cuser = getIdVendorForCUser();
     $product_id = JRequest::getInt('product_id');
     $layout = JRequest::getVar('layout', 'productinfo_json');
     if ($id_vendor_cuser && $product_id) {
         checkAccessVendorToProduct($id_vendor_cuser, $product_id);
     }
     $products = $this->getModel("products");
     $product = JTable::getInstance('product', 'jshop');
     $product->load($product_id);
     $product->getDescription();
     $res = array();
     $res['product_id'] = $product->product_id;
     $res['product_ean'] = $product->product_ean;
     $res['product_price'] = $product->product_price;
     $res['delivery_times_id'] = $product->delivery_times_id;
     $res['vendor_id'] = fixRealVendorId($product->vendor_id);
     $res['product_weight'] = $product->product_weight;
     $res['product_tax'] = $product->getTax();
     $res['product_name'] = $product->name;
     $res['thumb_image'] = getPatchProductImage($product->image, 'thumb');
     $view = $this->getView("product_edit", 'html');
     $view->setLayout($layout);
     $view->assign('res', $res);
     $view->assign('edit', null);
     $view->assign('product', $product);
     $dispatcher->trigger('onBeforeDisplayLoadInfoProduct', array(&$view));
     $view->display();
     die;
 }
Exemplo n.º 3
0
 function add($product_id, $quantity, $attr_id, $freeattributes, $additional_fields = array(), $usetriggers = 1, &$errors = array(), $displayErrorMessage = 1)
 {
     $jshopConfig = JSFactory::getConfig();
     if ($quantity <= 0) {
         $errors['100'] = 'Error quantity';
         if ($displayErrorMessage) {
             JError::raiseNotice(100, $errors['100']);
         }
         return 0;
     }
     $updateqty = 1;
     if ($usetriggers) {
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onBeforeAddProductToCart', array(&$this, &$product_id, &$quantity, &$attr_id, &$freeattributes, &$updateqty, &$errors, &$displayErrorMessage, &$additional_fields, &$usetriggers));
     }
     $attr_serialize = serialize($attr_id);
     $free_attr_serialize = serialize($freeattributes);
     $product = JSFactory::getTable('product', 'jshop');
     $product->load($product_id);
     //check attributes
     if (count($product->getRequireAttribute()) > count($attr_id) || in_array(0, $attr_id)) {
         $errors['101'] = _JSHOP_SELECT_PRODUCT_OPTIONS;
         if ($displayErrorMessage) {
             JError::raiseNotice(101, $errors['101']);
         }
         return 0;
     }
     //check free attributes
     if ($jshopConfig->admin_show_freeattributes) {
         $allfreeattributes = $product->getListFreeAttributes();
         $error = 0;
         foreach ($allfreeattributes as $k => $v) {
             if ($v->required && trim($freeattributes[$v->id]) == "") {
                 $error = 1;
                 $errors['102_' . $v->id] = sprintf(_JSHOP_PLEASE_ENTER_X, $v->name);
                 if ($displayErrorMessage) {
                     JError::raiseNotice(102, $errors['102_' . $v->id]);
                 }
             }
         }
         if ($error) {
             return 0;
         }
     }
     $product->setAttributeActive($attr_id);
     $product->setFreeAttributeActive($freeattributes);
     $qtyInStock = $product->getQtyInStock();
     $pidCheckQtyValue = $product->getPIDCheckQtyValue();
     $new_product = 1;
     if ($updateqty) {
         foreach ($this->products as $key => $value) {
             if ($value['product_id'] == $product_id && $value['attributes'] == $attr_serialize && $value['freeattributes'] == $free_attr_serialize) {
                 $product_in_cart = $this->products[$key]['quantity'];
                 $save_quantity = $product_in_cart + $quantity;
                 $sum_quantity = $save_quantity;
                 foreach ($this->products as $key2 => $value2) {
                     if ($key == $key2) {
                         continue;
                     }
                     if ($value2['pid_check_qty_value'] == $pidCheckQtyValue) {
                         $sum_quantity += $value2["quantity"];
                         $product_in_cart += $value2["quantity"];
                     }
                 }
                 if ($jshopConfig->max_count_order_one_product && $sum_quantity > $jshopConfig->max_count_order_one_product) {
                     $errors['103'] = sprintf(_JSHOP_ERROR_MAX_COUNT_ORDER_ONE_PRODUCT, $jshopConfig->max_count_order_one_product);
                     if ($displayErrorMessage) {
                         JError::raiseNotice(103, $errors['103']);
                     }
                     return 0;
                 }
                 if ($jshopConfig->min_count_order_one_product && $sum_quantity < $jshopConfig->min_count_order_one_product) {
                     $errors['104'] = sprintf(_JSHOP_ERROR_MIN_COUNT_ORDER_ONE_PRODUCT, $jshopConfig->min_count_order_one_product);
                     if ($displayErrorMessage) {
                         JError::raiseNotice(104, $errors['104']);
                     }
                     return 0;
                 }
                 if (!$product->unlimited && $jshopConfig->controler_buy_qty && $sum_quantity > $qtyInStock) {
                     $balans = $qtyInStock - $product_in_cart;
                     if ($balans < 0) {
                         $balans = 0;
                     }
                     $errors['105'] = sprintf(_JSHOP_ERROR_EXIST_QTY_PRODUCT_IN_CART, $this->products[$key]['quantity'], $balans);
                     if ($displayErrorMessage) {
                         JError::raiseWarning(105, $errors['105']);
                     }
                     return 0;
                 }
                 $this->products[$key]['quantity'] = $save_quantity;
                 $this->products[$key]['price'] = $product->getPrice($this->products[$key]['quantity'], 1, 1, 1, $this->products[$key]);
                 if ($jshopConfig->cart_basic_price_show) {
                     $this->products[$key]['basicprice'] = $product->getBasicPrice();
                 }
                 if ($usetriggers) {
                     $dispatcher->trigger('onBeforeSaveUpdateProductToCart', array(&$this, &$product, $key, &$errors, &$displayErrorMessage, &$product_in_cart, &$quantity));
                 }
                 $new_product = 0;
                 break;
             }
         }
     }
     if ($new_product) {
         $product_in_cart = 0;
         foreach ($this->products as $key2 => $value2) {
             if ($value2['pid_check_qty_value'] == $pidCheckQtyValue) {
                 $product_in_cart += $value2["quantity"];
             }
         }
         $sum_quantity = $product_in_cart + $quantity;
         if ($jshopConfig->max_count_order_one_product && $sum_quantity > $jshopConfig->max_count_order_one_product) {
             $errors['106'] = sprintf(_JSHOP_ERROR_MAX_COUNT_ORDER_ONE_PRODUCT, $jshopConfig->max_count_order_one_product);
             if ($displayErrorMessage) {
                 JError::raiseNotice(106, $errors['106']);
             }
             return 0;
         }
         if ($jshopConfig->min_count_order_one_product && $sum_quantity < $jshopConfig->min_count_order_one_product) {
             $errors['107'] = sprintf(_JSHOP_ERROR_MIN_COUNT_ORDER_ONE_PRODUCT, $jshopConfig->min_count_order_one_product);
             if ($displayErrorMessage) {
                 JError::raiseNotice(107, $errors['107']);
             }
             return 0;
         }
         if (!$product->unlimited && $jshopConfig->controler_buy_qty && $sum_quantity > $qtyInStock) {
             $balans = $qtyInStock - $product_in_cart;
             if ($balans < 0) {
                 $balans = 0;
             }
             $errors['108'] = sprintf(_JSHOP_ERROR_EXIST_QTY_PRODUCT, $balans);
             if ($displayErrorMessage) {
                 JError::raiseWarning(108, $errors['108']);
             }
             return 0;
         }
         $product->getDescription();
         $temp_product['quantity'] = $quantity;
         $temp_product['product_id'] = $product_id;
         $temp_product['category_id'] = $product->getCategory();
         $temp_product['tax'] = $product->getTax();
         $temp_product['tax_id'] = $product->product_tax_id;
         $temp_product['min_kolichestvo'] = $product->getData('min_kolichestvo');
         $temp_product['product_name'] = $product->name;
         $temp_product['thumb_image'] = $product->getData('product_thumb_image');
         $temp_product['delivery_times_id'] = $product->getDeliveryTimeId();
         $temp_product['ean'] = $product->getEan();
         $temp_product['attributes'] = $attr_serialize;
         $temp_product['attributes_value'] = array();
         $temp_product['extra_fields'] = array();
         $temp_product['weight'] = $product->getWeight();
         $temp_product['vendor_id'] = fixRealVendorId($product->vendor_id);
         $temp_product['files'] = serialize($product->getSaleFiles());
         $temp_product['freeattributes'] = $free_attr_serialize;
         if ($jshopConfig->show_manufacturer_in_cart) {
             $manufacturer_info = $product->getManufacturerInfo();
             $temp_product['manufacturer'] = $manufacturer_info->name;
         }
         $temp_product['pid_check_qty_value'] = $pidCheckQtyValue;
         $i = 0;
         if (is_array($attr_id) && count($attr_id)) {
             foreach ($attr_id as $key => $value) {
                 $attr = JSFactory::getTable('attribut', 'jshop');
                 $attr_v = JSFactory::getTable('attributvalue', 'jshop');
                 $temp_product['attributes_value'][$i] = new stdClass();
                 $temp_product['attributes_value'][$i]->attr_id = $key;
                 $temp_product['attributes_value'][$i]->value_id = $value;
                 $temp_product['attributes_value'][$i]->attr = $attr->getName($key);
                 $temp_product['attributes_value'][$i]->value = $attr_v->getName($value);
                 $i++;
             }
         }
         if ($jshopConfig->admin_show_product_extra_field && count($jshopConfig->getCartDisplayExtraFields()) > 0) {
             $extra_field = $product->getExtraFields(2);
             $temp_product['extra_fields'] = $extra_field;
         }
         foreach ($additional_fields as $k => $v) {
             if ($k != 'after_price_calc') {
                 $temp_product[$k] = $v;
             }
         }
         if ($usetriggers) {
             $dispatcher->trigger('onBeforeSaveNewProductToCartBPC', array(&$this, &$temp_product, &$product, &$errors, &$displayErrorMessage));
         }
         $temp_product['price'] = $product->getPrice($quantity, 1, 1, 1, $temp_product);
         if ($jshopConfig->cart_basic_price_show) {
             $temp_product['basicprice'] = $product->getBasicPrice();
             $temp_product['basicpriceunit'] = $product->getBasicPriceUnit();
         }
         if (is_array($additional_fields['after_price_calc'])) {
             foreach ($additional_fields['after_price_calc'] as $k => $v) {
                 $temp_product[$k] = $v;
             }
         }
         if ($usetriggers) {
             $dispatcher->trigger('onBeforeSaveNewProductToCart', array(&$this, &$temp_product, &$product, &$errors, &$displayErrorMessage));
         }
         $this->products[] = $temp_product;
     }
     $this->loadPriceAndCountProducts();
     $this->reloadRabatValue();
     $this->saveToSession();
     if ($usetriggers) {
         $dispatcher->trigger('onAfterAddProductToCart', array(&$this, &$product_id, &$quantity, &$attr_id, &$freeattributes, &$errors, &$displayErrorMessage));
     }
     return 1;
 }