Ejemplo n.º 1
0
    function fetchElement($name, $value, &$node, $control_name)
    {
        $output = '
		<input type="text" class="text_area" value="" id="pluginstiendaproductPrice" name="plugins[tiendaproductPrice]">
		<span class="k2Note">' . JText::_('Set Normal Price Now Special Prices Later') . '</span>
		';
        $id = JRequest::getInt('cid');
        if ($id) {
            $K2Item = JTable::getInstance('K2Item', 'Table');
            $K2Item->load($id);
            $params = new K2Parameter($K2Item->plugins, JPATH_PLUGINS . '/k2/tienda.xml', 'tienda');
            $productID = $params->get('productID');
            if ($productID) {
                Tienda::load('TiendaUrl', 'library.url');
                Tienda::load("TiendaHelperProduct", 'helpers.product');
                $prices = TiendaHelperProduct::getPrices($productID);
                if (count($prices)) {
                    $output = '<div class="tiendaButton">' . TiendaUrl::popup("index.php?option=com_tienda&controller=products&task=setprices&id=" . $productID . "&tmpl=component", JText::_('COM_TIENDA_SET_PRICES')) . '</div>';
                    $output .= '<div>';
                    foreach (@$prices as $price) {
                        $output .= '
						<div>
							<span>' . TiendaHelperBase::currency($price->product_price) . '</span>
							<div class="tiendaButton"><a href="' . $price->link_remove . '&return=' . base64_encode("index.php?option=com_k2&view=item&cid=" . $id) . '">' . JText::_('Remove') . '</a></div>
						</div>';
                    }
                    $output .= '</div>';
                }
            }
        }
        return $output;
    }
Ejemplo n.º 2
0
 private function _migrateProduct($data)
 {
     // Check for product_name.
     if (!empty($data->product_name)) {
         $isNew = false;
         if (!empty($data->product_id)) {
             if ((int) $data->product_id) {
                 $data['product_id'] = 0;
                 $isNew = true;
             }
         }
         JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_tienda' . DS . 'tables');
         $product = JTable::getInstance('Products', 'TiendaTable');
         if (!$isNew) {
             if (!$product->load($data['product_id'])) {
                 $isNew = true;
                 $data['product_id'] = 0;
             }
         }
         // If is a new product, use product->create()
         if ($isNew) {
             $product->product_price = 0;
             $product->product_quantity = 0;
             $product->bind($this->simpleXml2Array($data));
             if ($product->product_full_image) {
                 Tienda::load('TiendaFile', 'library.file');
                 // Do the same cleaning to the image title that the image helper does
                 $name = explode('.', $product->product_full_image);
                 $name = TiendaFile::cleanTitle($name[0]) . '.' . $name[count($name) - 1];
                 $product->product_full_image = $name;
             }
             $product->create();
             $this->_migrateAttributes($product->product_id, $data->product_attributes);
             $this->_migrateCategories($product->product_id, $data->product_categories);
             $this->_migrateFiles($product->product_id, $data->product_files);
             $this->_migrateImages($product->product_id, $data->product_images);
             $this->_migrateChildren($product->product_id, $data->product_children);
             $this->_migrateRelated($product->product_id, $data->related_products);
             $this->_migrateCustomFields($product->product_id, $data->product_custom_fields);
         } else {
             $product->bind($this->simpleXml2Array($data));
             //check if normal price exists
             Tienda::load("TiendaHelperProduct", 'helpers.product');
             $prices = TiendaHelperProduct::getPrices($product->product_id);
             $quantities = TiendaHelperProduct::getProductQuantities($product->product_id);
             if ($product->save()) {
                 $product->product_id = $product->id;
                 // New price?
                 if (empty($prices)) {
                     // set price if new or no prices set
                     $price = JTable::getInstance('Productprices', 'TiendaTable');
                     $price->product_id = $product->id;
                     $price->product_price = (string) $data->product_price;
                     $price->group_id = Tienda::getInstance()->get('default_user_group', '1');
                     $price->save();
                 } else {
                     // set price if new or no prices set
                     $price = JTable::getInstance('Productprices', 'TiendaTable');
                     $price->load($prices[0]->product_price_id);
                     $price->product_price = (string) $data->product_price;
                     $price->group_id = Tienda::getInstance()->get('default_user_group', '1');
                     $price->save();
                 }
                 // New quantity?
                 if (empty($quantities)) {
                     // save default quantity
                     $quantity = JTable::getInstance('Productquantities', 'TiendaTable');
                     $quantity->product_id = $product->id;
                     $quantity->quantity = (string) $data->product_quantity;
                     $quantity->save();
                 } else {
                     // save default quantity
                     $quantity = JTable::getInstance('Productquantities', 'TiendaTable');
                     $quantity->load($quantities[0]->productquantity_id);
                     $quantity->product_id = $product->id;
                     $quantity->quantity = (string) $data->product_quantity;
                     $quantity->save();
                 }
             }
         }
         return $product;
     }
     return null;
 }
