registerTask('getMedias', 'getMedias'); $this->registerTask('getProductData', 'getProductData'); } public function getProductData() { $filter = trim(vRequest::getVar('q', vRequest::getVar('term', ''))); $db = JFactory::getDBO(); $virtuemart_product_id = vRequest::getInt('virtuemart_product_id', array()); if (is_array($virtuemart_product_id) && count($virtuemart_product_id) > 0) { $product_id = (int)$virtuemart_product_id[0]; } else { $product_id = (int)$virtuemart_product_id; } $useFb = vmLanguage::getUseLangFallback(); $useFb2 = vmLanguage::getUseLangFallbackSecondary(); $type = vRequest::getCmd('type', ''); switch ($type) { case 'relatedcategories': { $query = "SELECT c.virtuemart_category_id AS id, "; $langField = 'category_name'; if ($useFb) { $f2 = 'ld.' . $langField; if ($useFb2) { $f2 = 'IFNULL(ld.' . $langField . ', ljd.' . $langField . ')'; } $field = 'IFNULL(l.' . $langField . ',' . $f2 . ')'; } else { $field = 'l.' . $langField; } $query .= ' CONCAT(' . $field . ', "[", c.virtuemart_category_id,"]") AS value'; $query .= ' FROM `#__virtuemart_categories` AS c '; $joinedTables = VmModel::joinLangTables('#__virtuemart_categories', 'c', 'virtuemart_category_id'); $query .= " \n" . implode(" \n", $joinedTables); if (!empty($filter)) { $filter = '"%' . $db->escape($filter, true) . '%"'; $fields = VmModel::joinLangLikeFields(array('category_name'), $filter); $query .= ' WHERE ' . implode(' OR ', $fields); } $json = self::getRelated($product_id, $query, 'Z'); } break; case 'relatedproducts': { $query = "SELECT p.virtuemart_product_id AS id, "; $langField = 'product_name'; if($useFb){ $f2 = 'ld.'.$langField; if($useFb2){ $f2 = 'IFNULL(ld.'.$langField.', ljd.'.$langField.')'; } $field = 'IFNULL(l.'.$langField.','.$f2.')'; } else { $field = 'l.'.$langField; } $query .= ' CONCAT('.$field.', " [", p.product_sku, "]") AS value'; $query .= ' FROM `#__virtuemart_products` AS p '; $joinedTables = VmModel::joinLangTables('#__virtuemart_products','p','virtuemart_product_id'); $query .= " \n".implode(" \n",$joinedTables); if (!empty($filter)){ $filter = '"%'.$db->escape( $filter, true ).'%"'; $fields = VmModel::joinLangLikeFields(array('product_name'),$filter); $query .= ' WHERE '.implode (' OR ', $fields) ; $query .= ' OR p.product_sku LIKE '.$filter; } /*$ctype = vRequest::getInt('ctype',0); if($ctype == 1){*/ $type = 'R'; /*} else { $type = 'RC'; }*/ $json = self::getRelated($product_id,$query,$type); } break; case 'fields': { $thisRow = vRequest::getInt('row', false); $id = vRequest::getInt('id', false); $model = VmModel::getModel('custom'); $rows = array(); if($id){ $q = 'SELECT `virtuemart_custom_id` FROM `#__virtuemart_customs` WHERE (`custom_parent_id`=' . $id . ') '; $q .= 'order by `ordering` asc'; $db->setQuery($q); $ids = $db->loadColumn(); if ($ids) { array_unshift($ids, $id); } else { $ids = array($id); } foreach ($ids as $k => $i) { $p = $model->getCustom($i); if ($p) { $p->value = $p->custom_value; $rows[] = $p; } } } $modelCustomfields = VmModel::getModel('Customfields'); $fieldTypes = VirtueMartModelCustom::getCustomTypes(); $html = array(); foreach ($rows as $field) { $customcf= new stdClass(); if ($field->field_type == 'deprecatedwasC') { $childcf= new stdClass(); $json['table'] = 'childs'; $q = 'SELECT `virtuemart_product_id` FROM `#__virtuemart_products` WHERE `published`=1 AND `product_parent_id`= ' . vRequest::getInt('virtuemart_product_id'); //$this->db->setQuery(' SELECT virtuemart_product_id, product_name FROM `#__virtuemart_products` WHERE `product_parent_id` ='.(int)$product_id); $db->setQuery($q); if ($childIds = $db->loadColumn()) { // Get childs foreach ($childIds as $childId) { $field->custom_value = $childId; $display = $modelCustomfields->displayProductCustomfieldBE($field, $childId, $thisRow ); if ($field->is_cart_attribute) { $cartIcone = 'default'; } else { $cartIcone = 'default-off'; } $html[] = '
' . $field->custom_title . ' ' . $display . $field->custom_tip . ' ' . vmText::_($fieldTypes[$field->field_type]) . '
'; $customcf->canMove=true; $customcf->canRemove=true; $customcf->type=vmText::_($fieldTypes[$field->field_type]) ; $customcf->title=$field->custom_tip; $customcf->is_cart_attribute=$field->is_cart_attribute; $customcf->hiddenHTML=$modelCustomfields->setEditCustomHidden($field, $thisRow ); $customcf->displayHTML= $modelCustomfields->displayProductCustomfieldBE($field, $childId, $thisRow ); $customcfs[]=$customcf; $thisRow ++; } } } else { //if ($field->field_type =='E') { $json['table'] = 'customPlugins'; $colspan = ''; if ($field->field_type == 'E') { $modelCustomfields->bindCustomEmbeddedFieldParams($field, 'E'); } else { if ($field->field_type == 'C' or $field->field_type == 'RC') { $colspan = 'colspan="2" '; } } $display = $modelCustomfields->displayProductCustomfieldBE($field, $product_id, $thisRow ); if ($field->is_cart_attribute) { $cartIcone = 'default'; } else { $cartIcone = 'default-off'; } $field->virtuemart_product_id = $product_id; $html[] = ' ' . vmText::_($fieldTypes[$field->field_type]) . ' ' . vmText::_($field->custom_title) . '
' . $display . ' '; $customcf->canMove=true; $customcf->canRemove=true; $customcf->type=vmText::_($fieldTypes[$field->field_type]) ; $customcf->title=vmText::_($field->custom_title); $customcf->is_cart_attribute=$field->is_cart_attribute; $customcf->hiddenHTML=$modelCustomfields->setEditCustomHidden($field, $thisRow ); $customcf->displayHTML= $display; $customcfs[]=$customcf; $thisRow ++; } } $json = $customcfs; } break; } echo vmJsApi::safe_json_encode($json); jexit(); } function getRelated($product_id, $query, $fieldType) { $row = vRequest::getInt('row', false); $model = VmModel::getModel('Customfields'); $db = JFactory::getDBO(); $start = vRequest::getInt('start', 0); $max = vRequest::getInt('max', 25); $db->setQuery($query . ' limit '.$start.','.$max); $json = $db->loadObjectList(); if (!($json)) { echo('setRelatedHtml ' . $query); return; } $query = 'SELECT * FROM `#__virtuemart_customs` WHERE field_type ="' . $fieldType . '" '; $db->setQuery($query); $custom = $db->loadObject(); if (!$custom) { vmdebug('setRelatedHtml could not find $custom for field type ' . $fieldType); return false; } $custom->virtuemart_product_id = $product_id; foreach ($json as $k => $related) { $custom->customfield_value = $related->id; $json[$k]->displayHTML = $model->displayProductCustomfieldBE($custom, $related->id, $row); $json[$k]->hiddenHTML = $model->setEditCustomHidden($custom, $row); } return $json; } public function getMedias() { if (!JSession::checkToken()) { //echo new JsonResponse(null, JText::_('JINVALID_TOKEN'), true); //exit; } $start = vRequest::getInt('start', 0); $max = vRequest::getInt('max', 16); $type = vRequest::getCmd('mediatype', ''); $list = VmMediaHandler::getImagesList($type, $start, $max); $images = array(); if($list['total']>0){ foreach ($list['images'] as $key => $vmImage) { $image = new stdClass(); $image->virtuemart_media_id = $vmImage->virtuemart_media_id; $image->value = $vmImage->file_title; $image->label = $vmImage->file_title; $image->file_title = $vmImage->file_title; $image->file_meta = $vmImage->file_meta; $image->file_description = $vmImage->file_description; $image->file_url = $vmImage->file_url; $image->ordering = $key; $vmImage->displayMediaThumb($imageArgs = '', $lightbox = false, $effect = "", $return = false); $file_url_thumb = $vmImage->getFileUrlThumb(); $image->file_url_thumb = JURI::root(false) . '/' . str_replace('/', DS, $file_url_thumb); $image->file_url = JURI::root(true) . '/' . $image->file_url; $image->file_url_thumb_img = ''.$image->file_title.''; $image->file_url_img = ''.$image->file_title.''; $images[] = $image; } } else { $image = new stdClass(); $image->virtuemart_media_id = 0; $image->value = ''; $image->label = 'No images with paging start '.$start; $image->file_title = 'No images with paging start '.$start; $images[] = $image; } echo vmJsApi::safe_json_encode($images); jexit(); } }