Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**************************************************
- Author : HellSea
- Date : 2017.04.25
- Description : Set to NULL the special price which
- has his end date that is passed.
- ***************************************************/
- $sql = new Sql();
- $sql->updateSpecialPrice();
- class Sql {
- //---------- Attributs ----------
- private $ConnectDB;
- //- End -----
- public function __construct() {
- $this->ConnectDB = new ConnectDB('magento','root','','localhost'
- );
- }
- public function updateSpecialPrice() {
- $db = new PDO('mysql:host='.$this->ConnectDB->geturlServerDB().';dbname='.$this->ConnectDB->getnomBD().';charset=utf8', $this->ConnectDB->getloginDB(), $this->ConnectDB->getpassBD());
- //----- Check si la vue "view_special_price" existe
- $sql = "SHOW tables LIKE 'view_special_price'";
- $stmt = $db->query($sql);
- $i = 0;
- while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
- $i++;
- }
- if ($i == 0) {
- $sql = "CREATE VIEW view_special_price AS
- SELECT `entity_id`,`value` FROM `catalog_product_entity_decimal` AS `price`
- INNER JOIN `eav_attribute` AS `attribute` ON `price`.`attribute_id` = `attribute`.`attribute_id`
- WHERE `entity_type_id` = '4'
- AND `attribute`.`attribute_code` = 'special_price'
- AND `price`.`value` != ''";
- $stmt = $db->query($sql);
- }
- //----- Check si la vue "view_special_price_to" existe
- $sql = "SHOW tables LIKE 'view_special_price_to'";
- $stmt = $db->query($sql);
- $i = 0;
- while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
- $i++;
- }
- if ($i == 0) {
- $sql = "CREATE VIEW view_special_price_to AS
- SELECT `entity_id`, `value` FROM `catalog_product_entity_datetime` AS `price`
- INNER JOIN `eav_attribute` AS `attribute` ON `price`.`attribute_id` = `attribute`.`attribute_id`
- WHERE `attribute_code` = 'special_to_date'";
- $stmt = $db->query($sql);
- }
- //----- Met à NULL les special price dont la date de fin est passée
- $sql = "UPDATE `view_special_price` AS `price`
- INNER JOIN `view_special_price_to` AS `time` ON `price`.`entity_id` = `time`.`entity_id`
- SET `price`.`value` = NULL
- WHERE `time`.`value` < NOW()";
- $stmt = $db->query($sql);
- $db = null;
- }
- }
- class ConnectDB
- {
- private $nomBD;
- private $loginDB;
- private $passBD;
- private $urlServerDB;
- public function __construct($nomBD,$loginDB,$passBD,$urlServerDB)
- {
- $this->nomBD = $nomBD;
- $this->loginDB = $loginDB;
- $this->passBD = $passBD;
- $this->urlServerDB = $urlServerDB;
- }
- public function getloginDB()
- {
- return $this->loginDB;
- }
- public function getnomBD()
- {
- return $this->nomBD;
- }
- public function getpassBD()
- {
- return $this->passBD;
- }
- public function geturlServerDB()
- {
- return $this->urlServerDB;
- }
- /**
- *
- * @param urlServerDB
- */
- public function seturlServerDB($urlServerDB)
- {
- $this->urlServerDB = $urlServerDB;
- }
- /**
- *
- * @param nomBD
- */
- public function setnomBD($nomBD)
- {
- $this->nomBD = $nomBD;
- }
- /**
- *
- * @param loginDB
- */
- public function setloginDB($loginDB)
- {
- $this->loginDB = $loginDB;
- }
- /**
- *
- * @param passBD
- */
- public function setpassBD($passBD)
- {
- $this->passBD = $passBD;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement