Advertisement
Guest User

Update-Actions.php

a guest
Oct 25th, 2019
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.44 KB | None | 0 0
  1. <?php
  2. /**************************************************
  3.  Author :          HellSea
  4.  Date :            2017.04.25
  5.  Description : Set to NULL the special price which
  6.                             has his end date that is passed.
  7. ***************************************************/
  8. $sql = new Sql();
  9. $sql->updateSpecialPrice();
  10.  
  11. class Sql {
  12.         //---------- Attributs ----------
  13.         private $ConnectDB;
  14.         //- End -----
  15.         public function __construct() {
  16.                 $this->ConnectDB = new ConnectDB('magento','root','','localhost'
  17. );
  18.         }
  19.         public function updateSpecialPrice() {
  20.                 $db = new PDO('mysql:host='.$this->ConnectDB->geturlServerDB().';dbname='.$this->ConnectDB->getnomBD().';charset=utf8', $this->ConnectDB->getloginDB(), $this->ConnectDB->getpassBD());
  21.                 //----- Check si la vue "view_special_price" existe
  22.                 $sql = "SHOW tables LIKE 'view_special_price'";
  23.                 $stmt = $db->query($sql);
  24.                 $i = 0;
  25.                 while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
  26.                         $i++;
  27.                 }
  28.                 if ($i == 0) {
  29.                         $sql = "CREATE VIEW view_special_price AS
  30.                                        SELECT `entity_id`,`value` FROM `catalog_product_entity_decimal` AS `price`
  31.                                        INNER JOIN `eav_attribute` AS `attribute` ON `price`.`attribute_id` = `attribute`.`attribute_id`
  32.                                        WHERE `entity_type_id` = '4'
  33.                                        AND `attribute`.`attribute_code` = 'special_price'
  34.                                        AND `price`.`value` != ''";
  35.                         $stmt = $db->query($sql);
  36.                 }
  37.                 //----- Check si la vue "view_special_price_to" existe
  38.                 $sql = "SHOW tables LIKE 'view_special_price_to'";
  39.                 $stmt = $db->query($sql);
  40.                 $i = 0;
  41.                 while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
  42.                         $i++;
  43.                 }
  44.                 if ($i == 0) {
  45.                         $sql = "CREATE VIEW view_special_price_to AS
  46.                                        SELECT `entity_id`, `value` FROM `catalog_product_entity_datetime` AS `price`
  47.                                        INNER JOIN `eav_attribute` AS `attribute` ON `price`.`attribute_id` = `attribute`.`attribute_id`
  48.                                        WHERE `attribute_code` = 'special_to_date'";
  49.                         $stmt = $db->query($sql);
  50.                 }
  51.                 //----- Met à  NULL les special price dont la date de fin est passée
  52.                 $sql = "UPDATE `view_special_price` AS `price`
  53.                                INNER JOIN `view_special_price_to` AS `time` ON `price`.`entity_id` = `time`.`entity_id`
  54.                                SET `price`.`value` = NULL
  55.                                WHERE `time`.`value` < NOW()";
  56.                 $stmt = $db->query($sql);
  57.                 $db = null;
  58.         }
  59. }
  60. class ConnectDB
  61. {
  62.         private   $nomBD;
  63.         private   $loginDB;
  64.         private   $passBD;
  65.         private   $urlServerDB;
  66.         public function __construct($nomBD,$loginDB,$passBD,$urlServerDB)
  67.         {
  68.             $this->nomBD = $nomBD;
  69.             $this->loginDB = $loginDB;
  70.             $this->passBD = $passBD;
  71.             $this->urlServerDB = $urlServerDB;
  72.         }
  73.         public function getloginDB()
  74.         {
  75.             return $this->loginDB;
  76.         }
  77.         public function getnomBD()
  78.         {
  79.             return $this->nomBD;
  80.         }
  81.         public function getpassBD()
  82.         {
  83.             return $this->passBD;
  84.         }
  85.         public function geturlServerDB()
  86.         {
  87.             return $this->urlServerDB;
  88.         }
  89.         /**
  90.          *
  91.          * @param urlServerDB
  92.          */
  93.         public function seturlServerDB($urlServerDB)
  94.         {
  95.             $this->urlServerDB = $urlServerDB;
  96.         }
  97.      /**
  98.        *
  99.        * @param nomBD
  100.        */
  101.      public function setnomBD($nomBD)
  102.      {
  103.         $this->nomBD = $nomBD;
  104.      }
  105.      /**
  106.        *
  107.        * @param loginDB
  108.        */
  109.      public function setloginDB($loginDB)
  110.      {
  111.         $this->loginDB = $loginDB;
  112.      }
  113.      /**
  114.        *
  115.        * @param passBD
  116.        */
  117.      public function setpassBD($passBD)
  118.      {
  119.         $this->passBD = $passBD;
  120.      }
  121. }
  122. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement