Example #1
0
 /**
  * Supprime un produit (et tout ce qui lui est relatif)
  * @param oledrion_products $product
  */
 function deleteProduct(oledrion_products $product)
 {
     global $xoopsModule;
     $id = $product->getVar('product_id');
     // On commence par supprimer les commentaires
     $mid = $xoopsModule->getVar('mid');
     xoops_comment_delete($mid, $id);
     // Puis les votes
     $this->handlers->h_oledrion_votedata->deleteProductRatings($id);
     // Puis les produits relatifs
     $this->handlers->h_oledrion_related->deleteProductRelatedProducts($id);
     // Les images (la grande et la miniature)
     $product->deletePictures();
     // Le fichier attaché
     $product->deleteAttachment();
     // Les fichiers attachés
     $this->handlers->h_oledrion_files->deleteProductFiles($id);
     // Suppression dans les paniers persistants enregistrés
     $this->handlers->h_oledrion_persistent_cart->deleteProductForAllCarts($id);
     // Les attributs qui lui sont rattachés
     $this->handlers->h_oledrion_attributes->deleteProductAttributes($id);
     // Le produit dans les listes
     $this->handlers->h_oledrion_products_list->deleteProductFromLists($id);
     // La relation entre le produit et le fabricant
     $this->handlers->h_oledrion_productsmanu->removeManufacturerProduct($id);
     // Le produit dans les remises
     $this->handlers->h_oledrion_discounts->removeProductFromDiscounts($id);
     // Et le produit en lui même, à la fin
     return $this->handlers->h_oledrion_products->delete($product, true);
 }
 /**
  * Retourne le nom des champs (représentant les attributs) obligatoires que l'on devrait trouver suite à une sélection de produit
  *
  * @param oledrion_products $product
  * @return array	objets des type oledrion_attributes
  */
 function getProductMandatoryFieldsList(oledrion_products $product)
 {
     $criteria = new CriteriaCompo();
     $criteria->add(new Criteria('attribute_product_id', $product->getVar('attribute_product_id'), '='));
     $criteria->add(new Criteria('attribute_mandatory', 1, '='));
     return $this->getObjects($criteria);
 }
