2016-01-04 12:49:26 +01:00
< ? php
if ( ! defined ( '_PS_VERSION_' ))
exit ;
class BulkUpdate extends Module {
function __construct () {
$this -> name = 'bulkupdate' ;
$this -> tab = 'administration' ;
$this -> need_instance = 0 ;
parent :: __construct ();
$this -> displayName = $this -> l ( 'Bulk update' );
$this -> description = $this -> l ( 'Bulk update products.' );
$this -> version = '1.0' ;
$this -> author = 'Antadis' ;
}
function install () {
if ( parent :: install () == FALSE )
return FALSE ;
return TRUE ;
}
public function getContent () {
global $cookie ;
$output = '<h2>' . $this -> displayName . '</h2>' ;
set_time_limit ( 300 );
if ( Tools :: isSubmit ( 'submitUploadQuantities' )) {
$process = ( int ) Tools :: getValue ( 'qty_process' );
if ( isset ( $_FILES [ 'csvfile' ]) && $_FILES [ 'csvfile' ][ 'name' ] != '' ) {
$f = fopen ( $_FILES [ 'csvfile' ][ 'tmp_name' ], 'r' );
fgetcsv ( $f , 0 , ';' );
$ean_ok = TRUE ;
$i = 2 ;
while ( $line = fgetcsv ( $f , 0 , ';' )) {
if ( isset ( $line [ 4 ]) && $line [ 4 ] != '' && ! Validate :: isEan13 ( $line [ 4 ])) {
$ean_ok = FALSE ;
break ;
}
$i ++ ;
}
fclose ( $f );
if ( ! $ean_ok ) {
$output .= '<p class="error">' . $this -> l ( 'Invalid EAN13 on line' ) . ' ' . $i . '</p>' ;
return $output . $this -> displayForm ();
}
$f = fopen ( $_FILES [ 'csvfile' ][ 'tmp_name' ], 'r' );
fgetcsv ( $f , 0 , ';' );
$i = 1 ;
while ( $line = fgetcsv ( $f , 0 , ';' )) {
$i ++ ;
$product = new Product (( int ) $line [ 0 ]);
if ( Validate :: isLoadedObject ( $product )) {
if (( int ) $line [ 1 ] != 0 ) {
if ( ! Db :: getInstance () -> getRow ( '
SELECT `id_product_attribute`
FROM `'._DB_PREFIX_.'product_attribute`
WHERE `id_product` = '.(int) $line[0].'
AND `id_product_attribute` = '.(int) $line[1].'
' )) {
$output .= '<p class="error">' . $this -> l ( 'Invalid attribute ID for this product ID on line' ) . ' ' . $i . '</p>' ;
continue ;
}
}
if ( $line [ 2 ] != '' ) {
$qty = ( int ) $line [ 2 ];
$old_qty = Product :: getQuantity (( int ) $line [ 0 ], ( int ) $line [ 1 ] == 0 ? NULL : ( int ) $line [ 1 ]);
if ( $process == 0 ) {
$product -> addStockMvt ( $qty , 5 , ( int ) $line [ 1 ]);
} else {
if ( $qty > $old_qty ) {
$product -> addStockMvt ( $qty - $old_qty , 5 , ( int ) $line [ 1 ]);
} else {
$product -> addStockMvt ( - ( $old_qty - $qty ), 5 , ( int ) $line [ 1 ]);
}
}
}
if ( isset ( $line [ 4 ]) && $line [ 4 ] != '' && Validate :: isEan13 ( $line [ 4 ])) {
if (( int ) $line [ 1 ] != 0 ) {
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'product_attribute`
SET `ean13` = " '.pSQL( $line[4] ).' "
WHERE `id_product` = '.(int) $line[0].'
AND `id_product_attribute` = '.(int) $line[1].'
LIMIT 1
' );
} else {
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'product`
SET `ean13` = " '.pSQL( $line[4] ).' "
WHERE `id_product` = '.(int) $line[0].'
LIMIT 1
' );
}
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'order_detail`
SET `product_ean13` = " '.pSQL( $line[4] ).' "
WHERE `product_id` = '.(int) $line[0].'
AND `product_attribute_id` = '.(int) $line[1].'
' );
}
if ( isset ( $line [ 5 ]) && $line [ 5 ] != '' && Validate :: isReference ( $line [ 5 ])) {
if (( int ) $line [ 1 ] != 0 ) {
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'product_attribute`
SET `location` = " '.pSQL( $line[5] ).' "
WHERE `id_product` = '.(int) $line[0].'
AND `id_product_attribute` = '.(int) $line[1].'
LIMIT 1
' );
} else {
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'product`
SET `location` = " '.pSQL( $line[5] ).' "
WHERE `id_product` = '.(int) $line[0].'
LIMIT 1
' );
}
}
} else {
$output .= '<p class="warn">' . $this -> l ( 'Product #' ) . ( int ) $line [ 0 ] . ' ' . $this -> l ( 'not found' ) . '</p>' ;
}
}
fclose ( $f );
$output .= '<p class="conf">' . $this -> l ( 'Products updated' ) . '</p>' ;
}
} elseif ( Tools :: isSubmit ( 'submitUploadCategories' )) {
$f = fopen ( $_FILES [ 'csvfile' ][ 'tmp_name' ], 'r' );
fgetcsv ( $f , 0 , ';' );
$products = array ();
$defaults = array ();
$positions = array ();
while ( $line = fgetcsv ( $f , 0 , ';' )) {
if ( empty ( $line [ 0 ])) {
continue ;
}
if ( ! isset ( $line [ 1 ])) {
continue ;
}
if ( isset ( $line [ 2 ]) && ! empty ( $line [ 2 ]) && ( int ) $line [ 2 ] != 0 ) {
$defaults [( int ) $line [ 0 ]] = ( int ) $line [ 2 ];
}
$categories = array_map ( 'intval' , explode ( ',' , $line [ 1 ]));
$products [( int ) $line [ 0 ]] = $categories ;
foreach ( $categories as $id_category ) {
$positions [( int ) $id_category ] = 1 ;
}
}
fclose ( $f );
if ( Tools :: getValue ( 'category_process' ) == 1 ) {
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'category_product`
WHERE `id_product` IN ( '.implode(' , ', array_keys($products)).' )
' );
}
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_category` , MAX ( `position` ) AS `position`
FROM `'._DB_PREFIX_.'category_product`
WHERE `id_category` IN ( '.implode(' , ', array_keys($positions)).' )
GROUP BY `id_category`
' ) as $row ) {
$positions [( int ) $row [ 'id_category' ]] = ( int ) $row [ 'position' ];
}
foreach ( $products as $id_product => $id_categories ) {
foreach ( $id_categories as $id_category ) {
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'category_product` VALUES (
'.(int) $id_category.' ,
'.(int) $id_product.' ,
'.(int) ++$positions[(int) $id_category].'
)
' );
}
}
foreach ( $defaults as $id_product => $id_category_default ) {
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'product`
SET `id_category_default` = '.(int) $id_category_default.'
WHERE `id_product` = '.(int) $id_product.'
LIMIT 1
' );
if ( ! $row = Db :: getInstance () -> getRow ( '
SELECT `id_product`
FROM `'._DB_PREFIX_.'category_product`
WHERE `id_product` = '.(int) $id_product.'
AND `id_category` = '.(int) $id_category_default.'
' )) {
$pos = ( int ) Db :: getInstance () -> getValue ( '
SELECT MAX ( `position` )
FROM `'._DB_PREFIX_.'category_product`
WHERE `id_category` = '.(int) $id_category_default.'
' ) + 1 ;
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'category_product` VALUES (
'.(int) $id_category_default.' ,
'.(int) $id_product.' ,
'.(int) $pos.'
)
' );
}
}
$output .= '<p class="conf">' . $this -> l ( 'Products updated' ) . '</p>' ;
} elseif ( Tools :: isSubmit ( 'submitUploadAccessories' )) {
$f = fopen ( $_FILES [ 'csvfile' ][ 'tmp_name' ], 'r' );
fgetcsv ( $f , 0 , ';' );
$products = array ();
while ( $line = fgetcsv ( $f , 0 , ';' )) {
if ( empty ( $line [ 0 ]) || empty ( $line [ 1 ])) {
continue ;
}
if ( ! isset ( $products [( int ) $line [ 0 ]])) {
$products [( int ) $line [ 0 ]] = array ();
}
$products [( int ) $line [ 0 ]][] = ( int ) $line [ 1 ];
}
fclose ( $f );
if ( Tools :: getValue ( 'access_process' ) == 1 ) {
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'accessory`
WHERE `id_product_1` IN ( '.implode(' , ', array_keys($products)).' )
' );
}
foreach ( $products as $id_product_1 => $id_products_2 ) {
foreach ( $id_products_2 as $id_product_2 ) {
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'accessory` VALUES (
'.(int) $id_product_1.' ,
'.(int) $id_product_2.'
)
' );
}
}
$output .= '<p class="conf">' . $this -> l ( 'Products updated' ) . '</p>' ;
} elseif ( Tools :: isSubmit ( 'submitUploadImages' )) {
$f = fopen ( $_FILES [ 'csvfile' ][ 'tmp_name' ], 'r' );
fgetcsv ( $f , 0 , ';' );
$products = array ();
$products_a = array ();
$products_a_ids = array ();
while ( $line = fgetcsv ( $f , 0 , ';' )) {
if ( empty ( $line [ 0 ])) {
continue ;
}
if ( ! isset ( $line [ 1 ])
|| empty ( $line [ 1 ])) {
continue ;
}
if ( isset ( $line [ 2 ]) && ! empty ( $line [ 2 ])) {
if ( ! isset ( $products_a [( int ) $line [ 0 ]])) {
$products_a [( int ) $line [ 0 ]] = array ( array (), array ());
}
$products_a [( int ) $line [ 0 ]][ 0 ] = array_merge ( $products_a [( int ) $line [ 0 ]][ 0 ], array_map ( 'trim' , explode ( ',' , $line [ 1 ])));
$products_a [( int ) $line [ 0 ]][ 1 ][( int ) $line [ 2 ]] = array_map ( 'trim' , explode ( ',' , $line [ 1 ]));
$products_a_ids [] = ( int ) $line [ 2 ];
} else {
$products [( int ) $line [ 0 ]] = array_map ( 'trim' , explode ( ',' , $line [ 1 ]));
}
}
fclose ( $f );
if ( Tools :: getValue ( 'image_process' ) == 1 ) {
if ( count ( $products ) > 0 ) {
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_image`
FROM `'._DB_PREFIX_.'image`
WHERE `id_product` IN ( '.implode(' , ', array_keys($products)).' )
' ) as $row ) {
$i = new Image (( int ) $row [ 'id_image' ]);
$i -> delete ();
}
}
if ( count ( $products_a_ids ) > 0 ) {
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT DISTINCT i . `id_image`
FROM `'._DB_PREFIX_.'image` i
LEFT JOIN `'._DB_PREFIX_.'product_attribute` a
ON i . `id_product` = a . `id_product`
WHERE a . `id_product_attribute` IN ( '.implode(' , ', $products_a_ids).' )
' ) as $row ) {
$i = new Image (( int ) $row [ 'id_image' ]);
$i -> delete ();
}
}
}
foreach ( $products as $id_product => $urls ) {
foreach ( $urls as $url ) {
$image = new Image ();
$image -> id_product = $id_product ;
$image -> position = Image :: getHighestPosition ( $id_product ) + 1 ;
$image -> cover = FALSE ;
$image -> legend = self :: createMultiLangField ( Db :: getInstance () -> getValue ( '
SELECT `name`
FROM `'._DB_PREFIX_.'product_lang`
WHERE `id_product` = '.(int) $id_product.'
AND `id_lang` = 2
' ));
$image -> add ();
self :: copyImg ( $id_product , $image -> id , $url , 'products' );
}
}
$_id_products = array ();
foreach ( $products_a as $id_product => $data ) {
$_id_products [] = $id_product ;
foreach ( array_unique ( $data [ 0 ]) as $url ) {
$image = new Image ();
$image -> id_product = $id_product ;
$image -> position = Image :: getHighestPosition ( $id_product ) + 1 ;
$image -> cover = FALSE ;
$image -> legend = self :: createMultiLangField ( Db :: getInstance () -> getValue ( '
SELECT `name`
FROM `'._DB_PREFIX_.'product_lang`
WHERE `id_product` = '.(int) $id_product.'
AND `id_lang` = 2
' ));
$image -> add ();
self :: copyImg ( $id_product , $image -> id , $url , 'products' );
foreach ( $data [ 1 ] as $id_product_attribute => $urls ) {
if ( in_array ( $url , $urls )) {
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'product_attribute_image`
VALUES (
'.(int) $id_product_attribute.' ,
'.(int) $image->id.'
)
' );
}
}
}
}
$covers = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_product`
FROM `'._DB_PREFIX_.'image`
WHERE `id_product` IN ( '.implode(' , ', array_merge($_id_products, array_keys($products))).' )
AND `cover` = 1
' ) as $row ) {
$covers [] = ( int ) $row [ 'id_product' ];
}
$to_cover = array_diff ( array_merge ( $_id_products , array_keys ( $products )), $covers );
foreach ( $to_cover as $id_product ) {
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'image`
SET `cover` = 1
WHERE `id_product` = '.(int) $id_product.'
LIMIT 1
' );
}
$output .= '<p class="conf">' . $this -> l ( 'Products updated' ) . '</p>' ;
} elseif ( Tools :: isSubmit ( 'submitUploadStatus' )) {
$f = fopen ( $_FILES [ 'csvfile' ][ 'tmp_name' ], 'r' );
fgetcsv ( $f , 0 , ';' );
$products_0 = array ();
$products_1 = array ();
while ( $line = fgetcsv ( $f , 0 , ';' )) {
if ( empty ( $line [ 0 ]) || ! isset ( $line [ 1 ])) {
continue ;
}
if (( int ) $line [ 1 ] == 0 ) {
$products_0 [] = ( int ) $line [ 0 ];
} else {
$products_1 [] = ( int ) $line [ 0 ];
}
}
fclose ( $f );
if ( count ( $products_0 ) > 0 ) {
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'product`
SET `active` = 0
WHERE `id_product` IN ( '.implode(' , ', $products_0).' )
' );
}
if ( count ( $products_1 ) > 0 ) {
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'product`
SET `active` = 1
WHERE `id_product` IN ( '.implode(' , ', $products_1).' )
' );
}
$output .= '<p class="conf">' . $this -> l ( 'Products updated' ) . '</p>' ;
} elseif ( Tools :: isSubmit ( 'submitUploadPrices' )) {
$f = fopen ( $_FILES [ 'csvfile' ][ 'tmp_name' ], 'r' );
fgetcsv ( $f , 0 , ';' );
$products = array ();
$prices = array ();
if ( Tools :: getValue ( 'price_process' ) == 2 ) {
while ( $line = fgetcsv ( $f , 0 , ';' )) {
if ( empty ( $line [ 0 ])) {
continue ;
}
$products [] = ( int ) $line [ 0 ];
}
} else {
while ( $line = fgetcsv ( $f , 0 , ';' )) {
if ( empty ( $line [ 0 ])) {
continue ;
}
if ( ! isset ( $line [ 1 ])
|| ! isset ( $line [ 2 ])
|| ! in_array ( strtolower ( $line [ 1 ]), array ( 'percentage' , 'amount' ))) {
continue ;
}
$products [] = ( int ) $line [ 0 ];
$prices [] = array (
( int ) $line [ 0 ],
strtolower ( $line [ 1 ]),
( float ) $line [ 2 ] > 1 ? ( float ) $line [ 2 ] / 100 : ( float ) $line [ 2 ],
isset ( $line [ 3 ]) && Validate :: isDateFormat ( $line [ 3 ]) ? $line [ 3 ] : '0000-00-00 00:00:00' ,
isset ( $line [ 4 ]) && Validate :: isDateFormat ( $line [ 4 ]) ? $line [ 4 ] : '0000-00-00 00:00:00' ,
isset ( $line [ 5 ]) ? ( int ) $line [ 5 ] : 1 ,
);
}
}
fclose ( $f );
if ( Tools :: getValue ( 'price_process' ) == 1
|| Tools :: getValue ( 'price_process' ) == 2 ) {
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'specific_price`
WHERE `id_product` IN ( '.implode(' , ', $products).' )
' );
}
if ( Tools :: getValue ( 'price_process' ) != 2 ) {
foreach ( $prices as $price ) {
if (( int ) $price [ 0 ] != 0 ) {
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'specific_price` VALUES (
DEFAULT ,
'.(int) $price[0].' ,
1 ,
0 ,
0 ,
0 ,
0.0 ,
'.(int) $price[5].' ,
'.(float) $price[2].' ,
" '.pSQL( $price[1] ).' " ,
" '.pSQL( $price[3] ).' " ,
" '.pSQL( $price[4] ).' "
)
' );
} else {
$output .= '<p class="error">ID produit à 0, ligne non traitée : ' . serialize ( $price ) . '</p>' ;
}
}
}
$output .= '<p class="conf">' . $this -> l ( 'Products updated' ) . '</p>' ;
} elseif ( Tools :: isSubmit ( 'submitUploadCombinations' )) {
$f = fopen ( $_FILES [ 'csvfile' ][ 'tmp_name' ], 'r' );
fgetcsv ( $f , 0 , ';' );
$products = array ();
while ( $line = fgetcsv ( $f , 0 , ';' )) {
if ( empty ( $line [ 0 ])) {
continue ;
}
$products [] = ( int ) $line [ 0 ];
}
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'product_attribute_combination`
WHERE `id_product_attribute` IN (
SELECT `id_product_attribute`
FROM `'._DB_PREFIX_.'product_attribute`
WHERE `id_product` IN ( '.implode(' , ', $products).' )
)
' );
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'product_attribute`
WHERE `id_product` IN ( '.implode(' , ', $products).' )
' );
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'product`
SET `quantity` = 0
WHERE `id_product` IN ( '.implode(' , ', $products).' )
' );
fclose ( $f );
$output .= '<p class="conf">' . $this -> l ( 'Products updated' ) . '</p>' ;
} elseif ( Tools :: isSubmit ( 'submitExport' )) {
set_time_limit ( 300 );
$id_lang = Tools :: getValue ( 'id_lang' , $cookie -> id_lang );
if ( $id_category = ( int ) Tools :: getValue ( 'category' )) {
$c = new Category ( $id_category , $cookie -> id_lang );
$children = $c -> recurseLiteCategTree ( 5 , 0 , $id_lang );
$ids = $this -> _recurse_array ( array ( $children ));
$products = array ();
foreach ( $c -> getProductsWs () as $p ) {
$products [] = $p [ 'id' ];
}
foreach ( $ids as $id ) {
$sc = new Category ( $id , $id_lang );
foreach ( $sc -> getProductsWs () as $p ) {
$products [] = $p [ 'id' ];
}
}
$products = array_unique ( $products );
foreach ( glob ( dirname ( __FILE__ ) . '/*.csv' ) as $filename ) {
unlink ( $filename );
}
$fname = Tools :: passwdGen ( 10 ) . '.csv' ;
$f = fopen ( dirname ( __FILE__ ) . '/' . $fname , 'w' );
fputcsv ( $f , array (
'id_product' ,
'id_product_attribute' ,
'quantity' ,
'product_name' ,
'combination' ,
'ean13' ,
'location' ,
'brand' ,
'supplier_reference' ,
'quantity_sold' ,
'public_price_wt' ,
'price_wt' ,
'wholesale_price' ,
'active' ,
'description_short' ,
'description' ,
'images' ,
'categories' ,
), ';' , '"' );
foreach ( $products as $product ) {
$p = new Product (( int ) $product , $id_lang );
if ( ! Validate :: isLoadedObject ( $p )) {
$output .= '<p class="error">Erreur produit: ' . serialize ( $product ) . ' ce produit ne figure pas dans l\'export</p>' ;
} else {
$categories = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_category`
FROM `'._DB_PREFIX_.'category_product`
WHERE `id_product` = '.(int) $p->id.'
' ) as $cat ) {
$categories [] = ( int ) $cat [ 'id_category' ];
}
$combinations = array ();
foreach ( $p -> getAttributeCombinaisons ( $id_lang ) as $combi ) {
if ( ! isset ( $combinations [ $combi [ 'id_product_attribute' ]])) {
$combinations [ $combi [ 'id_product_attribute' ]] = array (
'qty' => $combi [ 'quantity' ],
'name' => array ( $combi [ 'attribute_name' ]),
'ean13' => $combi [ 'ean13' ],
'location' => empty ( $combi [ 'location' ]) ? $p -> location : $combi [ 'location' ],
'brand' => $p -> manufacturer_name ,
'supplier_reference' => empty ( $combi [ 'supplier_reference' ]) ? $p -> supplier_reference : $combi [ 'supplier_reference' ],
);
} else {
$combinations [ $combi [ 'id_product_attribute' ]][ 'name' ][] = $combi [ 'attribute_name' ];
}
}
$images = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT i . `id_image` , l . `legend`
FROM `'._DB_PREFIX_.'image` i
LEFT JOIN `'._DB_PREFIX_.'image_lang` l
ON l . `id_image` = i . `id_image`
WHERE l . `id_lang` = '.(int) $id_lang.'
AND i . `id_product` = '.(int) $p->id.'
' ) as $img ) {
$link_image = str_split ( $img [ 'id_image' ]);
$images [] = 'http://static.bebeboutik.com/img/p/' . implode ( '/' , $link_image ) . '/' . $img [ 'id_image' ] . '.jpg' ;
}
if ( count ( $combinations ) > 0 ) {
foreach ( $combinations as $k => $v ) {
$c_images = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT i . `id_image` , l . `legend`
FROM `'._DB_PREFIX_.'image` i
LEFT JOIN `'._DB_PREFIX_.'image_lang` l
ON l . `id_image` = i . `id_image`
LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` a
ON a . `id_image` = i . `id_image`
WHERE l . `id_lang` = '.(int) $id_lang.'
AND a . `id_product_attribute` = '.(int) $k.'
' ) as $img ) {
$link_image = str_split ( $img [ 'id_image' ]);
$c_images [] = 'http://static.bebeboutik.com/img/p/' . implode ( '/' , $link_image ) . '/' . $img [ 'id_image' ] . '.jpg' ;
// $c_images[] = 'http://static.bebeboutik.com/'.(int) $p->id.'-'.$img['id_image'].'.jpg';
}
$names = array_unique ( $v [ 'name' ]);
sort ( $names , SORT_STRING );
fputcsv ( $f , array (
$p -> id ,
$k ,
$v [ 'qty' ],
$p -> name [ $id_lang ],
implode ( ' - ' , $names ),
$v [ 'ean13' ],
$v [ 'location' ],
$v [ 'brand' ],
$v [ 'supplier_reference' ],
( int ) Db :: getInstance () -> getValue ( '
SELECT SUM ( d . `product_quantity` )
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'orders` o
ON o . `id_order` = d . `id_order`
LEFT JOIN `'._DB_PREFIX_.'order_history` h
ON h . `id_order` = d . `id_order`
WHERE d . `product_id` = '.(int) $p->id.'
AND d . `product_attribute_id` = '.(int) $k.'
AND h . `id_order_state` = 2
' ),
$p -> getPrice ( TRUE , ( int ) $k , 2 , NULL , FALSE , FALSE ),
$p -> getPrice ( TRUE , ( int ) $k , 2 ),
Tools :: ps_round ( $p -> wholesale_price , 2 ),
$p -> active ,
$p -> description_short [ $id_lang ],
$p -> description [ $id_lang ],
count ( $c_images ) > 0 ? implode ( ', ' , $c_images ) : implode ( ', ' , $images ),
implode ( ', ' , $categories ),
), ';' , '"' );
}
} else {
fputcsv ( $f , array (
$p -> id ,
0 ,
$p -> quantity ,
$p -> name [ $id_lang ],
'' ,
$p -> ean13 ,
$p -> location ,
$p -> manufacturer_name ,
$p -> supplier_reference ,
( int ) Db :: getInstance () -> getValue ( '
SELECT SUM ( d . `product_quantity` )
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'orders` o
ON o . `id_order` = d . `id_order`
LEFT JOIN `'._DB_PREFIX_.'order_history` h
ON h . `id_order` = d . `id_order`
WHERE d . `product_id` = '.(int) $p->id.'
AND h . `id_order_state` = 2
' ),
$p -> getPrice ( TRUE , NULL , 2 , NULL , FALSE , FALSE ),
$p -> getPrice ( TRUE , NULL , 2 ),
Tools :: ps_round ( $p -> wholesale_price , 2 ),
$p -> active ,
$p -> description_short [ $id_lang ],
$p -> description [ $id_lang ],
implode ( ', ' , $images ),
implode ( ', ' , $categories ),
), ';' , '"' );
}
}
}
fclose ( $f );
$output .= '<p class="conf">' . $this -> l ( 'Export complete.' ) . ' <a onclick="window.open(this.href); return false;" href="http://' . $_SERVER [ 'HTTP_HOST' ] . __PS_BASE_URI__ . 'modules/bulkupdate/' . $fname . '">' . $this -> l ( 'Click here to download the file' ) . '</a></p>' ;
} elseif ( $id_brand = ( int ) Tools :: getValue ( 'brand-ps' )) {
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT DISTINCT `id_product`
FROM `'._DB_PREFIX_.'product`
WHERE `id_manufacturer` = '.(int) $id_brand.'
' ) as $p ) {
$products [] = $p [ 'id_product' ];
}
foreach ( glob ( dirname ( __FILE__ ) . '/*.csv' ) as $filename ) {
unlink ( $filename );
}
$fname = Tools :: passwdGen ( 10 ) . '.csv' ;
$f = fopen ( dirname ( __FILE__ ) . '/' . $fname , 'w' );
fputcsv ( $f , array (
'id_product' ,
'id_product_attribute' ,
'quantity' ,
'product_name' ,
'combination' ,
'ean13' ,
'location' ,
'brand' ,
'supplier_reference' ,
'quantity_sold' ,
'public_price_wt' ,
'price_wt' ,
'wholesale_price' ,
'active' ,
'description_short' ,
'description' ,
'images' ,
'categories' ,
), ';' , '"' );
foreach ( $products as $product ) {
$p = new Product (( int ) $product , $id_lang );
if ( ! Validate :: isLoadedObject ( $p )) {
$output .= '<p class="error">Erreur produit: ' . serialize ( $product ) . ' ce produit ne figure pas dans l\'export</p>' ;
} else {
$categories = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_category`
FROM `'._DB_PREFIX_.'category_product`
WHERE `id_product` = '.(int) $p->id.'
' ) as $cat ) {
$categories [] = ( int ) $cat [ 'id_category' ];
}
$combinations = array ();
foreach ( $p -> getAttributeCombinaisons ( $id_lang ) as $combi ) {
if ( ! isset ( $combinations [ $combi [ 'id_product_attribute' ]])) {
$combinations [ $combi [ 'id_product_attribute' ]] = array (
'qty' => $combi [ 'quantity' ],
'name' => array ( $combi [ 'attribute_name' ]),
'ean13' => $combi [ 'ean13' ],
'location' => empty ( $combi [ 'location' ]) ? $p -> location : $combi [ 'location' ],
'brand' => $p -> manufacturer_name ,
'supplier_reference' => empty ( $combi [ 'supplier_reference' ]) ? $p -> supplier_reference : $combi [ 'supplier_reference' ],
);
} else {
$combinations [ $combi [ 'id_product_attribute' ]][ 'name' ][] = $combi [ 'attribute_name' ];
}
}
$images = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT i . `id_image` , l . `legend`
FROM `'._DB_PREFIX_.'image` i
LEFT JOIN `'._DB_PREFIX_.'image_lang` l
ON l . `id_image` = i . `id_image`
WHERE l . `id_lang` = '.(int) $id_lang.'
AND i . `id_product` = '.(int) $p->id.'
' ) as $img ) {
$images [] = 'http://static.bebeboutik.com/' . ( int ) $p -> id . '-' . $img [ 'id_image' ] . '.jpg' ;
}
if ( count ( $combinations ) > 0 ) {
foreach ( $combinations as $k => $v ) {
$c_images = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT i . `id_image` , l . `legend`
FROM `'._DB_PREFIX_.'image` i
LEFT JOIN `'._DB_PREFIX_.'image_lang` l
ON l . `id_image` = i . `id_image`
LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` a
ON a . `id_image` = i . `id_image`
WHERE l . `id_lang` = '.(int) $id_lang.'
AND a . `id_product_attribute` = '.(int) $k.'
' ) as $img ) {
$c_images [] = 'http://static.bebeboutik.com/' . ( int ) $p -> id . '-' . $img [ 'id_image' ] . '.jpg' ;
}
$names = array_unique ( $v [ 'name' ]);
sort ( $names , SORT_STRING );
fputcsv ( $f , array (
$p -> id ,
$k ,
$v [ 'qty' ],
$p -> name [ $id_lang ],
implode ( ' - ' , $names ),
$v [ 'ean13' ],
$v [ 'location' ],
$v [ 'brand' ],
$v [ 'supplier_reference' ],
( int ) Db :: getInstance () -> getValue ( '
SELECT SUM ( d . `product_quantity` )
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'orders` o
ON o . `id_order` = d . `id_order`
LEFT JOIN `'._DB_PREFIX_.'order_history` h
ON h . `id_order` = d . `id_order`
WHERE d . `product_id` = '.(int) $p->id.'
AND d . `product_attribute_id` = '.(int) $k.'
AND h . `id_order_state` = 2
' ),
$p -> getPrice ( TRUE , ( int ) $k , 2 , NULL , FALSE , FALSE ),
$p -> getPrice ( TRUE , ( int ) $k , 2 ),
Tools :: ps_round ( $p -> wholesale_price , 2 ),
$p -> active ,
$p -> description_short [ $id_lang ],
$p -> description [ $id_lang ],
count ( $c_images ) > 0 ? implode ( ', ' , $c_images ) : implode ( ', ' , $images ),
implode ( ', ' , $categories ),
), ';' , '"' );
}
} else {
fputcsv ( $f , array (
$p -> id ,
0 ,
$p -> quantity ,
$p -> name [ $id_lang ],
'' ,
$p -> ean13 ,
$p -> location ,
$p -> manufacturer_name ,
$p -> supplier_reference ,
( int ) Db :: getInstance () -> getValue ( '
SELECT SUM ( d . `product_quantity` )
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'orders` o
ON o . `id_order` = d . `id_order`
LEFT JOIN `'._DB_PREFIX_.'order_history` h
ON h . `id_order` = d . `id_order`
WHERE d . `product_id` = '.(int) $p->id.'
AND h . `id_order_state` = 2
' ),
$p -> getPrice ( TRUE , NULL , 2 , NULL , FALSE , FALSE ),
$p -> getPrice ( TRUE , NULL , 2 ),
Tools :: ps_round ( $p -> wholesale_price , 2 ),
$p -> active ,
$p -> description_short [ $id_lang ],
$p -> description [ $id_lang ],
implode ( ', ' , $images ),
implode ( ', ' , $categories ),
), ';' , '"' );
}
}
}
fclose ( $f );
$output .= '<p class="conf">' . $this -> l ( 'Export complete.' ) . ' <a onclick="window.open(this.href); return false;" href="http://' . $_SERVER [ 'HTTP_HOST' ] . __PS_BASE_URI__ . 'modules/bulkupdate/' . $fname . '">' . $this -> l ( 'Click here to download the file' ) . '</a></p>' ;
}
2016-01-27 15:59:19 +01:00
} elseif ( Tools :: isSubmit ( 'submitUploadProductDescriptions' )) {
$id_lang = Tools :: getValue ( 'description_process' );
$f = fopen ( $_FILES [ 'csvfile' ][ 'tmp_name' ], 'r' );
fgetcsv ( $f , 0 , ';' );
$products = array ();
while ( $line = fgetcsv ( $f , 0 , ';' )) {
if ( $line [ 0 ] == '' || $line [ 1 ] == '' ) {
continue ;
}
$products [] = $line ;
}
foreach ( $products as $line ) {
$result = Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'product_lang`
SET `description` = '. pSQL($line[1],true) .' "
WHERE `id_product` = '. (int) $line[0].'
AND `id_lang` = '.(int) $id_lang.'
' );
if ( ! $result ) {
$output .= '<p class="error">ligne non traitée, id_product: ' . $line [ 0 ] . '</p>' ;
}
}
fclose ( $f );
$output .= '<p class="conf">' . $this -> l ( 'Products updated' ) . '</p>' ;
2016-01-04 12:49:26 +01:00
} elseif ( Tools :: isSubmit ( 'submitExportPositions' )) {
set_time_limit ( 300 );
if ( $id_category = ( int ) Tools :: getValue ( 'category' )) {
foreach ( glob ( dirname ( __FILE__ ) . '/*.csv' ) as $filename ) {
unlink ( $filename );
}
$fname = Tools :: passwdGen ( 10 ) . '.csv' ;
$f = fopen ( dirname ( __FILE__ ) . '/' . $fname , 'w' );
fputcsv ( $f , array (
'id_category' ,
'id_product' ,
'position' ,
'name' ,
), ';' , '"' );
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT *
FROM `'._DB_PREFIX_.'category_product` cp
LEFT JOIN `'._DB_PREFIX_.'product_lang` l
ON cp . `id_product` = l . `id_product`
WHERE cp . `id_category` = '.(int) $id_category.'
AND l . `id_lang` = 2
' ) as $row ) {
fputcsv ( $f , array (
( int ) $row [ 'id_category' ],
( int ) $row [ 'id_product' ],
( int ) $row [ 'position' ],
$row [ 'name' ],
), ';' , '"' );
}
fclose ( $f );
$output .= '<p class="conf">' . $this -> l ( 'Export complete.' ) . ' <a onclick="window.open(this.href); return false;" href="http://' . $_SERVER [ 'HTTP_HOST' ] . __PS_BASE_URI__ . 'modules/bulkupdate/' . $fname . '">' . $this -> l ( 'Click here to download the file' ) . '</a></p>' ;
}
} elseif ( Tools :: isSubmit ( 'submitUploadPositions' )) {
set_time_limit ( 300 );
$f = fopen ( $_FILES [ 'csvfile' ][ 'tmp_name' ], 'r' );
fgetcsv ( $f , 0 , ';' );
$products = array ();
while ( $line = fgetcsv ( $f , 0 , ';' )) {
if ( $line [ 0 ] == '' || $line [ 1 ] == '' || $line [ 2 ] == '' ) {
continue ;
}
$products [] = $line ;
}
foreach ( $products as $line ) {
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'category_product`
SET `position` = '.(int) $line[2].'
WHERE `id_product` = '.(int) $line[1].'
AND `id_category` = '.(int) $line[0].'
' );
}
fclose ( $f );
$output .= '<p class="conf">' . $this -> l ( 'Products updated' ) . '</p>' ;
}
return $output . $this -> displayForm ();
}
private function _recurse_array ( $array ) {
$result = array ();
foreach ( $array as $i ) {
$result [] = $i [ 'id' ];
if ( count ( $i [ 'children' ]) > 0 ) {
$result = array_merge ( $result , $this -> _recurse_array ( $i [ 'children' ]));
}
}
return $result ;
}
public function displayForm () {
global $cookie ;
$output = '
< form action = " '.Tools::safeOutput( $_SERVER['REQUEST_URI'] ).' " method = " post " enctype = " multipart/form-data " >
< fieldset >< legend >< img src = " '. $this->_path .'logo.gif " alt = " " title = " " /> '.$this->l(' Update categories ').' </ legend >
< label > '.$this->l(' Action : ').' </ label >
< div class = " margin-form " >
< input type = " radio " id = " category_process_0 " name = " category_process " value = " 0 " /> < label style = " float: none; " for = " category_process_0 " > '.$this->l(' Update ').' </ label >
< input type = " radio " id = " category_process_1 " name = " category_process " value = " 1 " /> < label style = " float: none; " for = " category_process_1 " > '.$this->l(' Replace ').' </ label >
</ div >
< p > </ p >
< label > '.$this->l(' File : ').' </ label >
< div class = " margin-form " >
< input type = " file " name = " csvfile " />
< p > '.$this->l(' Format : id_product ; id_category , id_category , ... ; id_category_default -- the subsequent columns and the first line are ignored ').' </ p >
</ div >
< p > </ p >
< center >< input type = " submit " name = " submitUploadCategories " value = " '. $this->l ('Upload').' " class = " button " /></ center >
</ fieldset >
</ form > ' ;
$output .= '
< p >< br /></ p >
< form action = " '.Tools::safeOutput( $_SERVER['REQUEST_URI'] ).' " method = " post " enctype = " multipart/form-data " >
< fieldset >< legend >< img src = " '. $this->_path .'logo.gif " alt = " " title = " " /> '.$this->l(' Update prices ').' </ legend >
< label > '.$this->l(' Action : ').' </ label >
< div class = " margin-form " >
< input type = " radio " id = " price_process_0 " name = " price_process " value = " 0 " /> < label style = " float: none; " for = " price_process_0 " > '.$this->l(' Update ').' </ label >
< input type = " radio " id = " price_process_1 " name = " price_process " value = " 1 " /> < label style = " float: none; " for = " price_process_1 " > '.$this->l(' Replace ').' </ label >
< input type = " radio " id = " price_process_2 " name = " price_process " value = " 2 " /> < label style = " float: none; " for = " price_process_2 " > '.$this->l(' Delete ').' </ label >
</ div >
< p > </ p >
< label > '.$this->l(' File : ').' </ label >
< div class = " margin-form " >
< input type = " file " name = " csvfile " />
< p > '.$this->l(' Format : id_product ; reduction_type ; reduction ; date_from ; date_to ; quantity -- the subsequent columns and the first line are ignored ').' </ p >
</ div >
< p > </ p >
< center >< input type = " submit " name = " submitUploadPrices " value = " '. $this->l ('Upload').' " class = " button " /></ center >
</ fieldset >
</ form > ' ;
// $output .= '
// <p><br /></p>
// <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">
// <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Update status').'</legend>
// <label>'.$this->l('File:').'</label>
// <div class="margin-form">
// <input type="file" name="csvfile" />
// <p>'.$this->l('Format: id_product;active (0 / 1) -- the subsequent columns and the first line are ignored').'</p>
// </div>
// <p> </p>
// <center><input type="submit" name="submitUploadStatus" value="'.$this->l('Upload').'" class="button" /></center>
// </fieldset>
// </form>';
$output .= '
< p >< br /></ p >
< form action = " '.Tools::safeOutput( $_SERVER['REQUEST_URI'] ).' " method = " post " enctype = " multipart/form-data " >
< fieldset >< legend >< img src = " '. $this->_path .'logo.gif " alt = " " title = " " /> '.$this->l(' Update images ').' </ legend >
< label > '.$this->l(' Action : ').' </ label >
< div class = " margin-form " >
< input type = " radio " id = " image_process_0 " name = " image_process " value = " 0 " /> < label style = " float: none; " for = " image_process_0 " > '.$this->l(' Update ').' </ label >
< input type = " radio " id = " image_process_1 " name = " image_process " value = " 1 " /> < label style = " float: none; " for = " image_process_1 " > '.$this->l(' Replace ').' </ label >
</ div >
< p > </ p >
< label > '.$this->l(' File : ').' </ label >
< div class = " margin-form " >
< input type = " file " name = " csvfile " />
< p > '.$this->l(' Format : id_product ; image_url , image_url , ... -- the subsequent columns and the first line are ignored ').' </ p >
</ div >
< p > </ p >
< center >< input type = " submit " name = " submitUploadImages " value = " '. $this->l ('Upload').' " class = " button " /></ center >
</ fieldset >
</ form > ' ;
$output .= '
< p >< br /></ p >
< form action = " '.Tools::safeOutput( $_SERVER['REQUEST_URI'] ).' " method = " post " enctype = " multipart/form-data " >
< fieldset >< legend >< img src = " '. $this->_path .'logo.gif " alt = " " title = " " /> '.$this->l(' Update quantities ').' </ legend >
< label > '.$this->l(' Quantity process : ').' </ label >
< div class = " margin-form " >
< input type = " radio " id = " qty_process_0 " name = " qty_process " value = " 0 " /> < label style = " float: none; " for = " qty_process_0 " > '.$this->l(' Update ').' </ label >
< input type = " radio " id = " qty_process_1 " name = " qty_process " value = " 1 " /> < label style = " float: none; " for = " qty_process_1 " > '.$this->l(' Replace ').' </ label >
</ div >
< p > </ p >
< label > '.$this->l(' File : ').' </ label >
< div class = " margin-form " >
< input type = " file " name = " csvfile " />
< p > '.$this->l(' Format : id_product ; id_product_attribute ; quantity -- the subsequent columns and the first line are ignored ').' </ p >
</ div >
< p > </ p >
< center >< input type = " submit " name = " submitUploadQuantities " value = " '. $this->l ('Upload').' " class = " button " /></ center >
</ fieldset >
</ form > ' ;
2016-01-27 15:59:19 +01:00
$output .= '
< p >< br /></ p >
< form action = " '.Tools::safeOutput( $_SERVER['REQUEST_URI'] ).' " method = " post " enctype = " multipart/form-data " >
< fieldset >< legend >< img src = " '. $this->_path .'logo.gif " alt = " " title = " " /> '.$this->l(' Update product descriptions ').' </ legend >
< label > '.$this->l(' Description process : ').' </ label >
< div class = " margin-form " >
< input type = " radio " id = " description_process_0 " name = " description_process " value = " 0 " /> < label style = " float: none; " for = " description_process_0 " > '.$this->l(' Fr ').' </ label >
< input type = " radio " id = " description_process_1 " name = " description_process " value = " 1 " /> < label style = " float: none; " for = " description_process_1 " > '.$this->l(' Es ').' </ label >
</ div >
< p > </ p >
< label > '.$this->l(' File : ').' </ label >
< div class = " margin-form " >
< input type = " file " name = " csvfile " />
< p > '.$this->l(' Format : id_product ; description ; the subsequent columns and the first line are ignored ').' </ p >
</ div >
< p > </ p >
< center >< input type = " submit " name = " submitUploadProductDescriptions " value = " '. $this->l ('Upload').' " class = " button " /></ center >
</ fieldset >
</ form > ' ;
2016-01-04 12:49:26 +01:00
// $output .= '
// <p><br /></p>
// <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">
// <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Update accessories').'</legend>
// <label>'.$this->l('Accessory process:').'</label>
// <div class="margin-form">
// <input type="radio" id="access_process_0" name="access_process" value="0" /> <label style="float: none;" for="access_process_0">'.$this->l('Update').'</label>
// <input type="radio" id="access_process_1" name="access_process" value="1" /> <label style="float: none;" for="access_process_1">'.$this->l('Replace').'</label>
// </div>
// <p> </p>
// <label>'.$this->l('File:').'</label>
// <div class="margin-form">
// <input type="file" name="csvfile" />
// <p>'.$this->l('Format: id_product_1;id_product_2 -- the subsequent columns and the first line are ignored').'</p>
// </div>
// <p> </p>
// <center><input type="submit" name="submitUploadAccessories" value="'.$this->l('Upload').'" class="button" /></center>
// </fieldset>
// </form>';
// $output .= '
// <p><br /></p>
// <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">
// <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Update products positions').'</legend>
// <div class="margin-form">
// <br />';
// if(is_file(dirname(__FILE__).'/ctree.html') && (time() - filectime(dirname(__FILE__).'/ctree.html') < 86400)) {
// $output .= file_get_contents(dirname(__FILE__).'/ctree.html');
// } else {
// $ctree = '
// <select id="category_positions" name="category">';
// foreach(Db::getInstance()->ExecuteS('
// SELECT c.`id_category`, l.`name`
// FROM `'._DB_PREFIX_.'category_lang` l
// LEFT JOIN `'._DB_PREFIX_.'category` c
// ON c.`id_category` = l.`id_category`
// WHERE l.`id_lang` = '.(int) $cookie->id_lang.'
// AND c.`id_parent` = 1
// ') as $row) {
// $ctree .= '<option label="'.$row['name'].'">'.$row['id_category'].' - '.$row['name'].'</option>';
// foreach(Db::getInstance()->ExecuteS('
// SELECT c.`id_category`, l.`name`
// FROM `'._DB_PREFIX_.'category_lang` l
// LEFT JOIN `'._DB_PREFIX_.'category` c
// ON c.`id_category` = l.`id_category`
// WHERE l.`id_lang` = '.(int) $cookie->id_lang.'
// AND c.`id_parent` = '.$row['id_category'].'
// ') as $srow) {
// $ctree .= '<option style="padding-left: 30px;" value="'.$srow['id_category'].'">'.$srow['id_category'].' - '.$srow['name'].'</option>';
// foreach(Db::getInstance()->ExecuteS('
// SELECT c.`id_category`, l.`name`
// FROM `'._DB_PREFIX_.'category_lang` l
// LEFT JOIN `'._DB_PREFIX_.'category` c
// ON c.`id_category` = l.`id_category`
// WHERE l.`id_lang` = '.(int) $cookie->id_lang.'
// AND c.`id_parent` = '.$srow['id_category'].'
// ') as $ssrow) {
// $ctree .= '<option style="padding-left: 60px;" value="'.$ssrow['id_category'].'">'.$ssrow['id_category'].' - '.$ssrow['name'].'</option>';
// foreach(Db::getInstance()->ExecuteS('
// SELECT c.`id_category`, l.`name`
// FROM `'._DB_PREFIX_.'category_lang` l
// LEFT JOIN `'._DB_PREFIX_.'category` c
// ON c.`id_category` = l.`id_category`
// WHERE l.`id_lang` = '.(int) $cookie->id_lang.'
// AND c.`id_parent` = '.$ssrow['id_category'].'
// ') as $sssrow) {
// $ctree .= '<option style="padding-left: 90px;" value="'.$sssrow['id_category'].'">'.$sssrow['id_category'].' - '.$sssrow['name'].'</option>';
// foreach(Db::getInstance()->ExecuteS('
// SELECT c.`id_category`, l.`name`
// FROM `'._DB_PREFIX_.'category_lang` l
// LEFT JOIN `'._DB_PREFIX_.'category` c
// ON c.`id_category` = l.`id_category`
// WHERE l.`id_lang` = '.(int) $cookie->id_lang.'
// AND c.`id_parent` = '.$sssrow['id_category'].'
// ') as $ssssrow) {
// $ctree .= '<option style="padding-left: 120px;" value="'.$ssssrow['id_category'].'">'.$ssssrow['id_category'].' - '.$ssssrow['name'].'</option>';
// }
// }
// }
// }
// }
// $ctree .= '</select>';
// file_put_contents(dirname(__FILE__).'/ctree.html', $ctree);
// }
// $output .= '
// <p class="text">
// <input type="text" style="width: 300px;" id="filter_categories" value="" autocomplete="off" placeholder="'.$this->l('Filter by category').'" />
// </p>
// <script type="text/javascript">
// <!--
// var filter_timeout = null;
// $("#filter_categories").keyup(function() {
// clearTimeout(filter_timeout);
// filter_timeout = setTimeout(function() {
// $("#category_positions option").css("display", "none");
// var filter_str = $("#filter_categories").val().toLowerCase();
// $("#category_positions option").filter(function(index) {
// return $(this).text().toLowerCase().indexOf(filter_str) >= 0;
// }).css("display", "block");
// }, 300);
// });
// -->
// </script>
// </div>
// <p> </p>
// <center><input type="submit" name="submitExportPositions" value="'.$this->l('Export').'" class="button" /></center>
// <p> </p>
// <hr />
// <p> </p>
// <label>'.$this->l('File:').'</label>
// <div class="margin-form">
// <input type="file" name="csvfile" />
// <p>'.$this->l('Format: id_category;id_product;position -- the subsequent columns and the first line are ignored').'</p>
// </div>
// <p> </p>
// <center><input type="submit" name="submitUploadPositions" value="'.$this->l('Upload').'" class="button" /></center>
// </fieldset>
// </form>';
$output .= '
< p >< br /></ p >
< form action = " '.Tools::safeOutput( $_SERVER['REQUEST_URI'] ).' " method = " post " enctype = " multipart/form-data " >
< fieldset >< legend >< img src = " '. $this->_path .'logo.gif " alt = " " title = " " /> '.$this->l(' Delete combinations ').' </ legend >
< label > '.$this->l(' File : ').' </ label >
< div class = " margin-form " >
< input type = " file " name = " csvfile " />
< p > '.$this->l(' Format : id_product -- the subsequent columns and the first line are ignored ').' </ p >
</ div >
< p > </ p >
< center >< input type = " submit " name = " submitUploadCombinations " value = " '. $this->l ('Upload').' " class = " button " /></ center >
</ fieldset >
</ form > ' ;
$output .= '
< p >< br /></ p >
< form action = " '.Tools::safeOutput( $_SERVER['REQUEST_URI'] ).' " method = " post " enctype = " multipart/form-data " >
< fieldset >< legend >< img src = " '. $this->_path .'logo.gif " alt = " " title = " " /> '.$this->l(' Export ').' </ legend >
< label > '.$this->l(' Select a category to export : ').' </ label >
< div class = " margin-form " >
< br />
< select id = " category " name = " category " onchange = " $ ( \ '#brand-ps \ ').val( \ ' \ '); " >
< option value = " " ></ option >
' ;
//$sales_root = (int) Configuration::get('PRIVATESALES_ROOT');
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT c . `id_category` , l . `name`
FROM `'._DB_PREFIX_.'category_lang` l
LEFT JOIN `'._DB_PREFIX_.'category` c
ON c . `id_category` = l . `id_category`
WHERE l . `id_lang` = '.(int) $cookie->id_lang.'
AND c . `id_parent` = 1
' ) as $row ) {
$output .= '<option value="' . $row [ 'id_category' ] . '">' . $row [ 'id_category' ] . ' - ' . $row [ 'name' ] . '</option>' ;
}
$output .= ' </ select >
</ div >
< p > </ p >
< label > '.$this->l(' Select a private sales brand to export : ').' </ label >
< div class = " margin-form " >
< br />
< select id = " brand-ps " name = " brand-ps " onchange = " $ ( \ '#category \ ').val( \ ' \ '); " >
< option value = " " ></ option >
' ;
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_manufacturer` , `name`
FROM `'._DB_PREFIX_.'manufacturer`
' ) as $row ) {
$output .= '<option value="' . $row [ 'id_manufacturer' ] . '">' . $row [ 'id_manufacturer' ] . ' - ' . $row [ 'name' ] . '</option>' ;
}
$output .= ' </ select >
</ div >
< p > </ p >
< label > '.$this->l(' Select a language : ').' </ label >
< div class = " margin-form " >
< select id = " id_lang " name = " id_lang " >
' ;
foreach ( Language :: getLanguages ( FALSE ) as $lang ) {
$output .= '<option value="' . $lang [ 'id_lang' ] . '"' . ( $cookie -> id_lang == $lang [ 'id_lang' ] ? ' selected="selected"' : '' ) . '>' . $lang [ 'name' ] . '</option>' ;
}
$output .= ' </ select >
</ div >
< p > </ p >
< center >< input type = " submit " name = " submitExport " value = " '. $this->l ('Export').' " class = " button " /></ center >
</ fieldset >
</ form > ' ;
return $output ;
}
private static function copyImg ( $id_entity , $id_image = NULL , $url , $entity = 'products' ) {
$tmpfile = tempnam ( _PS_TMP_IMG_DIR_ , 'ps_import' );
$watermark_types = explode ( ',' , Configuration :: get ( 'WATERMARK_TYPES' ));
switch ( $entity ) {
default :
case 'products' :
$imageObj = new Image ( $id_image );
$path = $imageObj -> getPathForCreation ();
break ;
case 'categories' :
$path = _PS_CAT_IMG_DIR_ . ( int )( $id_entity );
break ;
}
if ( copy ( str_replace ( ' ' , '%20' , trim ( $url )), $tmpfile )) {
imageResize ( $tmpfile , $path . '.jpg' );
$imagesTypes = ImageType :: getImagesTypes ( $entity );
foreach ( $imagesTypes AS $k => $imageType ) {
imageResize ( $tmpfile , $path . '-' . stripslashes ( $imageType [ 'name' ]) . '.jpg' , $imageType [ 'width' ], $imageType [ 'height' ]);
}
if ( in_array ( $imageType [ 'id_image_type' ], $watermark_types )) {
Module :: hookExec ( 'watermark' , array ( 'id_image' => $id_image , 'id_product' => $id_entity ));
}
} else {
unlink ( $tmpfile );
return false ;
}
unlink ( $tmpfile );
return true ;
}
private static function createMultiLangField ( $field ) {
$languages = Language :: getLanguages ( FALSE );
$res = array ();
foreach ( $languages AS $lang ) {
$res [ $lang [ 'id_lang' ]] = $field ;
}
return $res ;
}
}