function onBeforeK2Save(&$item, $isNew) { //Check if Tienda is installed if (!$this->_isInstalled()) { return; } //Get Tienda plugin variables $tiendaParams = new K2Parameter($item->plugins, '', $this->_name); //Get All plugins variables $plugins = new DSCParameter($item->plugins); //Handle assignment if (JRequest::getBool('tiendaAssign')) { $plugins->merge($tiendaParams); $item->plugins = $plugins->toString(); return; } //Handle unassignment if (JRequest::getBool('tiendaUnassign')) { $plugins->set('tiendaproductID', NULL); $plugins->set('tiendaproductName', NULL); $plugins->set('tiendaproductSKU', NULL); $plugins->set('tiendaproductTax', NULL); $plugins->set('tiendaproductManufacturer', NULL); $plugins->set('tiendaproductWeight', NULL); $plugins->set('tiendaproductLength', NULL); $plugins->set('tiendaproductWidth', NULL); $plugins->set('tiendaproductHeight', NULL); $plugins->set('tiendaproductShipping', NULL); $plugins->set('tiendaproductEnabled', NULL); $item->plugins = $plugins->toString(); return; } //Handle unassignment if (JRequest::getBool('tiendaRemove')) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $product = JTable::getInstance('Products', 'TiendaTable'); $product->delete($plugins->get('tiendaproductID')); $plugins->set('tiendaproductID', NULL); $plugins->set('tiendaproductName', NULL); $plugins->set('tiendaproductSKU', NULL); $plugins->set('tiendaproductTax', NULL); $plugins->set('tiendaproductManufacturer', NULL); $plugins->set('tiendaproductWeight', NULL); $plugins->set('tiendaproductLength', NULL); $plugins->set('tiendaproductWidth', NULL); $plugins->set('tiendaproductHeight', NULL); $plugins->set('tiendaproductShipping', NULL); $plugins->set('tiendaproductEnabled', NULL); $item->plugins = $plugins->toString(); return; } //Handle form if ($tiendaParams->get('productName', NULL) && $tiendaParams->get('productSKU', NULL)) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $product = JTable::getInstance('Products', 'TiendaTable'); $product->product_id = $tiendaParams->get('productID', NULL); $product->product_name = $tiendaParams->get('productName', NULL); $product->product_sku = $tiendaParams->get('productSKU', NULL); $product->manufacturer_id = $tiendaParams->get('productManufacturer', 0); $product->tax_class_id = $tiendaParams->get('productTax'); $product->product_weight = $tiendaParams->get('productWeight', NULL); $product->product_length = $tiendaParams->get('productLength', NULL); $product->product_width = $tiendaParams->get('productWidth', NULL); $product->product_height = $tiendaParams->get('productHeight', NULL); $product->product_ships = $tiendaParams->get('productShipping', 0); $product->product_enabled = $tiendaParams->get('productEnabled', 1); $product->save(); $tiendaParams->set('tiendaproductID', $product->product_id); $price = $tiendaParams->get('productPrice', NULL); if ($price) { $price = JTable::getInstance('ProductPrices', 'TiendaTable'); $price->product_id = $product->product_id; $price->product_price = $tiendaParams->get('productPrice', NULL); $price->save(); } $plugins->merge($tiendaParams); $item->plugins = $plugins->toString(); } }