Example #3
0
 /**
  * Clone d'un produit
  *
  * @param  object $originalProduct Le produit à cloner
  * @return mixed  Soit l'objet représentant le nouveau produit soit false
  */
 public function cloneProduct(oledrion_products $originalProduct)
 {
     global $h_oledrion_productsmanu, $h_oledrion_files, $h_oledrion_productsmanu, $h_oledrion_related, $oledrion_handlers;
     $newProduct = $originalProduct->xoopsClone();
     if (OLEDRION_DUPLICATED_PLACE == 'right') {
         $newProduct->setVar('product_title', $originalProduct->getvar('product_title') . ' ' . _AM_OLEDRION_DUPLICATED);
     } else {
         $newProduct->setVar('product_title', _AM_OLEDRION_DUPLICATED . ' ' . $originalProduct->getvar('product_title'));
     }
     $newProduct->setVar('product_id', 0);
     $newProduct->setNew();
     // Copie des 2 images
     if (xoops_trim($originalProduct->getVar('product_image_url')) != '') {
         $resCopy = oledrion_utils::duplicateFile(OLEDRION_PICTURES_PATH, $originalProduct->getVar('product_image_url'));
         if ($resCopy !== false) {
             $newProduct->setVar('product_image_url', $resCopy);
         }
     }
     if (xoops_trim($originalProduct->getVar('product_thumb_url')) != '') {
         $resCopy = oledrion_utils::duplicateFile(OLEDRION_PICTURES_PATH, $originalProduct->getVar('product_thumb_url'));
         if ($resCopy !== false) {
             $newProduct->setVar('product_thumb_url', $resCopy);
         }
     }
     // Copie du fichier attaché
     if (xoops_trim($originalProduct->getVar('product_attachment')) != '') {
         $resCopy = oledrion_utils::duplicateFile(OLEDRION_ATTACHED_FILES_PATH, $originalProduct->getVar('product_attachment'));
         if ($resCopy !== false) {
             $newProduct->setVar('product_attachment', $resCopy);
         }
     }
     $res = $this->insert($newProduct, true);
     if ($res) {
         $newProductId = $newProduct->getVar('product_id');
         // Copie des fichiers liés
         if ($h_oledrion_files->getProductFilesCount($originalProduct->product_id) > 0) {
             $attachedFiles = array();
             $attachedFiles = $h_oledrion_files->getProductFiles($originalProduct->product_id);
             if (count($attachedFiles) > 0) {
                 foreach ($attachedFiles as $oneFile) {
                     $newAttachedFile = $oneFile->xoopsClone();
                     $newAttachedFile->setVar('file_product_id', $newProductId);
                     $resCopy = oledrion_utils::duplicateFile(OLEDRION_ATTACHED_FILES_PATH, $oneFile->getVar('file_filename'));
                     if ($resCopy !== false) {
                         $newAttachedFile->setVar('file_filename', $resCopy);
                     }
                     $newAttachedFile->setNew();
                     $h_oledrion_files->insert($newAttachedFile, true);
                 }
             }
         }
         // Copie des fabricants
         $tblTmp = array();
         $criteria = new Criteria('pm_product_id', $originalProduct->getVar('product_id'), '=');
         $tblTmp = $h_oledrion_productsmanu->getObjects($criteria);
         foreach ($tblTmp as $productAuthor) {
             $newProductAuthor = $productAuthor->xoopsClone();
             $newProductAuthor->setVar('pm_product_id', $newProductId);
             $newProductAuthor->setVar('pm_id', 0);
             $newProductAuthor->setNew();
             $h_oledrion_productsmanu->insert($newProductAuthor, true);
         }
         // Copie des produits relatifs
         $tblTmp = array();
         $criteria = new Criteria('related_product_id', $originalProduct->getVar('product_id'), '=');
         $tblTmp = $h_oledrion_related->getObjects($criteria);
         foreach ($tblTmp as $related) {
             $newRelated = $related->xoopsClone();
             $newRelated->setVar('related_product_id', $newProductId);
             $newRelated->setVar('related_id', 0);
             $newRelated->setNew();
             $h_oledrion_related->insert($newRelated, true);
         }
         // Copie des attributs
         if ($oledrion_handlers->h_oledrion_attributes->getProductAttributesCount($originalProduct->product_id) > 0) {
             $criteria = new Criteria('attribute_product_id', $originalProduct->product_id, '=');
             $tblTmp = $oledrion_handlers->h_oledrion_attributes->getObjects($criteria);
             foreach ($tblTmp as $attribute) {
                 $newAttribute = $attribute->xoopsClone();
                 $newAttribute->setVar('attribute_product_id', $newProductId);
                 $newAttribute->setVar('attribute_id', 0);
                 $newAttribute->setNew();
                 $oledrion_handlers->h_oledrion_attributes->insert($newAttribute, true);
             }
         }
         return $newProduct;
     } else {
         return false;
     }
 }
 /**
  * Retourne les informations formatées de l'attribut pour affichage dans la facture
  *
  * @param oledrion_products $product	Le produit concerné par l'attribut
  * @return array
  * @since 2.3.2009.03.23
  */
 function renderForInvoice(oledrion_products $product, $format = 's')
 {
     $names = $prices = $ret = array();
     $names = $this->getOption('ca_attribute_names', $format);
     if (oledrion_utils::getModuleOption('use_price')) {
         $prices = $this->getOption('ca_attribute_prices', $format);
     }
     $oledrion_Currency = oledrion_Currency::getInstance();
     $counter = 0;
     foreach ($names as $name) {
         $price = 0;
         if (oledrion_utils::getModuleOption('use_price')) {
             if (isset($prices[$counter])) {
                 $price = oledrion_utils::getAmountWithVat(floatval($prices[$counter]), $product->getVar('product_vat_id'));
                 $price = $oledrion_Currency->amountForDisplay($price);
             }
         }
         $ret[] = array('ca_attribute_name' => $name, 'ca_attribute_price_formated' => $price);
         $counter++;
     }
     return $ret;
 }