Ejemplo n.º 3
0
 /**
  * Updates a product and its related informations (price, quantity & categories)
  * The price will be created from the $this->product_price property
  * The quantity will be created from the $this->product_quantity property
  * The categories will be created from the $this->product_category property
  */
 function update()
 {
     // If this product is already stored, we shouldn't create the product!
     if (!$this->product_id) {
         $this->setError(JText::_('COM_TIENDA_YOU_CANNOT_UPDATE_A_NON_EXISTING_PRODUCT'));
         return false;
     }
     $product_price = @$this->product_price;
     $product_quantity = @$this->product_quantity;
     $product_categories = @$this->product_category;
     if (!is_array($product_categories)) {
         $product_categories = array($product_categories);
     }
     unset($this->product_price);
     unset($this->product_quantity);
     unset($this->product_category);
     // Save the product First
     $success = $this->save();
     if ($success) {
         // now the price
         if ($product_price) {
             // Load the default price
             Tienda::load('TiendaHelperProduct', 'helpers.product');
             $prices = TiendaHelperProduct::getPrices($this->product_id);
             if (count($prices)) {
                 $price_id = $prices[0]->product_price_id;
             } else {
                 $price_id = 0;
             }
             Tienda::load('TiendaTableProductPrices', 'tables.productprices');
             $price = JTable::getInstance('ProductPrices', 'TiendaTable');
             // load the price if it does exist
             if ($price_id) {
                 $price->load($price_id);
             }
             // else just save it as a new price
             $price->product_id = $this->product_id;
             $price->product_price = $product_price;
             $price->group_id = Tienda::getInstance()->get('default_user_group', '1');
             $success = $price->save();
             if (!$success) {
                 $this->setError($price->getError());
                 return false;
             }
         }
         // now the quantities
         if ($product_quantity) {
             // Load the default quantity
             Tienda::load('TiendaHelperProduct', 'helpers.product');
             $quantities = TiendaHelperProduct::getProductQuantities($this->product_id);
             if (count($quantities)) {
                 $quantity_id = $quantities[0]->productquantity_id;
             } else {
                 $quantity_id = 0;
             }
             Tienda::load('TiendaTableProductQuantities', 'tables.productquantities');
             $quantity = JTable::getInstance('ProductQuantities', 'TiendaTable');
             // load the quantity if it does exist
             if ($quantity_id) {
                 $quantity->load($quantity_id);
             }
             // else just save it as a new quantity
             $quantity->product_id = $this->product_id;
             $quantity->quantity = $product_quantity;
             $success = $quantity->save();
             if (!$success) {
                 $this->setError($quantity->getError());
                 return false;
             }
         }
         // now the categories
         if ($product_categories) {
             foreach ($product_categories as $product_category) {
                 // This is probably not the best way to do it
                 // Numeric = id, string = category name
                 if (!is_numeric($product_category)) {
                     // check for existance
                     JModel::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_tienda' . DS . 'models');
                     $model = JModel::getInstance('Categories', 'TiendaModel');
                     $model->setState('filter_name', $product_category);
                     $matches = $model->getList();
                     $matched = false;
                     if ($matches) {
                         foreach ($matches as $match) {
                             // is a perfect match?
                             if (strtolower($product_category) == strtolower($match->category_name)) {
                                 $product_category = $match->category_id;
                                 $matched = true;
                             }
                         }
                     }
                     // Not matched, create category
                     if (!$matched) {
                         Tienda::load('TiendaTableCategories', 'tables.categories');
                         $category = JTable::getInstance('Categories', 'TiendaTable');
                         $category->category_name = $product_category;
                         $category->parent_id = 1;
                         $category->category_enabled = 1;
                         $category->save();
                         $product_category = $category->category_id;
                     }
                 }
                 // save xref in every case
                 Tienda::load('TiendaTableProductCategories', 'tables.productcategories');
                 $xref = JTable::getInstance('ProductCategories', 'TiendaTable');
                 $xref->product_id = $this->product_id;
                 $xref->category_id = $product_category;
                 $xref->save();
             }
         }
     } else {
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Do the migration
  *
  * @return array
  */
 function _migrate($datas)
 {
     $queries = array();
     $results = array();
     $n = 0;
     // Loop though the rows
     foreach ($datas as $data) {
         // Check for product_name. Explode() could have generated an empty row
         if (!empty($data['product_name'])) {
             $isNew = false;
             if (!$data['product_id']) {
                 $data['product_id'] = 0;
                 $isNew = true;
             }
             JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_tienda' . DS . 'tables');
             $product = JTable::getInstance('Products', 'TiendaTable');
             if (!$isNew) {
                 if (!$product->load($data['product_id'])) {
                     $isNew = true;
                     $data['product_id'] = 0;
                 }
             }
             // If is a new product, use product->create()
             if ($isNew) {
                 $product->product_price = 0;
                 $product->product_quantity = 0;
                 $product->bind($data);
                 if ($product->product_full_image) {
                     Tienda::load('TiendaFile', 'library.file');
                     // Do the same cleaning to the image title that the image helper does
                     $name = explode('.', $product->product_full_image);
                     $name = TiendaFile::cleanTitle($name[0]) . '.' . $name[count($name) - 1];
                     $product->product_full_image = $name;
                 }
                 $product->create();
                 $this->_migrateAttributes($product->product_id, $data['product_attributes']);
             } else {
                 $product->bind($data);
                 //check if normal price exists
                 Tienda::load("TiendaHelperProduct", 'helpers.product');
                 $prices = TiendaHelperProduct::getPrices($product->product_id);
                 $quantities = TiendaHelperProduct::getProductQuantities($product->product_id);
                 if ($product->save()) {
                     $product->product_id = $product->id;
                     // New price?
                     if (empty($prices)) {
                         // set price if new or no prices set
                         $price = JTable::getInstance('Productprices', 'TiendaTable');
                         $price->product_id = $product->id;
                         $price->product_price = $data['product_price'];
                         $price->group_id = Tienda::getInstance()->get('default_user_group', '1');
                         $price->save();
                     } else {
                         // set price if new or no prices set
                         $price = JTable::getInstance('Productprices', 'TiendaTable');
                         $price->load($prices[0]->product_price_id);
                         $price->product_price = $data['product_price'];
                         $price->group_id = Tienda::getInstance()->get('default_user_group', '1');
                         $price->save();
                     }
                     // New quantity?
                     if (empty($quantities)) {
                         // save default quantity
                         $quantity = JTable::getInstance('Productquantities', 'TiendaTable');
                         $quantity->product_id = $product->id;
                         $quantity->quantity = $data['product_quantity'];
                         $quantity->save();
                     } else {
                         // save default quantity
                         $quantity = JTable::getInstance('Productquantities', 'TiendaTable');
                         $quantity->load($quantities[0]->productquantity_id);
                         $quantity->product_id = $product->id;
                         $quantity->quantity = $data['product_quantity'];
                         $quantity->save();
                     }
                 }
             }
             // at this point, the product is saved, so now do additional relationships
             // such as categories
             if (!empty($product->product_id) && !empty($data['product_categories'])) {
                 foreach ($data['product_categories'] as $category_id) {
                     // This is probably not the best way to do it
                     // Numeric = id, string = category name
                     if (!is_numeric($category_id)) {
                         // check for existance
                         JModel::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_tienda' . DS . 'models');
                         $model = JModel::getInstance('Categories', 'TiendaModel');
                         $model->setState('filter_name', $category_id);
                         $matches = $model->getList();
                         $matched = false;
                         if ($matches) {
                             foreach ($matches as $match) {
                                 // is a perfect match?
                                 if (strtolower($category_id) == strtolower($match->category_name)) {
                                     $category_id = $match->category_id;
                                     $matched = true;
                                 }
                             }
                         }
                         // Not matched, create category
                         if (!$matched) {
                             $category = JTable::getInstance('Categories', 'TiendaTable');
                             $category->category_name = $category_id;
                             $category->parent_id = 1;
                             $category->category_enabled = 1;
                             $category->save();
                             $category_id = $category->category_id;
                         }
                     }
                     // save xref in every case
                     $xref = JTable::getInstance('ProductCategories', 'TiendaTable');
                     $xref->product_id = $product->product_id;
                     $xref->category_id = $category_id;
                     $xref->save();
                 }
             }
             $results[$n]->title = $product->product_name;
             $results[$n]->query = "";
             $results[$n]->error = implode('\\n', $product->getErrors());
             $results[$n]->affectedRows = 1;
             $n++;
             $this->_migrateImages($product->product_id, $data['product_images'], $results);
         }
     }
     return $results;
 }
Ejemplo n.º 5
0
        <table class="table table-striped table-bordered">
            <tr>
                <td class="dsc-key"><?php 
echo JText::_('COM_TIENDA_ITEM_FOR_SALE');
?>
                </td>
                <td>
                <?php 
//swapping yes and no because  this is a NOT for SALE so the logic is in reverse.
echo TiendaSelect::btbooleanlist('product_notforsale', '', @$row->product_notforsale, 'JNO', 'JYES');
?>
                </td>
            </tr>
            <?php 
$prices = $helper_product->getPrices($row->product_id);
if (empty($row->product_id) || empty($prices)) {
    // new product (or no prices set) - ask for normal price
    ?>
            <tr>
                <td class="dsc-key"><?php 
    echo JText::_('COM_TIENDA_NORMAL_PRICE');
    ?>
:
                </td>
                <td><input type="text" name="product_price" id="product_price" value="<?php 
    echo @$row->product_price;
    ?>
" size="25" maxlength="25" />
                    <div class="note well">
                        <?php 
Ejemplo n.º 6
0
 /**
  * Saves an item and redirects based on task
  * @return void
  */
 function save()
 {
     $task = JRequest::getVar('task');
     $model = $this->getModel($this->get('suffix'));
     $isSaveAs = false;
     $row = $model->getTable();
     $row->load($model->getId());
     $row->bind(JRequest::get('POST'));
     $row->product_description = JRequest::getVar('product_description', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $row->product_description_short = JRequest::getVar('product_description_short', '', 'post', 'string', JREQUEST_ALLOWRAW);
     // set the id as 0 for new entry
     if ($task == "save_as") {
         unset($row);
         // load WITHOUT EAV! otherwise the save will fail
         $row = $model->getTable();
         $row->load($model->getId(), true, false);
         $row->bind(JRequest::get('POST'));
         $row->product_description = JRequest::getVar('product_description', '', 'post', 'string', JREQUEST_ALLOWRAW);
         $row->product_description_short = JRequest::getVar('product_description_short', '', 'post', 'string', JREQUEST_ALLOWRAW);
         $isSaveAs = true;
         $oldProductImagePath = $row->getImagePath();
         $pk = $row->getKeyName();
         $oldPk = $row->{$pk};
         // these get reset
         $row->{$pk} = 0;
         $row->product_images_path = '';
         $row->product_rating = '';
         $row->product_comments = '';
     }
     $row->_isNew = empty($row->product_id);
     $fieldname = 'product_full_image_new';
     $userfiles = JRequest::getVar($fieldname, '', 'files', 'array');
     // save the integrations
     $row = $this->prepareParameters($row);
     //check if normal price exists
     Tienda::load("TiendaHelperProduct", 'helpers.product');
     if ($isSaveAs) {
         // and the prices
         $prices = TiendaHelperProduct::getPrices($oldPk);
     } else {
         $prices = TiendaHelperProduct::getPrices($row->product_id);
     }
     if ($row->save()) {
         $row->product_id = $row->id;
         $model->setId($row->id);
         $this->messagetype = 'message';
         $this->message = JText::_('COM_TIENDA_SAVED');
         // check it's new entry or empty price but not save as
         if (($row->_isNew || empty($prices)) && !$isSaveAs) {
             // set price if new or no prices set
             $price = JTable::getInstance('Productprices', 'TiendaTable');
             $price->product_id = $row->id;
             $price->product_price = JRequest::getVar('product_price');
             $price->group_id = Tienda::getInstance()->get('default_user_group', '1');
             if (!$price->save()) {
                 $this->messagetype = 'notice';
                 $this->message .= " :: " . $price->getError();
             }
         }
         if ($row->_isNew && !$isSaveAs) {
             // set category
             $category = JTable::getInstance('Productcategories', 'TiendaTable');
             $category->product_id = $row->id;
             $category->category_id = JRequest::getVar('category_id');
             if (!$category->save()) {
                 $this->messagetype = 'notice';
                 $this->message .= " :: " . $category->getError();
             }
             // save default quantity
             $quantity = JTable::getInstance('Productquantities', 'TiendaTable');
             $quantity->product_id = $row->id;
             $quantity->quantity = JRequest::getInt('product_quantity');
             if (!$quantity->save()) {
                 $this->messagetype = 'notice';
                 $this->message .= " :: " . $quantity->getError();
             }
         }
         if ($isSaveAs) {
             // set price when cloning
             $priceTable = JTable::getInstance('Productprices', 'TiendaTable');
             foreach ($prices as $price) {
                 $priceTable->product_id = $row->id;
                 $priceTable->product_price = $price->product_price;
                 $priceTable->product_price_startdate = $price->product_price_startdate;
                 $priceTable->product_price_enddate = $price->product_price_enddate;
                 $priceTable->created_date = $price->created_date;
                 $priceTable->modified_date = $price->modified_date;
                 $priceTable->group_id = $price->group_id;
                 $priceTable->price_quantity_start = $price->price_quantity_start;
                 $priceTable->price_quantity_end = $price->price_quantity_end;
                 if (!$priceTable->save()) {
                     $this->messagetype = 'notice';
                     $this->message .= " :: " . $priceTable->getError();
                 }
             }
             // set category
             $categoryTable = JTable::getInstance('Productcategories', 'TiendaTable');
             $categories = TiendaHelperProduct::getCategories($oldPk);
             foreach ($categories as $category) {
                 $categoryTable->product_id = $row->id;
                 $categoryTable->category_id = $category;
                 if (!$categoryTable->save()) {
                     $this->messagetype = 'notice';
                     $this->message .= " :: " . $categoryTable->getError();
                 }
             }
             // TODO Save Attributes
             // An array to map attribute id  old attribute id  are as key and new attribute id are as value
             $attrbuteMappingArray = array();
             $attrbuteParentMappingArray = array();
             $attributes = TiendaHelperProduct::getAttributes($oldPk);
             foreach ($attributes as $attribute) {
                 $attributeTable = JTable::getInstance('ProductAttributes', 'TiendaTable');
                 $attributeTable->productattribute_name = $attribute->productattribute_name;
                 $attributeTable->product_id = $row->id;
                 $attributeTable->ordering = $attribute->ordering;
                 if ($attributeTable->save()) {
                     $attrbuteMappingArray[$attribute->productattribute_id] = $attributeTable->productattribute_id;
                     $attrbuteParentMappingArray[$attributeTable->productattribute_id] = $attribute->parent_productattributeoption_id;
                 } else {
                     $this->messagetype = 'notice';
                     $this->message .= " :: " . $attributeTable->getError();
                 }
             }
             // set Attribute options
             $attrbuteOptionsMappingArray = array();
             foreach ($attrbuteMappingArray as $oldAttrbuteId => $newAttributeId) {
                 // set Attribute options
                 $options = TiendaHelperProduct::getAttributeOptionsObjects($oldAttrbuteId);
                 foreach ($options as $option) {
                     $attributeOptionsTable = JTable::getInstance('ProductAttributeOptions', 'TiendaTable');
                     $attributeOptionsTable->productattribute_id = $newAttributeId;
                     $attributeOptionsTable->productattributeoption_name = $option->productattributeoption_name;
                     $attributeOptionsTable->productattributeoption_price = $option->productattributeoption_price;
                     $attributeOptionsTable->productattributeoption_prefix = $option->productattributeoption_prefix;
                     $attributeOptionsTable->productattributeoption_code = $option->productattributeoption_code;
                     $attributeOptionsTable->ordering = $option->ordering;
                     if ($attributeOptionsTable->save()) {
                         $attrbuteOptionsMappingArray[$option->productattributeoption_id] = $attributeOptionsTable->productattributeoption_id;
                     } else {
                         $this->messagetype = 'notice';
                         $this->message .= " :: " . $attributeOptionsTable->getError();
                     }
                 }
                 // save parent relationship
                 if ($attrbuteParentMappingArray[$newAttributeId]) {
                     $attributeTable = JTable::getInstance('ProductAttributes', 'TiendaTable');
                     $attributeTable->load($newAttributeId);
                     $attributeTable->parent_productattributeoption_id = $attrbuteOptionsMappingArray[$attrbuteParentMappingArray[$newAttributeId]];
                     if (!$attributeTable->save()) {
                         $this->messagetype = 'notice';
                         $this->message .= " :: " . $attributeTable->getError();
                     }
                 }
             }
             // set quantity
             $quantityTable = JTable::getInstance('Productquantities', 'TiendaTable');
             $quantities = TiendaHelperProduct::getProductQuantitiesObjects($oldPk);
             foreach ($quantities as $quantity) {
                 $quantityTable->product_attributes = $quantity->product_attributes;
                 $quantityTable->product_id = $row->id;
                 $quantityTable->vendor_id = $quantity->vendor_id;
                 $quantityTable->quantity = $quantity->quantity;
                 $optionsCSV = $quantity->product_attributes;
                 $options = explode(",", $optionsCSV);
                 $newOptions = array();
                 foreach ($options as $option) {
                     $newOptions[] = $attrbuteOptionsMappingArray[$option];
                 }
                 $optionsCSV = implode(",", $newOptions);
                 $quantityTable->product_attributes = $optionsCSV;
                 if (!$quantityTable->save()) {
                     $this->messagetype = 'notice';
                     $this->message .= " :: " . $quantityTable->getError();
                 }
             }
             // copy all gallery files
             jimport('joomla.filesystem.folder');
             jimport('joomla.filesystem.file');
             $galleryFiles = JFolder::files($oldProductImagePath);
             // get all gallery images
             if (count($galleryFiles)) {
                 JFolder::create($row->getImagePath());
                 // create folder for images
                 JFolder::create($row->getImagePath() . 'thumbs');
                 // create folder for thumbnails images
                 for ($i = 0, $c = count($galleryFiles); $i < $c; $i++) {
                     // copy only images with both original file and a corresponding thumbnail
                     if (JFile::exists($oldProductImagePath . 'thumbs/' . $galleryFiles[$i]) && JFile::exists($oldProductImagePath . $galleryFiles[$i])) {
                         JFile::copy($oldProductImagePath . $galleryFiles[$i], $row->getImagePath() . DS . $galleryFiles[$i]);
                         JFile::copy($oldProductImagePath . 'thumbs/' . $galleryFiles[$i], $row->getImagePath() . '/thumbs/' . $galleryFiles[$i]);
                     }
                 }
             }
             // duplicate product files (only in db)
             $modelFiles = $this->getModel('productfiles');
             $modelFiles->setState('filter_product', $oldPk);
             $listFiles = $modelFiles->getList();
             if (count($listFiles)) {
                 $row_file = JTable::getInstance('Productfiles', 'TiendaTable');
                 for ($i = 0, $c = count($listFiles); $i < $c; $i++) {
                     $row_file->bind($listFiles[$i]);
                     // bind old data
                     $row_file->productfile_id = 0;
                     // will be set
                     $row_file->product_id = $row->product_id;
                     // use clone's ID
                     $row_file->save();
                     // save the data
                 }
             }
             // create duplicate connections for EAV custom fields
             JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
             $model = JModel::getInstance('EavAttributes', 'TiendaModel');
             $model->setState('filter_entitytype', 'products');
             $model->setState('filter_entityid', $oldPk);
             $listEAV = $model->getList();
             $teav = $model->getTable();
             if (is_array($listEAV)) {
                 for ($i = 0, $c = count($listEAV); $i < $c; $i++) {
                     $tblEAV = JTable::getInstance('EavAttributeEntities', 'TiendaTable');
                     $tblEAV->eaventity_id = $row->product_id;
                     $tblEAV->eaventity_type = 'products';
                     $tblEAV->eavattribute_id = $listEAV[$i]->eavattribute_id;
                     $tblEAV->save();
                     // Clone the values too!
                     $teav->load($listEAV[$i]->eavattribute_id);
                     $value = TiendaHelperEav::getAttributeValue($teav, 'products', $row->product_id);
                     $newValue = JTable::getInstance('EavValues', 'TiendaTable');
                     $newValue->setType($teav->eavattribute_type);
                     $newValue->eavattribute_id = $listEAV[$i]->eavattribute_id;
                     $newValue->eaventity_id = $row->product_id;
                     // Store the value
                     $newValue->eavvalue_value = $value;
                     $newValue->eaventity_type = 'products';
                     $newValue->store();
                 }
             }
         }
         // Multiple images processing
         $i = 0;
         $error = false;
         while (!empty($userfiles['size'][$i])) {
             $dir = $row->getImagePath(true);
             if ($upload = $this->addimage($fieldname, $i, $dir)) {
                 // The first One is the default (if there is no default yet)
                 if ($i == 0 && (empty($row->product_full_image) || $row->product_full_image == '')) {
                     $row->product_full_image = $upload->getPhysicalName();
                     // need to re-save in this instance
                     // should we be storing or saving?
                     $row->save();
                 }
             } else {
                 $error = true;
             }
             $i++;
         }
         if ($error) {
             $this->messagetype = 'notice';
             $this->message .= " :: " . $this->getError();
         }
         $helper = new TiendaHelperProduct();
         $helper->onAfterSaveProducts($row);
         $model->clearCache();
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onAfterSave' . $this->get('suffix'), array($row));
     } else {
         $this->messagetype = 'notice';
         $this->message = JText::_('COM_TIENDA_SAVE_FAILED') . " - " . $row->getError();
     }
     $redirect = "index.php?option=com_tienda";
     switch ($task) {
         case "save_as":
             $redirect .= '&view=' . $this->get('suffix') . '&task=edit&id=' . $row->product_id;
             $this->message .= " - " . JText::_('COM_TIENDA_YOU_ARE_NOW_EDITING_NEW_PRODUCT');
             break;
         case "saveprev":
             $redirect .= '&view=' . $this->get('suffix');
             // get prev in list
             Tienda::load("TiendaHelperProduct", 'helpers.product');
             $surrounding = TiendaHelperProduct::getSurrounding($model->getId());
             if (!empty($surrounding['prev'])) {
                 $redirect .= '&task=edit&id=' . $surrounding['prev'];
             }
             break;
         case "savenext":
             $redirect .= '&view=' . $this->get('suffix');
             // get next in list
             Tienda::load("TiendaHelperProduct", 'helpers.product');
             $surrounding = TiendaHelperProduct::getSurrounding($model->getId());
             if (!empty($surrounding['next'])) {
                 $redirect .= '&task=edit&id=' . $surrounding['next'];
             }
             break;
         case "savenew":
             $redirect .= '&view=' . $this->get('suffix') . '&task=add';
             break;
         case "apply":
             $redirect .= '&view=' . $this->get('suffix') . '&task=edit&id=' . $model->getId();
             break;
         case "save":
         default:
             $redirect .= "&view=" . $this->get('suffix');
             break;
     }
     $redirect = JRoute::_($redirect, false);
     $this->setRedirect($redirect, $this->message, $this->messagetype);
 }