function addtocartaslink(&$ref) { require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'addtocartaslink.php'; OPCAddToCartAsLink::addtocartaslink($ref, $this); }
public static function addtocartaslink(&$ref) { $c = get_class($ref->cart); if ($c != 'VirtuemartCart') { $ref->cart = VirtuemartCart::getCart(); } include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php'; $rememberhtml = ''; $rp = JRequest::getVar('randomproduct', 0); if (!empty($rp)) { if (OPCloader::checkOPCSecret()) { $opc_link_type = 1; $q = 'select virtuemart_product_id from #__virtuemart_products where published=1 limit 1'; $db = JFactory::getDBO(); $db->setQuery($q); $temp_id = $db->loadResult(); JRequest::setVar('add_id', $temp_id); } } if (empty($opc_link_type)) { return; } $p_id = JRequest::getVar('add_id', ''); if (empty($p_id)) { return; } if (!isset($ref->cart->order_number)) { $ref->cart->order_number = ''; } if (!empty($p_id)) { $qq = array(); if (is_array($p_id)) { foreach ($p_id as $i => $item) { if (!is_numeric($p_id[$i])) { break; } $q = JRequest::getVar('qadd_' . $p_id[$i], 1); if (!is_numeric($q)) { break; } $rememberhtml .= '<input type="hidden" name="qadd_' . $p_id[$i] . '" value="' . $q . '" />'; $rememberhtml .= '<input type="hidden" name="add_id[' . $i . ']" value="' . $p_id[$i] . '" />'; $q = (double) $q; $qq[$p_id[$i]] = $q; } } else { // you can use /index.php?option=com_virtuemart&page=shop.cart&add_id=10&quadd=1; // to add two products (ids: 10 and 11) of two quantity each (quadd_11=2 for product id 11 set quantity 2) // OR /index.php?option=com_virtuemart&page=shop.cart&add_id[]=10&quadd_10=2&add_id[]=11&qadd_11=2 $q = JRequest::getVar('qadd_' . $p_id, 1); $rememberhtml .= '<input type="hidden" name="qadd_' . $p_id . '" value="' . $q . '" />'; $rememberhtml .= '<input type="hidden" name="add_id" value="' . $p_id . '" />'; $q = (double) $q; $q2 = JRequest::getVar('qadd', 1); //$rememberhtml .= '<input type="hidden" name="qadd" value="'.$q2.'" />'; if (!is_numeric($p_id)) { return; } $qq[$p_id] = $q; $a = array(); $a[$p_id] = $p_id; $p_id = $a; } } else { return; } $post = JRequest::get('default'); /* if (!class_exists('VirtueMartModelProduct')) require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'product.php'); */ require_once JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'mini.php'; $productClass = OPCmini::getModel('product'); //new VirtueMartModelProduct(); //$virtuemart_product_ids = JRequest::getVar('virtuemart_product_id', array(), 'default', 'array'); //is sanitized then $newp = array(); $rr2 = array(); foreach ($p_id as $pid) { $newp[$pid] = $pid; $product = $productClass->getProductSingle($pid, true, true, true); $rr = OPCAddToCartAsLink::getProductCustomsFieldCart($product); $rr2[] = $rr; } if ($opc_link_type == 2 || $opc_link_type == 1) { if (!empty($ref->cart->products)) { $p = $ref->cart->products; foreach ($p as $key => $pr) { $id = $pr->virtuemart_product_id; // delete cart content if ($opc_link_type == 1) { if (isset($ref->cart->products[$key])) { $ref->cart->removeProductCart($key); } else { if (isset($ref->cart->product[$id])) { $ref->cart->removeProductCart($id); } } continue; } // do not increment quantity: if ($opc_link_type == 2) { if (in_array($id, $newp)) { return; } } } } } $virtuemart_product_ids = JRequest::setVar('virtuemart_product_id', $newp); //is sanitized then $virtuemart_product_ids = JRequest::setVar('quantity', $qq); //is sanitized then if (!empty($rr2)) { foreach ($rr2 as $rr1) { foreach ($rr1 as $post) { $x = JRequest::getVar($post['name']); if (empty($x)) { $test = array(); if (strpos($post['name'], ']') !== false) { $post['name'] = parse_str($post['name'] . '=' . $post['value'], $test); $firstkey = 0; if (!empty($test)) { foreach ($test as $key => $val) { $firstkey = $key; break; } } $name = $firstkey; $value = $test[$name]; JRequest::setVar($name, $value); } else { JRequest::setVar($post['name'], $post['value']); } } } } } if (!empty($opc_auto_coupon)) { $ref->cart->couponCode = $opc_auto_coupon; } $ref->cart->add(); JRequest::setVar('virtuemart_product_id', ''); JRequest::setVar('add_id', ''); JRequest::setVar('opc_adc', 1); //$quantityPost = (int) $post['quantity'][$p_key]; return $rememberhtml; }