bundles/Jabber/GenericBundle/EventListener/PriceChangesLive.php line 29

Open in your IDE?
  1. <?php 
  2. namespace Jabber\GenericBundle\EventListener;
  3. use Jabber\GenericBundle\Messenger\TestMessenger;
  4. use Pimcore\Db;
  5. use Pimcore\Event\Model\ElementEventInterface;
  6. use Pimcore\Event\Model\DataObjectEvent;
  7. use Pimcore\Model\DataObject\Product;
  8. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  9. use Symfony\Component\Messenger\MessageBusInterface;
  10. class PriceChangesLive {
  11.     private $syncCompanyOne false;
  12.     private $syncCompanyTwo false;
  13.     /**
  14.      *
  15.      * @var ParameterBagInterface
  16.      */
  17.     private $params null;
  18.     public function __construct(ParameterBagInterface $params, private MessageBusInterface $bus) {
  19.         $this->params $params;
  20.     }
  21.     public function OnPostSave(ElementEventInterface $e) {
  22.         if (!$e->hasArgument('isAutoSave')) {
  23.             if ($e instanceof DataObjectEvent) {
  24.                 $dataObject $e->getObject();
  25.                 if ($dataObject instanceof Product) {
  26.                     // if (!$this->IgnoredUser($dataObject->getUserModification())) {
  27.                         if ($dataObject->getProductLevel() == 'STYLE') {
  28.                             $this->checkForChanges($dataObject);
  29.                             if ($this->syncCompanyOne == true) {
  30.                                 $this->bus->dispatch(new TestMessenger($dataObject->getId(), 58));
  31.                             }
  32.                             if ($this->syncCompanyTwo == true) {
  33.                                 $this->bus->dispatch(new TestMessenger($dataObject->getId(), 65));
  34.                             }
  35.                         }
  36.                     // }
  37.                 }
  38.             }
  39.         }
  40.     }
  41.     private function checkForChanges(Product $dataObject) {
  42.         $storedRetail Db::getConnection()->fetchAssociative('SELECT RetailPriceGBP, RetailPriceUSD FROM object_store_Product WHERE oo_id = ?', [$dataObject->getId()]);
  43.         $storedWebGb Db::getConnection()->fetchAssociative('SELECT WebSellingPrice FROM object_localized_query_Product_en_GB WHERE ooo_id = ?', [$dataObject->getId()]);
  44.         $storedWebUs Db::getConnection()->fetchAssociative('SELECT WebSellingPrice FROM object_localized_query_Product_en_US WHERE ooo_id = ?', [$dataObject->getId()]);
  45.         if ($storedRetail['RetailPriceGBP'] != $dataObject->getRetailPriceGBP()) {
  46.             $this->syncCompanyOne true;
  47.         }
  48.         if ($storedRetail['RetailPriceUSD'] != $dataObject->getRetailPriceUSD()) {
  49.             $this->syncCompanyTwo true;
  50.         }
  51.         if ($storedWebGb['WebSellingPrice'] != $dataObject->getWebSellingPrice('en_GB')) {
  52.             $this->syncCompanyOne true;
  53.         }
  54.         if ($storedWebUs['WebSellingPrice'] != $dataObject->getWebSellingPrice('en_US')) {
  55.             $this->syncCompanyTwo true;
  56.         }
  57.     }
  58.     // /**
  59.     //  * Is user in ignore list for price changes
  60.     //  *
  61.     //  * @param int $userId
  62.     //  * @return bool
  63.     //  */
  64.     // private function IgnoredUser($userId) {
  65.     //     $ignoredUsers = null;
  66.     //     $priceBundleParams = $this->params->get('jabber_price_bundle');
  67.     //     if (isset($priceBundleParams['ignored_users'])) {
  68.     //         $ignoredUsers = $priceBundleParams['ignored_users'];
  69.     //     }
  70.     //     if (is_array($ignoredUsers)) {
  71.     //         if (isset($ignoredUsers[$userId])) {
  72.     //             return true;
  73.     //         }
  74.     //     }
  75.     //     return false;
  76.     // }
  77.     
  78. }