89 lines
3.4 KiB
PHP
89 lines
3.4 KiB
PHP
<?php
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
|
|
class MarzaAllegro extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'marzaallegro';
|
|
$this->tab = 'pricing_promotion';
|
|
$this->version = '1.0.0';
|
|
$this->author = 'YourName';
|
|
$this->need_instance = 0;
|
|
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
|
|
$this->bootstrap = true;
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Marża Allegro');
|
|
$this->description = $this->l('Dodaje marżę do cen produktów na Allegro.');
|
|
|
|
$this->confirmUninstall = $this->l('Czy na pewno chcesz odinstalować?');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
Configuration::updateValue('MARZAALLEGRO_ENABLED', 'no');
|
|
|
|
return parent::install() &&
|
|
$this->registerHook('actionX13AllegroProductPriceModifier');
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
Configuration::deleteByName('MARZAALLEGRO_ENABLED');
|
|
|
|
return parent::uninstall();
|
|
}
|
|
|
|
public function hookActionX13AllegroProductPriceModifier($params)
|
|
{
|
|
if ( $params['id_product'] and $params['marketplace'] == 'allegro-pl' )
|
|
{
|
|
// file_put_contents( $_SERVER['DOCUMENT_ROOT'] . '/log.txt', print_r( $params, true ) . PHP_EOL, FILE_APPEND );
|
|
$allegro_prices = file_get_contents( '../../allegro-prices.txt' );
|
|
$allegro_prices = explode( PHP_EOL, $allegro_prices );
|
|
foreach ( $allegro_prices as $row )
|
|
{
|
|
$margin = explode( ';', $row );
|
|
$allegro_margin[$margin[0]] = [ 'id_manufacturer' => $margin[0], 'manufacturer' => $margin[1], 'margin' => $margin[2] ];
|
|
}
|
|
|
|
// pobieram id_manufacturer
|
|
$id_manufacturer = Db::getInstance()->getValue( 'SELECT `id_manufacturer` FROM `ps_product` WHERE `id_product` = "' . $params['id_product'] . '"' );
|
|
if ( isset( $allegro_margin[ $id_manufacturer]['margin'] ) )
|
|
{
|
|
// pobierz cenę produktu
|
|
$product = new Product( $params['id_product'] );
|
|
|
|
$product_price_static = Product::getPriceStatic( $params['id_product'], true );
|
|
// $product_price_netto = $product -> price;
|
|
|
|
// vat = 23%
|
|
// $product_price = $product_price_netto * 1.23;
|
|
echo '--------- DUMP naliczania marży ---------<br>';
|
|
// id produktu
|
|
echo 'ID produktu: ' . $params['id_product'] . '<br>';
|
|
echo 'Cena produktu netto: ' . $product -> price . '<br>';
|
|
echo 'Cena produktu: ' . ( $product -> price * 1.23 ) . '<br>';
|
|
echo 'Cena promocyjna produktu: ' . $product_price_static . '<br>';
|
|
echo 'Manufacturer: ' . $product -> id_manufacturer . '<br>';
|
|
// dodaj marażę
|
|
$product_price = $product_price_static * ( 1 + $allegro_margin[ $id_manufacturer]['margin'] / 100 );
|
|
echo 'Cena produktu z marżą: ' . $product_price . '<br>';
|
|
// zaokrąglij do 2 miejsc po przecinku
|
|
$product_price = round( $product_price, 2 );
|
|
echo 'Cena produktu z marżą zaokrąglona: ' . $product_price . '<br>';
|
|
// wielkość marży
|
|
echo 'Marża: ' . $allegro_margin[ $id_manufacturer]['margin'] . '<br>';
|
|
echo '-------- KONIEC DUMP naliczania marży --------<br>';
|
|
|
|
// $params['product_price'] = $product_price;
|
|
// $params['auction']['price_buy_now'] = $product_price;
|
|
}
|
|
}
|
|
}
|
|
}
|