@@ -724,7 +724,6 @@ public function ajaxProcessAddAttachment()
724
724
}
725
725
}
726
726
727
-
728
727
/**
729
728
* Attach an existing attachment to the product
730
729
*
@@ -758,17 +757,63 @@ public function processDuplicate()
758
757
unset($ product ->id_product );
759
758
$ product ->indexed = 0 ;
760
759
$ product ->active = 0 ;
760
+
761
+ // suffix 'Duplicate' if same hotel
762
+ $ id_hotel_new = Tools::getValue ('id_hotel ' );
763
+ $ obj_hotel_room_type = new HotelRoomType ();
764
+ $ room_type_info = $ obj_hotel_room_type ->getRoomTypeInfoByIdProduct ($ id_product_old );
765
+ if ($ room_type_info && $ room_type_info ['id_hotel ' ] == $ id_hotel_new ) {
766
+ foreach (Language::getLanguages (true ) as $ language ) {
767
+ $ product ->name [$ language ['id_lang ' ]] = $ product ->name [$ language ['id_lang ' ]].
768
+ ' - ' .$ this ->l ('Duplicate ' );
769
+ }
770
+ }
771
+
772
+ // update lang fields
773
+ foreach (Language::getLanguages (true ) as $ language ) {
774
+ $ product ->link_rewrite [$ language ['id_lang ' ]] = Tools::str2url ($ product ->name [$ language ['id_lang ' ]]);
775
+ }
761
776
if ($ product ->add ()
762
- && Category::duplicateProductCategories ($ id_product_old , $ product ->id )
763
- && Product::duplicateSuppliers ($ id_product_old , $ product ->id )
764
- && ($ combination_images = Product::duplicateAttributes ($ id_product_old , $ product ->id )) !== false
765
- && GroupReduction::duplicateReduction ($ id_product_old , $ product ->id )
766
- && Product::duplicateAccessories ($ id_product_old , $ product ->id )
767
- && Product::duplicateFeatures ($ id_product_old , $ product ->id )
768
- && Pack::duplicate ($ id_product_old , $ product ->id )
769
- && Product::duplicateCustomizationFields ($ id_product_old , $ product ->id )
770
- && Product::duplicateTags ($ id_product_old , $ product ->id )
771
- && Product::duplicateDownload ($ id_product_old , $ product ->id )) {
777
+ // && Category::duplicateProductCategories($id_product_old, $product->id)
778
+ && Product::duplicateSuppliers ($ id_product_old , $ product ->id )
779
+ && ($ combination_images = Product::duplicateAttributes ($ id_product_old , $ product ->id )) !== false
780
+ && GroupReduction::duplicateReduction ($ id_product_old , $ product ->id )
781
+ && Product::duplicateAccessories ($ id_product_old , $ product ->id )
782
+ && Product::duplicateFeatures ($ id_product_old , $ product ->id )
783
+ && Pack::duplicate ($ id_product_old , $ product ->id )
784
+ && Product::duplicateCustomizationFields ($ id_product_old , $ product ->id )
785
+ && Product::duplicateTags ($ id_product_old , $ product ->id )
786
+ && Product::duplicateDownload ($ id_product_old , $ product ->id )
787
+ ) {
788
+ $ obj_hotel_room_type = new HotelRoomType ();
789
+ $ room_type_info = $ obj_hotel_room_type ->getRoomTypeInfoByIdProduct ($ id_product_old );
790
+ $ id_room_type_old = $ room_type_info ['id ' ];
791
+ if (!$ id_hotel_new ) {
792
+ $ id_hotel_new = $ room_type_info ['id_hotel ' ];
793
+ }
794
+ $ id_room_type_new = HotelRoomType::duplicateRoomType (
795
+ $ id_product_old ,
796
+ $ product ->id ,
797
+ $ id_hotel_new ,
798
+ true
799
+ );
800
+ if ($ id_room_type_new ) {
801
+ if (!HotelRoomType::duplicateRooms (
802
+ $ id_product_old ,
803
+ $ id_room_type_new ,
804
+ $ product ->id ,
805
+ $ id_hotel_new
806
+ )) {
807
+ $ this ->errors [] = Tools::displayError ('An error occurred while duplicating rooms. ' );
808
+ }
809
+ if (!HotelRoomTypeDemand::duplicateRoomTypeDemands ($ id_product_old , $ product ->id )) {
810
+ $ this ->errors [] = Tools::displayError (
811
+ 'An error occurred while duplicating additional facilities. '
812
+ );
813
+ }
814
+ } else {
815
+ $ this ->errors [] = Tools::displayError ('An error occurred while duplicating room type. ' );
816
+ }
772
817
if ($ product ->hasAttributes ()) {
773
818
Product::updateDefaultAttribute ($ product ->id );
774
819
} else {
@@ -1540,6 +1585,10 @@ public function postProcess()
1540
1585
parent ::postProcess ();
1541
1586
}
1542
1587
1588
+ $ this ->addJS (array (
1589
+ _PS_JS_DIR_ .'admin/products.js ' ,
1590
+ ));
1591
+
1543
1592
if ($ this ->display == 'edit ' || $ this ->display == 'add ' ) {
1544
1593
$ this ->addJqueryUI (array (
1545
1594
'ui.core ' ,
@@ -1558,7 +1607,6 @@ public function postProcess()
1558
1607
));
1559
1608
1560
1609
$ this ->addJS (array (
1561
- _PS_JS_DIR_ .'admin/products.js ' ,
1562
1610
_PS_JS_DIR_ .'admin/attributes.js ' ,
1563
1611
_PS_JS_DIR_ .'admin/price.js ' ,
1564
1612
_PS_JS_DIR_ .'tiny_mce/tiny_mce.js ' ,
@@ -2734,6 +2782,12 @@ public function renderList()
2734
2782
return parent ::renderList ();
2735
2783
}
2736
2784
2785
+ public function displayDuplicateLink ($ token = null , $ id , $ name = null )
2786
+ {
2787
+ return '<a href="#" title=" ' .$ this ->l ('Duplicate ' ).'"
2788
+ onclick="initDuplicateRoomType( ' .(int )$ id .');return false;"><i class="icon-copy"></i> ' .$ this ->l ('Duplicate ' ).'</a> ' ;
2789
+ }
2790
+
2737
2791
public function ajaxProcessProductManufacturers ()
2738
2792
{
2739
2793
$ manufacturers = Manufacturer::getManufacturers (false , 0 , true , false , false , false , true );
@@ -2843,10 +2897,7 @@ public function initPageHeaderToolbar()
2843
2897
);
2844
2898
}
2845
2899
2846
- $ js = (bool )Image::getImages ($ this ->context ->language ->id , (int )$ product ->id ) ?
2847
- 'confirm_link( \'\', \'' .$ this ->l ('This will copy the images too. If you wish to proceed, click "Yes". If not, click "No". ' , null , true , false ).'\', \'' .$ this ->l ('Yes ' , null , true , false ).'\', \'' .$ this ->l ('No ' , null , true , false ).'\', \'' .$ this ->context ->link ->getAdminLink ('AdminProducts ' , true ).'&id_product= ' .(int )$ product ->id .'&duplicateproduct ' .'\', \'' .$ this ->context ->link ->getAdminLink ('AdminProducts ' , true ).'&id_product= ' .(int )$ product ->id .'&duplicateproduct&noimage=1 ' .'\') '
2848
- :
2849
- 'document.location = \'' .$ this ->context ->link ->getAdminLink ('AdminProducts ' , true ).'&id_product= ' .(int )$ product ->id .'&duplicateproduct&noimage=1 ' .'\'' ;
2900
+ $ js = 'initDuplicateRoomType( ' .(int )$ product ->id .');return false; ' ;
2850
2901
2851
2902
// adding button for duplicate this product
2852
2903
if ($ this ->tabAccess ['add ' ]) {
@@ -2882,6 +2933,12 @@ public function initPageHeaderToolbar()
2882
2933
parent ::initPageHeaderToolbar ();
2883
2934
}
2884
2935
2936
+ public function initModal ()
2937
+ {
2938
+ parent ::initModal ();
2939
+ $ this ->modals [] = $ this ->getModalDuplicateOptions ();
2940
+ }
2941
+
2885
2942
public function initToolbar ()
2886
2943
{
2887
2944
parent ::initToolbar ();
@@ -5427,6 +5484,50 @@ public function initFormFeatures($obj)
5427
5484
}
5428
5485
$ this ->tpl_form_vars ['custom_form ' ] = $ data ->fetch ();
5429
5486
}
5487
+
5488
+ public function getModalDuplicateOptions ()
5489
+ {
5490
+ $ tpl = $ this ->createTemplate ('modal-duplicate-options.tpl ' );
5491
+ $ idsHotel = HotelBranchInformation::getProfileAccessedHotels ($ this ->context ->employee ->id_profile , 1 , 1 );
5492
+ $ hotelsInfo = array ();
5493
+ foreach ($ idsHotel as $ idHotel ) {
5494
+ $ objHotelBranchInfo = new HotelBranchInformation ($ idHotel , $ this ->context ->language ->id );
5495
+ if (Validate::isLoadedObject ($ objHotelBranchInfo )) {
5496
+ $ hotelInfo = array (
5497
+ 'id_hotel ' => $ objHotelBranchInfo ->id ,
5498
+ 'hotel_name ' => $ objHotelBranchInfo ->hotel_name ,
5499
+ 'rating ' => $ objHotelBranchInfo ->rating ,
5500
+ 'city ' => $ objHotelBranchInfo ->city ,
5501
+ );
5502
+ $ hotelsInfo [] = $ hotelInfo ;
5503
+ }
5504
+ }
5505
+ $ formAction = $ this ->context ->link ->getAdminLink ('AdminProducts ' , true ).'&duplicateproduct ' ;
5506
+ $ tpl ->assign (array (
5507
+ 'action ' => $ formAction ,
5508
+ 'hotels_info ' => $ hotelsInfo ,
5509
+ 'duplicate_images ' => 1 ,
5510
+ ));
5511
+
5512
+ $ modalActions = array (
5513
+ array (
5514
+ 'type ' => 'button ' ,
5515
+ 'value ' => 'submitDuplicate ' ,
5516
+ 'class ' => 'btn-primary submit-duplicate ' ,
5517
+ 'label ' => $ this ->l ('Submit ' ),
5518
+ ),
5519
+ );
5520
+
5521
+ // set modal options
5522
+ $ modal = array (
5523
+ 'modal_id ' => 'modal-duplicate-options ' ,
5524
+ 'modal_class ' => 'modal-md ' ,
5525
+ 'modal_title ' => $ this ->l ('Duplication options ' ),
5526
+ 'modal_content ' => $ tpl ->fetch (),
5527
+ 'modal_actions ' => $ modalActions ,
5528
+ );
5529
+ return $ modal ;
5530
+ }
5430
5531
5431
5532
public function ajaxProcessProductQuantity ()
5432
5533
{
@@ -5746,6 +5847,19 @@ public function ajaxProcessPublishProduct()
5746
5847
}
5747
5848
}
5748
5849
5850
+ public function ajaxProcessGetIdHotelByIdProduct ()
5851
+ {
5852
+ $ response = array ('status ' => 'failed ' );
5853
+ $ idProduct = Tools::getValue ('id_product ' );
5854
+ $ objHotelRoomType = new HotelRoomType ();
5855
+ $ roomTypeInfo = $ objHotelRoomType ->getRoomTypeInfoByIdProduct ($ idProduct );
5856
+ if ($ roomTypeInfo ) {
5857
+ $ response ['status ' ] = 'success ' ;
5858
+ $ response ['id_hotel ' ] = (int )$ roomTypeInfo ['id_hotel ' ];
5859
+ }
5860
+ die (json_encode ($ response ));
5861
+ }
5862
+
5749
5863
public function processImageLegends ()
5750
5864
{
5751
5865
if (Tools::getValue ('key_tab ' ) == 'Images ' && Tools::getValue ('submitAddproductAndStay ' ) == 'update_legends ' && Validate::isLoadedObject ($ product = new Product ((int )Tools::getValue ('id_product ' )))) {
0 commit comments