AAAAstockable/stockable.php000066600000100615151372274610011212 0ustar00array('','char'),'selectname2'=>array('','char'),'selectname3'=>array('','char'),'selectname4'=>array('','char'), 'selectoptions1'=>array('','char'),'selectoptions2'=>array('','char'),'selectoptions3'=>array('','char'),'selectoptions4'=>array('','char') ); $this->setConfigParameterable('custom_params',$varsToPush); } // function plgVmOnOrder($product) { // $dbValues['virtuemart_product_id'] = $product->virtuemart_product_id; // $dbValues['stockable'] = $this->_virtuemart_paymentmethod_id; // $this->writeCustomData($dbValues, '#__virtuemart_product_custom_' . $this->_name); // } // get product param for this plugin on edit /** * @see components/com_virtuemart/helpers/vmCustomPlugin::plgVmOnProductEdit() * @author Matt Lewis-Garner * @author Patrick Kohl */ function plgVmOnProductEdit($field, $product_id, &$row,&$retValue) { //TODO Give warning if config not set to disableit_children if ($field->custom_element != $this->_name) return ''; $this->parseCustomParams($field); $html =''; if (!$childs = $this->getChilds($product_id) ) $html .='
'.JTEXT::_('VMCUSTOM_STOCKABLE_NO_CHILD').'
'; $db = JFactory::getDBO(); // $db->setQuery('SELECT `virtuemart_custom_id` FROM `#__virtuemart_customs` WHERE field_type="G" '); // $group_custom_id = $db->loadResult(); // $plgParam = $this->getVmCustomParams($field->virtuemart_custom_id); $html .=''.JText::_('VMCUSTOM_STOCKABLE_IS_VARIANT').''; for ($i = 1; $i<5 ;$i++) { $selectname = 'selectname'.$i ; $listname = $field->$selectname; if (!empty($listname)) { $html .=' '.JTEXT::_($listname).''; } } $html .=' '. JText::_('VMCUSTOM_STOCKABLE_PRICE') .''; // $param = json_decode($field->custom_param,true); if (isset($field->child)) $childList = $field->child; else $childList = array(); $html .= '
'; foreach ($childs as $child ) { $checked =''; $price = null; if(!empty($childList)) { if (!array_key_exists($child->id, $childList) ) $childList[$child->id]['is_variant'] = 1; if ($childList[$child->id]['is_variant'] ) $checked='checked'; if (array_key_exists('custom_price', $childList[$child->id] ) ) $price = $childList[$child->id]['custom_price'] ; } //$html .= JHTML::_('select.genericlist', $childlist, 'custom_param['.$row.'][child_id]','','virtuemart_product_id','product_name',$param['child_id'],false,true); $name='custom_param['.$row.'][child]['.$child->id.']'; $html .='
' ; $html .=' '; $html .=' '; $html .=$this->getCustomOptionsForm($field, $name, $childList[$child->id]); //$html .=''; // if (!$customfield = $this->getFieldId($product_id, $child->id) ) $price ='' ; // else $html .=''; // $html .=''; // $html .=''; $html .= ' '.$child->product_name.' ['.JText::_('COM_VIRTUEMART_PRODUCT_IN_STOCK').' : '.$child->stock.']
' ; } $html .='
'. JText::_('COM_VIRTUEMART_PRODUCT_FORM_NEW_PRODUCT_LBL').'
'. JText::_('COM_VIRTUEMART_PRODUCT_SKU').' '. JText::_('COM_VIRTUEMART_PRODUCT_NAME').' '. JText::_('VMCUSTOM_STOCKABLE_PRICE').' '. JText::_('COM_VIRTUEMART_PRODUCT_IN_STOCK').' '. JText::_('COM_VIRTUEMART_ADD').'
'; $new_fields = $this->getCustomOptionsForm($field, '{{NAME}}', array()); $script = " jQuery( function($) { $('#new_stockable_product').click(function() { var Prod = $('#new_stockable');// input[name^=\"stockable\"]').serialize(); $.getJSON('index.php?option=com_virtuemart&view=product&task=saveJS&token=".JUtility::getToken()."' , { product_sku: Prod.find('input[name*=\"product_sku\"]').val(), product_name: Prod.find('input[name*=\"product_name\"]').val(), product_price: Prod.find('input[name*=\"product_price\"]').val(), product_in_stock: Prod.find('input[name*=\"product_in_stock\"]').val(), product_parent_id: ".$product_id.", published: 1, format: \"json\" }, function(data) { //console.log (data); //$.each(data.msg, function(index, value){ // $(\"#new_stockable\").append(data.msg); //}); name='custom_param[".$row."][child]['+data.product_id+']'; new_fields = '".str_replace("\n", '', $new_fields)."'; new_fields = new_fields.replace(/\{\{NAME\}\}/g, name); $('#stockables').append( '
' + '' + '' + new_fields + '' + ' '+Prod.find('input[name*=\"product_name\"]').val()+' [".JText::_('COM_VIRTUEMART_PRODUCT_SKU')." : '+Prod.find('input[name*=\"product_sku\"]').val()+'] [".JText::_('COM_VIRTUEMART_PRODUCT_IN_STOCK')." : '+(Prod.find('input[name*=\"product_in_stock\"]').val() || 0)+']' + '
'); Prod.find('input[name*=\"product_sku\"]').val(''); Prod.find('input[name*=\"product_name\"]').val(''); Prod.find('input[name*=\"product_price\"]').val(''); Prod.find('input[name*=\"product_in_stock\"]').val(''); }); }); jQuery('input[name=field\\\\[$row\\\\]\\\\[custom_price\\\\]]').val('0.0'); }); "; //$document = JFactory::getDocument(); //$document->addScriptDeclaration($script); // $html =' '; // $html .=''; //$html .=JTEXT::_('VMCUSTOM_TEXTINPUT_NO_CHANGES_BE'); $retValue .= $html.''; return true ; } /** * Get the formatted options dropdowns and input fields (backend) * @author Matt Lewis-Garner */ function getCustomOptionsForm($field, $name, $values) { $options_html = ''; for ($i = 1; $i<5 ;$i++) { $selectoptions = 'selectoptions'.$i ; $attributes = 'attribute'.$i ; if (isset($field->$selectoptions)) $selectoption = (string)$field->$selectoptions; else $selectoption = "" ; $option = array(); $tmpOptions = str_replace( "\r", "" ,$selectoption); if ($listoptions = explode("\n",$tmpOptions ) ) { foreach ($listoptions as $key => $val) $option[] = JHTML::_('select.option',JText::_( $val ) , $val ); if (empty($values[$selectoptions])) { $values[$selectoptions] =''; } if ($listoptions[0] == '' && $field->{'selectname'.$i}) { $options_html .= '';// '.JText::_('VMCUSTOM_STOCKABLE_NO_OPTION') .''; } else if ($listoptions[0] == '') { $options_html .= ''; } else { $options_html .= JHTML::_('select.genericlist', $option, $name.'['.$selectoptions.']','style="width:100px !important;float:none;"','text','value',$values[$selectoptions],false,true)."\n"; } } } return $options_html; } /** * @ idx plugin index * @see components/com_virtuemart/helpers/vmCustomPlugin::onDisplayProductFE() * @author Matt Lewis-Garner * @author Patrick Kohl */ function plgVmOnDisplayProductVariantFE($field,&$row,&$group) { // default return if it's not this plugin if ($field->custom_element != $this->_name) return ''; $row++; $this->parseCustomParams($field); //if (!$childs = $this->getChilds($product_id) ) return ; $this->stockhandle = VmConfig::get('stockhandle','none'); $html='
'; $customfield_id = array(); $selects = array(); $js = array(); // generate option with valid child results foreach($field->child as $child_id => &$attribut) { if ($attribut['is_variant']==1) { unset ($attribut['is_variant']); if ($stock = $this->getValideChild( $child_id)) { $field->child[$child_id]['in_stock'] = $stock->product_in_stock - $stock->product_ordered; // Availability Image if ($field->child[$child_id]['in_stock'] < 1) { if ($this->stockhandle == 'risetime' and VmConfig::get('rised_availability') and empty($stock->product_availability)) { $field->child[$child_id]['product_availability'] = (file_exists(JPATH_BASE . DS . VmConfig::get('assets_general_path') . 'images/availability/' . VmConfig::get('rised_availability'))) ? JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' . VmConfig::get('rised_availability', '7d.gif'), VmConfig::get('rised_availability', '7d.gif'), array('class' => 'availability')) : $field->child[$child_id]['product_availability'] = VmConfig::get('rised_availability'); } else if (!empty($stock->product_availability)) { $field->child[$child_id]['product_availability'] = (file_exists(JPATH_BASE . DS . VmConfig::get('assets_general_path') . 'images/availability/' . $stock->product_availability)) ? JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' . $stock->product_availability, $stock->product_availability, array('class' => 'availability')) : $field->child[$child_id]['product_availability'] = $stock->product_availability; } } //$field->child[$child_id]['product_availability'] = $stock->product_availability; if ($attribut['custom_price']) $js[]= '"'.$child_id.'" :'.$attribut['custom_price']; unset ($attribut['custom_price']); foreach ($attribut as $key => $list) { // if (!in_array($key,$selects)) { // $selects[$key] = array() ; // } // if (!in_array($list , $selects[$key]) ) { if (preg_match('/^selectoptions\d+$/', $key)) { $selects[$key][$list] = $list ; $attribut[$key] = array($list,JText::_($list)); } // } } } } else unset ($attribut); } // Javascript can be added multiple times for multiple products on a page, // so need to suffix everything for the right products $js_suffix = $field->virtuemart_customfield_id;//.'_'.uniqid(); $html .= '
'; $i = 1; foreach ($selects as $keys =>$options) { $selectname = 'selectname'.$i; $listname = $field->$selectname; if (!empty($listname)) { $optionName = 'customPlugin['.$field->virtuemart_customfield_id.']['.$this->_name.']['.$keys.']'; $option = array(); $show_select = false; foreach ($options as $key => $val) { if (!empty($val)) { if (1 == $i) { $option[] = JHTML::_('select.option', $val, JText::_( $val )); } $show_select = true; } } if ($show_select) { $html .='
'.JTEXT::_($listname).''; $html .= JHTML::_('select.genericlist', $option,$optionName ,'class="attribute_list no-vm-bind customfield_id_'.$js_suffix.'" style="width:100px !important;"','value','text',reset($options),'selectoptions'.$i,false)."
\n"; } else $html .='' ; } $i++; } $html .= '
'; static $stockablejs; $group->display = $html.' '; // preventing 2 x load javascript /*if ($stockablejs) return; $stockablejs = true ;*/ // TODO ONE PARAM IS MISSING $document = JFactory::getDocument(); $js = ' //stockhandle.'"; var stockable_'.$js_suffix.' =$.parseJSON(\'' .str_replace('\"', '\\\"', json_encode($field->child)). '\') ; var selections_'.$js_suffix.' = []; //var original=[]; // var totalattribut_'.$js_suffix.' = $("select.attribute_list.customfield_id_'.$js_suffix.'").length+1; var totalattribut_'.$js_suffix.' = []; // get all initial select list values /*$.each($(".attribute_list"), function(idx,selec) { original[selec.name] = $.map($(this).find("option"), function(idx, opt) { return [[ idx.value ,idx.text ]]; }); });*/ // if ( $("#selectoptions1.attribute_list.customfield_id_'.$js_suffix.'").length ) { if ( $("select.attribute_list.customfield_id_'.$js_suffix.'").length ) { var stockableBlockIndex = 0; $(".stockable_block_'.$js_suffix.'").each(function() { $(this).attr("id", "stockableBlockIndex_'.$js_suffix.'_" + stockableBlockIndex); totalattribut_'.$js_suffix.'[stockableBlockIndex] = $(this).find("select.attribute_list.customfield_id_'.$js_suffix.'").length+1; recalculate_'.$js_suffix.'(stockableBlockIndex, $(this).find("select.attribute_list.customfield_id_'.$js_suffix.'").eq(0)); stockableBlockIndex++; }); } $("select.attribute_list.customfield_id_'.$js_suffix.'").unbind("change"); $("select.attribute_list.customfield_id_'.$js_suffix.'").change(function(){ var stockableBlockIndex = $(this).parents(".stockable_block_'.$js_suffix.'").attr("id").split("_"); recalculate_'.$js_suffix.'(stockableBlockIndex[stockableBlockIndex.length-1], $(this)); }); function recalculate_'.$js_suffix.'(stockableBlockIndex, Opt){ var found_id = 0; var currentIndex = $("#stockableBlockIndex_'.$js_suffix.'_"+stockableBlockIndex+" select.attribute_list.customfield_id_'.$js_suffix.'").index(Opt) +1; selections_'.$js_suffix.'[stockableBlockIndex] = []; var i=1; $("#stockableBlockIndex_'.$js_suffix.'_"+stockableBlockIndex+" select.attribute_list.customfield_id_'.$js_suffix.'").each(function() { selections_'.$js_suffix.'[stockableBlockIndex][i] = $(this).val(); // Clear the following selects if (i > currentIndex) { $(this).empty(); } i++; }); // Find current values /*for(var i=1; ispan").remove(); $(".addtocart-bar>div").remove(); $(".addtocart-bar>a.notify").remove(); $(".addtocart-bar").append(\'' . JText::_('COM_VIRTUEMART_CART_NOTIFY') . '\'); } else { var quantity = $(".addtocart-bar .quantity-input").val(); if (isNaN(quantity)) { quantity = 1; } $(".addtocart-bar>span").remove(); $(".addtocart-bar>div").remove(); $(".addtocart-bar>a.notify").remove(); $(".addtocart-bar").append(\'
\'); Virtuemart.product($("form.product")); } $(".availability").remove(); if ("risetime" == stockhandle && stockable_'.$js_suffix.'[found_id].product_availability) { $(".addtocart-area").after(\'
\' + stockable_'.$js_suffix.'[found_id].product_availability + \'
\'); } // recalculate the price by found product child id; formProduct = Opt.parents("form.product"); virtuemart_product_id = formProduct.find(\'input[name="virtuemart_product_id[]"]\').val(); //formProduct.find("#selectedStockable").remove(); //formProduct.append(\'\'); formProduct.find(\'input[name*="customPlugin['.$field->virtuemart_customfield_id.']['.$this->_name.'][child_id]"]\').val(found_id); //(\'\'); Virtuemart.setproducttype(formProduct,virtuemart_product_id); } function isChildValid_'.$js_suffix.'(stockableBlockIndex, child_attrib, currentIndex) { return_value = true; for (var i = currentIndex; i > 0; i--) { if (child_attrib["selectoptions"+i][0] != selections_'.$js_suffix.'[stockableBlockIndex][i]) { return_value = false; } } return return_value; } function populateNextSelect_'.$js_suffix.'(stockableBlockIndex, child_attrib, nextIndex) { var selectList = $("#stockableBlockIndex_'.$js_suffix.'_"+stockableBlockIndex+" select.attribute_list.customfield_id_'.$js_suffix.'"); var nextSelect = selectList.eq(nextIndex-1); // if the select exists if ("undefined" !== typeof(nextSelect) && nextSelect.length > 0) { // if it doesn\'t already contain this option, add it if (nextSelect.find("option[value=\'" + child_attrib["selectoptions"+nextIndex][0] + "\']").length == 0) { nextSelect.append(""); } // if there is only one option, make it selected if (1 == nextSelect.find("option").length) { nextSelect.find("option").attr("selected","selected"); selections_'.$js_suffix.'[stockableBlockIndex][nextIndex] = child_attrib["selectoptions"+nextIndex][0]; } // if this is the selected value, populate the next select too if (nextSelect.val() == child_attrib["selectoptions"+nextIndex][0]) { populateNextSelect_'.$js_suffix.'(stockableBlockIndex, child_attrib, nextIndex+1); } } } }); //]]> '; //$document->addScriptDeclaration($js); $group->display .= ''; // 'custom_param['.$keys.']' //dump($param); //"is_variant":"1","attribute1":"Red","attribute2":"20 cm","attribute3":"10","attribute4":"10" //echo $plgParam->get('custom_info'); // Here the plugin values //$html =JTEXT::_($param['custom_name']) ; //$html.=':
'; return true; } function plgVmOnDisplayProductFE( $product, &$idx,&$group){} /** * @see components/com_virtuemart/helpers/vmCustomPlugin::plgVmOnViewCartModule() * @author Patrick Kohl */ function plgVmOnViewCartModule( $product, $row,&$html) { if (empty($product->productCustom->custom_element) or $product->productCustom->custom_element != $this->_name) return ''; if (!$plgParam = $this->GetPluginInCart($product)) return false ; foreach ($plgParam as $attributes) { foreach ($attributes as $k => $attribute) { if ($k =='child_id') continue; $html .=' '.JText::_($attribute).' '; } } return true; } /** * @see components/com_virtuemart/helpers/vmCustomPlugin::plgVmOnViewCart() * @author Patrick Kohl */ function plgVmOnViewCart($product, $row,&$html) { if (empty($product->productCustom->custom_element) or $product->productCustom->custom_element != $this->_name) return ''; if (!$plgParam = $this->GetPluginInCart($product)) return false ; $html .= '
'; foreach ($plgParam as $attributes) { foreach ($attributes as $k => $attribute) { if ($k =='child_id') continue; $html .=' '.JText::_($attribute).' '; } } // $html .=''.$param->Morecomment.''; $html.='
'; return true; //vmdebug('stockable attributs',$plgParam); } /** * * vendor order display BE */ function plgVmDisplayInOrderBE($item, $row,&$html) { if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return ''; return $this->plgVmOnViewCart($item, $row,$html); } /** * * shopper order display FE */ function plgVmDisplayInOrderFE($item, $row,&$html) { if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return ''; return $this->plgVmOnViewCart($item, $row,$html); } function getChilds($child_id = null) { if ($child_id) { $db = JFactory::getDBO(); $q = 'SELECT CONCAT( `product_name`, " [' .JText::_('COM_VIRTUEMART_PRODUCT_SKU').'"," : ",`product_sku`,"]") as product_name,`virtuemart_product_id` as id, `product_in_stock` as stock FROM `#__virtuemart_products_'.VMLANG.'` as l ' . ' JOIN `#__virtuemart_products` AS p using (`virtuemart_product_id`)' . ' WHERE `product_parent_id` ='.(int)$child_id . ' ORDER BY `pordering`' ; $db->setQuery($q); $result = $db->loadObjectList(); if (!($result)) { //JError::raiseWarning(500, $db->getErrorMsg()); return array(); } else return $result ; } else { return array(); } } function getFieldId($virtuemart_product_id, $child_id ) { $db = JFactory::getDBO(); $q = 'SELECT cf.* FROM `#__virtuemart_product_customfields` as cf JOIN `#__virtuemart_customs` as c ON `c`.`virtuemart_custom_id` = cf.`virtuemart_custom_id` AND c.`field_type`="G" WHERE cf.`virtuemart_product_id` ='.(int)$virtuemart_product_id.' and cf.custom_value='.(int)$child_id ; $db->setQuery($q); $result = $db->loadObject(); if (!($result)) { //JError::raiseWarning(500, $db->getErrorMsg()); return false; } else return $result ; } /** * Get the child object for the given ID if it is valid for the config * @author Matt Lewis-Garner */ function getValideChild($child_id ) { $productModel = VmModel::getModel('product'); $child = $productModel->getProduct($child_id,true,false,true,1,false); /*$db = JFactory::getDBO(); $q = 'SELECT `product_sku`,`product_name`,`product_in_stock`,`product_ordered`,`product_availability`,`product_weight` FROM `#__virtuemart_products` JOIN `#__virtuemart_products_'.VMLANG.'` as l using (`virtuemart_product_id`) WHERE `published`=1 and `virtuemart_product_id` ='.(int)$child_id ; $db->setQuery($q); $child = $db->loadObject();*/ if ($child) { if ('disableit_children' === $this->stockhandle) { $stock = $child->product_in_stock - $child->product_ordered ; if ($stock>0)return $child ; else return false ; } else return $child ; } return false ; } public function plgVmGetProductStockToUpdateByCustom(&$item, $pluginParam, $productCustom) { if ($productCustom->custom_element !== $this->_name) return false ; //vmdebug('$pluginParam',$pluginParam[$this->_name]); $item->virtuemart_product_id = (int)$pluginParam[$this->_name]['child_id']; return true ; // echo $item[0]->virtuemart_product_id;jexit(); } /** * We must reimplement this triggers for joomla 1.7 * vmplugin triggers note by Max Milbers */ public function plgVmOnStoreInstallPluginTable($psType) { // return $this->onStoreInstallPluginTable($psType); } function plgVmDeclarePluginParamsCustom($psType,$name,$id, &$data){ return $this->declarePluginParams('custom', $name, $id, $data); } function plgVmSetOnTablePluginParamsCustom($name, $id, &$table){ return $this->setOnTablePluginParams($name, $id, $table); } /** * Custom triggers note by Max Milbers */ function plgVmOnDisplayEdit($virtuemart_custom_id,&$customPlugin){ return $this->onDisplayEditBECustom($virtuemart_custom_id,$customPlugin); } public function plgVmCalculateCustomVariant($product, &$productCustomsPrice,$selected){ if ($productCustomsPrice->custom_element != $this->_name) return false; if (!$customPlugin = JRequest::getVar('customPlugin',0)) { $customPlugin = json_decode($product->customPlugin,true); } $selected = $customPlugin[$productCustomsPrice->virtuemart_customfield_id]['stockable']['child_id']; $param = json_decode($productCustomsPrice->custom_param,true); if ($child = $this->getValideChild($selected)) { if ($param['child'][$selected]['custom_price'] !=='') { $productCustomsPrice->custom_price = (float)$param['child'][$selected]['custom_price']; } else { // Get the user details $usermodel = VmModel::getModel ('user'); $currentVMuser = $usermodel->getCurrentUser (); $db = JFactory::getDbo(); if (is_array($currentVMuser->shopper_groups)) { $shgroup = $currentVMuser->shopper_groups[0]; } else { $shgroup = $currentVMuser->shopper_groups; } $query = $db->getQuery(true) ->select($db->qn('product_price')) ->from($db->qn('#__virtuemart_product_prices')) ->where($db->qn('virtuemart_product_id').' = '.(int)$selected) ->where($db->qn('virtuemart_shoppergroup_id').' = '.$shgroup); $db->setQuery($query); $price = $db->loadResult(); if (empty($price)) { // Check for price to show to all $query->clear('where') ->where($db->qn('virtuemart_product_id').' = '.(int)$selected) ->where('('.$db->qn('virtuemart_shoppergroup_id').' = 0 OR '.$db->qn('virtuemart_shoppergroup_id').' = NULL)'); $db->setQuery($query); $price = $db->loadResult(); } if (!empty($price)) $product->product_price = (float)$price; /*$db = JFactory::getDBO(); $db->setQuery('SELECT `product_price` FROM `#__virtuemart_product_prices` WHERE `virtuemart_product_id`="' . (int)$selected . '" '); if ($price = $db->loadResult()) $product->product_price = (float)$price;*/ } //TODO merge parent and child (eg product_weight) return $child; } else return false; // find the selected child } public function plgVmOnAddToCart(&$product){ $customPlugin = JRequest::getVar('customPlugin',0); if ($customPlugin) { $db = JFactory::getDBO(); $query = 'SELECT C.* , field.* FROM `#__virtuemart_customs` AS C LEFT JOIN `#__virtuemart_product_customfields` AS field ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id` WHERE `virtuemart_product_id` =' . $product->virtuemart_product_id.' and `custom_element`="'.$this->_name.'"'; $query .=' and is_cart_attribute = 1'; $db->setQuery($query); $productCustomsPrice = $db->loadObject(); if (!$productCustomsPrice) return null; // if ( !in_array($this->_name,$customPlugin[$productCustomsPrice->virtuemart_custom_id]) ) return false; $selected = $customPlugin[$productCustomsPrice->virtuemart_customfield_id]['stockable']['child_id']; if (!$child = $this->plgVmCalculateCustomVariant($product, $productCustomsPrice,$selected) ) return false; /*if ($child->product_sku) $product->product_sku = $child->product_sku; if ($child->product_name) $product->product_name = $child->product_name; $product->product_in_stock = $child->product_in_stock;*/ foreach ($product as $key => $value) { if ('virtuemart_product_id' != $key) { if ($child->$key) { $product->$key = $child->$key; } } } $product->product_in_stock = $child->product_in_stock; $this->stockhandle = VmConfig::get('stockhandle','none'); if ('disableit' == $this->stockhandle || 'disableit_children' == $this->stockhandle || 'disableadd' == $this->stockhandle) { if (!class_exists ('VirtueMartCart')) { require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'); } $cart = VirtueMartCart::getCart (); $orderedQuantity = $product->quantity; foreach ($cart->products as $cartProduct) { $cartProductParam = json_decode($cartProduct->customPlugin); if ($cartProductParam->{$productCustomsPrice->virtuemart_customfield_id}->stockable->child_id == $selected) { $orderedQuantity += $cartProduct->quantity; if ($orderedQuantity > $product->product_in_stock) { return false; } } } } } } public function plgVmDisplayInOrderCustom(&$html,$item, $param,$productCustom, $row ,$view='FE'){ $this->plgVmDisplayInOrderCustom($html,$item, $param,$productCustom, $row ,$view); } public function plgVmCreateOrderLinesCustom(&$html,$item,$productCustom, $row ){ // $this->createOrderLinesCustom($html,$item,$productCustom, $row ); } } // No closing tagstockable/stockable.xml000066600000004457151372274610011232 0ustar00 VMCUSTOM_STOCKABLE January 10 2014 The VirtueMart Development Team http://www.virtuemart.net Copyright (C) 2004-2012 Virtuemart Team. All rights reserved. http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL 2.0.26d VMCUSTOM_STOCKABLE_DESC en-GB.plg_vmcustom_stockable.ini fr-FR.plg_vmcustom_stockable.ini stockable.php stockable/index.html000066600000000000151372274610010512 0ustar00stockable/.htaccess000066600000000177151372274610010332 0ustar00 Order allow,deny Deny from all specification/index.html000066600000000000151372274610011363 0ustar00specification/.htaccess000066600000000177151372274610011203 0ustar00 Order allow,deny Deny from all specification/specification/.htaccess000066600000000177151372274610014023 0ustar00 Order allow,deny Deny from all specification/specification/tmpl/.htaccess000066600000000177151372274610014777 0ustar00 Order allow,deny Deny from all specification/specification/tmpl/index.html000066600000000000151372274610015157 0ustar00specification/specification/tmpl/default.php000066600000000721151372274610015331 0ustar00custom_title) ; ?>
params->custom_specification_name1 ?>
params->custom_specification_default1 ?>
params->custom_specification_name2 ?>
params->custom_specification_default2 ?>
specification/specification/index.html000066600000000037151372274610014215 0ustar00 specification/specification.php000066600000015767151372274610012751 0ustar00_tablepkey = 'id'; $this->tableFields = array_keys($this->getTableSQLFields()); $this->varsToPush = array( 'custom_specification_name1'=> array('', 'char'), 'custom_specification_default1'=> array('', 'string'), 'custom_specification_name2'=> array('', 'char'), 'custom_specification_default2'=> array('', 'string'), ); $this->setConfigParameterable('custom_params',$this->varsToPush); } /** * Create the table for this plugin if it does not yet exist. * @author Val�rie Isaksen */ public function getVmPluginCreateTableSQL() { return $this->createTableSQL('Product Specification Table'); } function getTableSQLFields() { $SQLfields = array( 'id' => 'int(11) unsigned NOT NULL AUTO_INCREMENT', 'virtuemart_product_id' => 'int(11) UNSIGNED DEFAULT NULL', 'virtuemart_custom_id' => 'int(11) UNSIGNED DEFAULT NULL', 'custom_specification_default1' => 'varchar(1024) NOT NULL DEFAULT \'\' ', 'custom_specification_default2' => 'varchar(1024) NOT NULL DEFAULT \'\' ' ); return $SQLfields; } /* * (only to add if you want Searchable Plugin) * * Render the search in category * @ $selectList the list contain all the possible plugin(+customparent_id) * @ &$searchCustomValues The HTML to render as search fields * */ public function plgVmSelectSearchableCustom(&$selectList,&$searchCustomValues,$virtuemart_custom_id) { $db =JFactory::getDBO(); $db->setQuery('SELECT `virtuemart_custom_id`, `custom_title` FROM `#__virtuemart_customs` WHERE `custom_element` ="'.$this->_name.'"'); if ($this->selectList = $db->loadAssocList() ) { foreach ($this->selectList as $selected_custom_id) { if ($virtuemart_custom_id == $selected_custom_id['virtuemart_custom_id']) { $searchCustomValues.=''; } } $selectList = array_merge((array)$this->selectList,$selectList); } return true; } /* * (only to add if you want Searchable Plugin) * * Extend the search in category * @ $where the list contain all the possible plugin(+customparent_id) * @ $PluginJoinTables The plg_name table to join on the search * (in normal case must be = to $this->_name) */ public function plgVmAddToSearch(&$where,&$PluginJoinTables,$custom_id) { if ($keyword = vmRequest::uword('custom_specification_name1', null, ' ')) { $db = JFactory::getDBO(); if ($this->_name != $this->GetNameByCustomId($custom_id)) return; $keyword = '"%' . $db->getEscaped( $keyword, true ) . '%"' ; $where[] = $this->_name .'.`custom_specification_default1` LIKE '.$keyword; $PluginJoinTables[] = $this->_name ; } return true; } // get product param for this plugin on edit function plgVmOnProductEdit($field, $product_id, &$row,&$retValue) { if ($field->custom_element != $this->_name) return ''; // $this->tableFields = array ( 'id', 'virtuemart_custom_id', 'custom_specification_default1', 'custom_specification_default2' ); $this->getCustomParams($field); $this->getPluginCustomData($field, $product_id); // $data = $this->getVmPluginMethod($field->virtuemart_custom_id); // VmTable::bindParameterable($field,$this->_xParams,$this->_varsToPushParam); // $html =' '; $html ='
'; $html .='
'.$this->params->custom_specification_name1.'
'; $html .=''; $html .='
'.$this->params->custom_specification_name2.'
'; $html .=''; $html .=''; $html .='
'; // $field->display = $retValue .= $html ; $row++; return true ; } /** * @ idx plugin index * @see components/com_virtuemart/helpers/vmCustomPlugin::onDisplayProductFE() * @author Patrick Kohl * Display product */ function plgVmOnDisplayProductFE($product,&$idx,&$group) { // default return if it's not this plugin if ($group->custom_element != $this->_name) return ''; $this->_tableChecked = true; $this->getCustomParams($group); $this->getPluginCustomData($group, $product->virtuemart_product_id); // Here the plugin values //$html =JTEXT::_($group->custom_title) ; $group->display .= $this->renderByLayout('default',array($this->params,&$idx,&$group ) ); return true; } function plgVmOnStoreProduct($data,$plugin_param){ // $this->tableFields = array ( 'id', 'virtuemart_product_id', 'virtuemart_custom_id', 'custom_specification_default1', 'custom_specification_default2' ); return $this->OnStoreProduct($data,$plugin_param); } /** * We must reimplement this triggers for joomla 1.7 * vmplugin triggers note by Max Milbers */ public function plgVmOnStoreInstallPluginTable($psType,$name) { return $this->onStoreInstallPluginTable($psType,$name); } function plgVmSetOnTablePluginParamsCustom($name, $id, &$table){ return $this->setOnTablePluginParams($name, $id, $table); } function plgVmDeclarePluginParamsCustom($psType,$name,$id, &$data){ return $this->declarePluginParams('custom', $name, $id, $data); } /** * Custom triggers note by Max Milbers */ function plgVmOnDisplayEdit($virtuemart_custom_id,&$customPlugin){ return $this->onDisplayEditBECustom($virtuemart_custom_id,$customPlugin); } } // No closing tagspecification/specification.xml000066600000003241151372274610012742 0ustar00 VMCustom - specification January 09 2013 The VirtueMart Development Team http://www.virtuemart.net Copyright (C) 2004-2012 Virtuemart Team. All rights reserved. http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL 2.0.18a Specification plugin for product en-GB.plg_vmcustom_specification.ini fr-FR.plg_vmcustom_specification.ini specification.php textinput/index.html000066600000000000151372274610010607 0ustar00textinput/textinput/.htaccess000066600000000177151372274610012473 0ustar00 Order allow,deny Deny from all textinput/textinput/index.html000066600000000000151372274610012653 0ustar00textinput/textinput/tmpl/default.php000066600000001702151372274610014001 0ustar00custom_price_by_letter) $class='vmcustom-textinput';?>
addScriptDeclaration(' /* */ ');textinput/textinput/tmpl/.htaccess000066600000000177151372274610013447 0ustar00 Order allow,deny Deny from all textinput/textinput/tmpl/index.html000066600000000000151372274610013627 0ustar00textinput/textinput.xml000066600000003201151372274610011406 0ustar00 VMCustom - textinput January 10 2014 The VirtueMart Development Team http://www.virtuemart.net Copyright (C) 2004-2012 Virtuemart Team. All rights reserved. http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL 2.0.26d text input plugin for product en-GB.plg_vmcustom_textinput.ini fr-FR.plg_vmcustom_textinput.ini textinput.php textinput textinput/textinput.php000066600000014510151372274610011402 0ustar00array(0.0,'int'), 'custom_price_by_letter'=>array(0.0,'bool') ); $this->setConfigParameterable('custom_params',$varsToPush); } // get product param for this plugin on edit function plgVmOnProductEdit($field, $product_id, &$row,&$retValue) { if ($field->custom_element != $this->_name) return ''; // $html .=''; $this->parseCustomParams($field); $html ='
'. JText::_('VMCUSTOM_TEXTINPUT') .' '.VmHTML::row('input','VMCUSTOM_TEXTINPUT_SIZE','custom_param['.$row.'][custom_size]',$field->custom_size). '
'. JText::_('VMCUSTOM_TEXTINPUT_PRICE_BY_LETTER_OR_INPUT'). ' '; $html .= ($field->custom_price_by_letter==1)?JText::_('VMCUSTOM_TEXTINPUT_PRICE_BY_LETTER'):JText::_('VMCUSTOM_TEXTINPUT_PRICE_BY_INPUT'); $html .='
'; $retValue .= $html; $row++; return true ; } /** * @ idx plugin index * @see components/com_virtuemart/helpers/vmCustomPlugin::onDisplayProductFE() * @author Patrick Kohl * eg. name="customPlugin['.$idx.'][comment] save the comment in the cart & order */ function plgVmOnDisplayProductVariantFE($field,&$idx,&$group) { // default return if it's not this plugin if ($field->custom_element != $this->_name) return ''; $this->getCustomParams($field); $group->display .= $this->renderByLayout('default',array($field,&$idx,&$group ) ); return true; // return $html; } //function plgVmOnDisplayProductFE( $product, &$idx,&$group){} /** * @see components/com_virtuemart/helpers/vmCustomPlugin::plgVmOnViewCartModule() * @author Patrick Kohl */ function plgVmOnViewCartModule( $product,$row,&$html) { return $this->plgVmOnViewCart($product,$row,$html); } /** * @see components/com_virtuemart/helpers/vmCustomPlugin::plgVmOnViewCart() * @author Patrick Kohl */ function plgVmOnViewCart($product,$row,&$html) { if (empty($product->productCustom->custom_element) or $product->productCustom->custom_element != $this->_name) return ''; if (!$plgParam = $this->GetPluginInCart($product)) return '' ; foreach($plgParam as $k => $item){ if(!empty($item['comment']) ){ if($product->productCustom->virtuemart_customfield_id==$k){ $html .=''.JText::_($product->productCustom->custom_title).' '.$item['comment'].''; } } } return true; } /** * * vendor order display BE */ function plgVmDisplayInOrderBE($item, $row, &$html) { if(!empty($productCustom)){ $item->productCustom = $productCustom; } if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return ''; $this->plgVmOnViewCart($item,$row,$html); //same render as cart } /** * * shopper order display FE */ function plgVmDisplayInOrderFE($item, $row, &$html) { if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return ''; $this->plgVmOnViewCart($item,$row,$html); //same render as cart } /** * We must reimplement this triggers for joomla 1.7 * vmplugin triggers note by Max Milbers */ public function plgVmOnStoreInstallPluginTable($psType) { //Should the textinput use an own internal variable or store it in the params? //Here is no getVmPluginCreateTableSQL defined // return $this->onStoreInstallPluginTable($psType); } function plgVmDeclarePluginParamsCustom($psType,$name,$id, &$data){ return $this->declarePluginParams('custom', $name, $id, $data); } function plgVmSetOnTablePluginParamsCustom($name, $id, &$table){ return $this->setOnTablePluginParams($name, $id, $table); } /** * Custom triggers note by Max Milbers */ function plgVmOnDisplayEdit($virtuemart_custom_id,&$customPlugin){ return $this->onDisplayEditBECustom($virtuemart_custom_id,$customPlugin); } public function plgVmCalculateCustomVariant($product, &$productCustomsPrice,$selected){ if ($productCustomsPrice->custom_element !==$this->_name) return ; $customVariant = $this->getCustomVariant($product, $productCustomsPrice,$selected); if (!empty($productCustomsPrice->custom_price)) { //TODO adding % and more We should use here $this->interpreteMathOp // eg. to calculate the price * comment text length if (!empty($customVariant['comment'])) { if ($productCustomsPrice->custom_price_by_letter ==1) { $charcount = strlen ($customVariant['comment']); } else { $charcount = 1.0; } $productCustomsPrice->custom_price = $charcount * $productCustomsPrice->custom_price ; } else { $productCustomsPrice->custom_price = 0.0; } } return true; } public function plgVmDisplayInOrderCustom(&$html,$item, $param,$productCustom, $row ,$view='FE'){ $this->plgVmDisplayInOrderCustom($html,$item, $param,$productCustom, $row ,$view); } public function plgVmCreateOrderLinesCustom(&$html,$item,$productCustom, $row ){ // $this->createOrderLinesCustom($html,$item,$productCustom, $row ); } function plgVmOnSelfCallFE($type,$name,&$render) { $render->html = ''; } } // No closing tagtextinput/.htaccess000066600000000177151372274610010427 0ustar00 Order allow,deny Deny from all .htaccess000066600000000177151372274610006363 0ustar00 Order allow,deny Deny from all index.html000066600000000037151372274610006555 0ustar00