Esempio n. 1
0
 /**
  *
  * @author Max Milbers
  */
 function getUserInfoInUserFields($layoutName, $type, $uid, $cart = true, $isVendor = false)
 {
     // 		if(!class_exists('tsmartModelUserfields')) require(VMPATH_ADMIN.DS.'models'.DS.'userfields.php' );
     // 		$userFieldsModel = new tsmartModelUserfields();
     $userFieldsModel = tmsModel::getModel('userfields');
     $prepareUserFields = $userFieldsModel->getUserFieldsFor($layoutName, $type);
     if ($type == 'ST') {
         $preFix = 'shipto_';
     } else {
         $preFix = '';
     }
     /*
      * JUser  or $this->_id is the logged user
      */
     if (!empty($this->_data->JUser)) {
         $JUser = $this->_data->JUser;
     } else {
         $JUser = JUser::getInstance($this->_id);
     }
     $data = null;
     $userFields = array();
     if (!empty($uid)) {
         $dataT = $this->getTable('userinfos');
         $data = $dataT->load($uid);
         if ($data->tsmart_user_id !== 0 and !$isVendor) {
             $user = JFactory::getUser();
             if (!vmAccess::manager()) {
                 if ($data->tsmart_user_id != $this->_id) {
                     vmError('Blocked attempt loading userinfo, you got logged');
                     echo 'Hacking attempt loading userinfo, you got logged';
                     return false;
                 }
             }
         }
         if ($data->address_type != 'ST') {
             $BTuid = $uid;
             $data->name = $JUser->name;
             $data->email = $JUser->email;
             $data->username = $JUser->username;
             $data->address_type = 'BT';
         }
     } else {
         vmdebug('getUserInfoInUserFields case empty $uid');
         //New Address is filled here with the data of the cart (we are in the userview)
         if ($cart) {
             if (!class_exists('tsmartCart')) {
                 require VMPATH_SITE . DS . 'helpers' . DS . 'cart.php';
             }
             $cart = tsmartCart::getCart();
             $adType = $type . 'address';
             if (empty($cart->{$adType})) {
                 $data = $cart->{$type};
                 if (empty($data)) {
                     $data = array();
                 }
                 if ($JUser) {
                     if (empty($data['name'])) {
                         $data['name'] = $JUser->name;
                     }
                     if (empty($data['email'])) {
                         $data['email'] = $JUser->email;
                     }
                     if (empty($data['username'])) {
                         $data['username'] = $JUser->username;
                     }
                     if (empty($data['tsmart_user_id'])) {
                         $data['tsmart_user_id'] = $JUser->id;
                     }
                 }
                 $data = (object) $data;
             }
         } else {
             if ($JUser) {
                 if (empty($data['name'])) {
                     $data['name'] = $JUser->name;
                 }
                 if (empty($data['email'])) {
                     $data['email'] = $JUser->email;
                 }
                 if (empty($data['username'])) {
                     $data['username'] = $JUser->username;
                 }
                 if (empty($data['tsmart_user_id'])) {
                     $data['tsmart_user_id'] = $JUser->id;
                 }
                 $data = (object) $data;
             }
         }
     }
     if (empty($data)) {
         vmdebug('getUserInfoInUserFields $data empty', $uid, $data);
         $cart = tsmartCart::getCart();
         $data = $cart->BT;
     }
     $userFields[$uid] = $userFieldsModel->getUserFieldsFilled($prepareUserFields, $data, $preFix);
     return $userFields;
 }
Esempio n. 2
0
 /**
  * @param $product
  * @param $variants ids of the selected variants
  * @return float
  */
 public function calculateModificators(&$product)
 {
     if (!isset($product->modificatorSum)) {
         $product->modificatorSum = 0.0;
         if (!empty($product->customfields)) {
             foreach ($product->customfields as $k => $productCustom) {
                 $selected = -1;
                 if (isset($product->cart_item_id)) {
                     if (!class_exists('tsmartCart')) {
                         require VMPATH_SITE . DS . 'helpers' . DS . 'cart.php';
                     }
                     $cart = tsmartCart::getCart();
                     //vmdebug('my $productCustom->customfield_price '.$productCustom->tsmart_customfield_id,$cart->cartProductsData,$cart->cartProductsData[$product->cart_item_id]['customProductData'][$productCustom->tsmart_custom_id]);
                     if (isset($cart->cartProductsData[$product->cart_item_id]['customProductData'][$productCustom->tsmart_custom_id][$productCustom->tsmart_customfield_id])) {
                         $selected = $cart->cartProductsData[$product->cart_item_id]['customProductData'][$productCustom->tsmart_custom_id][$productCustom->tsmart_customfield_id];
                     } else {
                         if (isset($cart->cartProductsData[$product->cart_item_id]['customProductData'][$productCustom->tsmart_custom_id])) {
                             if ($cart->cartProductsData[$product->cart_item_id]['customProductData'][$productCustom->tsmart_custom_id] == $productCustom->tsmart_customfield_id) {
                                 $selected = $productCustom->tsmart_customfield_id;
                                 //= 1;
                             }
                         }
                     }
                     //vmdebug('my $productCustom->customfield_price',$selected,$productCustom->tsmart_custom_id,$productCustom->tsmart_customfield_id,$cart->cartProductsData[$product->cart_item_id]['customProductData']);
                 } else {
                     $pluginFields = vRequest::getVar('customProductData', NULL);
                     if ($pluginFields == NULL and isset($product->customPlugin)) {
                         $pluginFields = json_decode($product->customPlugin, TRUE);
                     }
                     if (isset($pluginFields[$product->tsmart_product_id][$productCustom->tsmart_custom_id][$productCustom->tsmart_customfield_id])) {
                         $selected = $pluginFields[$product->tsmart_product_id][$productCustom->tsmart_custom_id][$productCustom->tsmart_customfield_id];
                     } else {
                         if (isset($pluginFields[$product->tsmart_product_id][$productCustom->tsmart_custom_id])) {
                             if ($pluginFields[$product->tsmart_product_id][$productCustom->tsmart_custom_id] == $productCustom->tsmart_customfield_id) {
                                 $selected = 1;
                             }
                         }
                     }
                 }
                 if ($selected === -1) {
                     continue;
                 }
                 if (!empty($productCustom) and $productCustom->field_type == 'E') {
                     if (!class_exists('vmCustomPlugin')) {
                         require VMPATH_PLUGINLIBS . DS . 'vmcustomplugin.php';
                     }
                     JPluginHelper::importPlugin('vmcustom');
                     $dispatcher = JDispatcher::getInstance();
                     $dispatcher->trigger('plgVmPrepareCartProduct', array(&$product, &$product->customfields[$k], $selected, &$product->modificatorSum));
                 } else {
                     if ($productCustom->customfield_price) {
                         //vmdebug('calculateModificators $productCustom->customfield_price ',$productCustom->customfield_price);
                         //TODO adding % and more We should use here $this->interpreteMathOp
                         $product->modificatorSum += $productCustom->customfield_price;
                     }
                 }
             }
         }
     }
     return $product->modificatorSum;
 }
