protected function getInput() { //print_r($this); $html = ''; $fieldId = isset($this->element['id']) ? $this->element['id'] : 'jform_product_list'; $products = F0FModel::getTmpInstance('Products', 'J2StoreModel')->enabled(1)->getList(); $productarray = array(); $value = array(); $link = 'index.php?option=com_j2store&view=products&task=setProducts&tmpl=component&object=' . $this->name; $selected_value = array(); if (isset($this->value) && !empty($this->value)) { $selected_value = isset($this->value['ids']) && !empty($this->value['ids']) ? $this->value['ids'] : array(); } if (is_array($selected_value) && !empty($selected_value)) { foreach ($products as $product) { $product = J2Product::getInstance()->setId($product->j2store_product_id)->getProduct(); if (in_array($product->j2store_product_id, $selected_value)) { $productarray[$product->j2store_product_id] = $product->product_name; } } } $js = "\r\n\t\tfunction jSelectItem(id, title, object) {\r\n\t\tvar exists = jQuery('#j2store-product-li-'+id).html();\n\t\t\tif(!exists){\n\t\t\t\tvar container = jQuery('<li/>' ,{'id' :'j2store-product-li-'+id,'class':'j2store-product-list-menu'}).appendTo(jQuery('#j2store-product-item-list'));\n\t\t\t\tvar span = jQuery('<label/>',{'class':'label label-info'}).html(title).appendTo(container);\n\t\t\t\tvar input =jQuery('<input/>',{value:id, type:'hidden', name:'jform[request][j2store_item][ids][]'}).appendTo(container);\n\t\t\t\tvar remove = jQuery('<a/>',{'class':'btn btn-danger btn-mini' ,'onclick':'jQuery(this).closest(\"li\").remove();' }).html('<i class=\"icon icon-remove\"></i>').appendTo(container);\n\t\t\t\t}else{\n\t\t\t\t\talert('" . JText::_('J2STORE_PRODUCT_ALREADY_EXISTS') . "');\n\t\t\t\t}\n\t\tif(typeof(window.parent.SqueezeBox.close=='function')){\r\n\t\t\twindow.parent.SqueezeBox.close();\r\n\t\t}\r\n\t\telse {\r\n\t\t\tdocument.getElementById('sbox-window').close();\r\n\t\t\t}\r\n\t\t}\n\t\tfunction removeProductList(id){\n\t\t\tjQuery('#j2store-product-li-'+id).remove();\n\t\t}\n\t\t"; $css = '#j2store-product-item-list{ list-style:none; margin:5px; }'; JFactory::getDocument()->addScriptDeclaration($js); JFactory::getDocument()->addStyleDeclaration($css); $html .= JHTML::_('behavior.modal', 'a.modal'); $html .= '<div id="' . $fieldId . '">'; $html .= '<label class="control-label"></label>'; $html .= '<span class="input-append">'; $html .= '<input type="text" id="' . $this->name . '" name="" disabled="disabled"/>'; $html .= '<a class="modal btn btn-primary" title="' . JText::_('J2STORE_SELECT_AN_ITEM') . '" href="' . $link . '" rel="{handler: \'iframe\', size: {x: 700, y: 450}}"><i class="icon-list"></i> ' . JText::_('J2STORE_SELECT_PRODUCT') . '</a>'; $html .= J2StorePopup::popup("index.php?option=com_j2store&view=coupons&task=setProducts&layout=products&tmpl=component&function=jSelectProduct&field=" . $fieldId, JText::_("J2STORE_SET_PRODUCTS"), array('width' => 800, 'height' => 400)); $html . '</span>'; $html .= '<ul id="j2store-product-item-list" >'; foreach ($productarray as $key => $value) { $html .= '<li class="j2store-product-list-menu" id="j2store-product-li-' . $key . '">'; $html .= '<label class="label label-info">'; $html .= $value; $html .= '<input type="hidden" value="' . $key . '" name="jform[request][j2store_item][ids][]">'; $html .= '</label>'; $html .= '<a class="btn btn-danger btn-mini" onclick="removeProductList(' . $key . ');">'; $html .= '<i class="icon icon-remove"></i>'; $html .= '</a>'; $html .= '</li>'; } $html .= '</ul>'; $html .= '</div>'; return $html; }
public static function product($config = array()) { return J2Product::getInstance($config); }
function setProducts() { //get variant id $model = F0FModel::getTmpInstance('Products', 'J2StoreModel'); $filter_category = $this->input->getInt('filter_category'); $limit = $this->input->getInt('limit', 0); $limitstart = $this->input->getInt('limitstart', 0); $model->setState('filter_category', $filter_category); $model->setState('limit', $limit); $model->setState('limitstart', $limitstart); $model->setState('enabled', 1); $model->setState('visible', 1); $items = $model->getProductList(); $catarray = array(); foreach ($items as $item) { $product = J2Product::getInstance()->setId($item->j2store_product_id)->getProduct(); $item->product_name = $product->product_name; $item->catid = $product->source->catid; } $testproduct = array(); foreach ($items as $product) { if (empty($filter_category)) { $testproduct[] = $product; } elseif (isset($filter_category) && !empty($filter_category) && $filter_category == $product->catid) { $testproduct[] = $product; } } $categories = JHtmlCategory::options('com_content'); $layout = $this->input->getString('layout'); $view = $this->getThisView(); $view->setModel($model, true); $view->set('state', $model->getState()); $view->set('pagination', $model->getPagiantion()); $view->set('total', $model->getTotal()); $view->set('productitems', $testproduct); $view->set('categories', $categories); $view->setLayout('elements'); $view->display(); }