Esempio n. 3
0
 function emptyCart($session_id = NULL, $order_number = NULL)
 {
     if (!class_exists('tsmartCart')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'cart.php';
     }
     $this->logInfo('Notification: emptyCart ' . $session_id, 'message');
     if ($session_id != NULL and $order_number != NULL) {
         // Recover session from the storage session in wich the payment is done
         $this->emptyCartFromStorageSession($session_id, $order_number);
     } else {
         $cart = tsmartCart::getCart();
         $cart->emptyCart();
     }
     return TRUE;
 }
Esempio n. 4
0
 /** Create empty order head record from admin only
  *
  * @author Ondřej Spilka
  * @return ID of the newly created order
  */
 public function CreateOrderHead()
 {
     $usrid = 0;
     $_orderData = new stdClass();
     $_orderData->tsmart_order_id = null;
     $_orderData->tsmart_user_id = 0;
     $_orderData->tsmart_vendor_id = 1;
     //TODO
     $_orderData->order_total = 0;
     $_orderData->order_salesPrice = 0;
     $_orderData->order_billTaxAmount = 0;
     $_orderData->order_billDiscountAmount = 0;
     $_orderData->order_discountAmount = 0;
     $_orderData->order_subtotal = 0;
     $_orderData->order_tax = 0;
     $_orderData->order_shipment = 0;
     $_orderData->order_shipment_tax = 0;
     $_orderData->order_payment = 0;
     $_orderData->order_payment_tax = 0;
     $_orderData->order_discount = 0;
     $_orderData->order_status = 'P';
     $_orderData->order_currency = $this->getVendorCurrencyId($_orderData->tsmart_vendor_id);
     $_orderData->tsmart_paymentmethod_id = vRequest::getInt('tsmart_paymentmethod_id');
     $_orderData->tsmart_shipmentmethod_id = vRequest::getInt('tsmart_shipmentmethod_id');
     //$_orderData->customer_note = '';
     $_orderData->ip_address = $_SERVER['REMOTE_ADDR'];
     $_orderData->order_number = '';
     JPluginHelper::importPlugin('vmshopper');
     $dispatcher = JDispatcher::getInstance();
     $_orderData->order_number = $this->genStdOrderNumber($_orderData->tsmart_vendor_id);
     $_orderData->order_pass = $this->genStdOrderPass();
     $_orderData->order_create_invoice_pass = $this->genStdCreateInvoicePass();
     $orderTable = $this->getTable('orders');
     $orderTable->bindChecknStore($_orderData);
     $db = JFactory::getDBO();
     $_orderID = $db->insertid();
     $_usr = JFactory::getUser();
     if (!$this->_writeUserInfo($_orderID, $_usr, array())) {
         vmError('Problem writing user info to order');
     }
     $orderModel = tmsModel::getModel('orders');
     $order = $orderModel->getOrder($_orderID);
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('vmcustom');
     JPluginHelper::importPlugin('vmshipment');
     JPluginHelper::importPlugin('vmpayment');
     if (!class_exists('tsmartCart')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'cart.php';
     }
     $cart = tsmartCart::getCart();
     $returnValues = $dispatcher->trigger('plgVmConfirmedOrder', array($cart, $order));
     return $_orderID;
 }
Esempio n. 5
0
 protected function setCountryState()
 {
     if ($this->_app->isAdmin()) {
         return;
     }
     if (empty($this->_cart)) {
         if (!class_exists('tsmartCart')) {
             require VMPATH_SITE . DS . 'helpers' . DS . 'cart.php';
         }
         $this->_cart = tsmartCart::getCart();
     }
     if ($this->_cart->BT === 0) {
         $this->_cart->prepareAddressFieldsInCart();
     }
     $stBased = tsmConfig::get('taxSTbased', TRUE);
     if ($stBased) {
         $this->_deliveryCountry = (int) $this->_cart->getST('tsmart_country_id');
     } else {
         if (!empty($this->_cart->BT['tsmart_country_id'])) {
             $this->_deliveryCountry = (int) $this->_cart->BT['tsmart_country_id'];
         }
     }
     if ($stBased) {
         $this->_deliveryState = (int) $this->_cart->getST('tsmart_state_id');
     } else {
         if (!empty($this->_cart->BT['tsmart_state_id'])) {
             $this->_deliveryState = (int) $this->_cart->BT['tsmart_state_id'];
         }
     }
 }