SHARE
TWEET

Untitled

a guest Feb 17th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. event name="prepare_catalog_product_collection_prices"
  2.    
  3. use MagentoFrameworkEventObserverInterface;
  4. use MagentoCatalogModelProduct;
  5. use MagentoCustomerModelSession as CustomerModelSession;
  6. use MagentoFrameworkEventObserver as EventObserver;
  7.  
  8. class Discount implements ObserverInterface
  9. {
  10.     /**
  11.      * @var CustomerModelSession
  12.      */
  13.     protected $customerSession;
  14.  
  15.  
  16.  
  17.     public function __construct(        
  18.         CustomerModelSession $customerSession
  19.     ) {
  20.         $this->customerSession = $customerSession;
  21.     }
  22.  
  23.  
  24.  
  25.  
  26.    public function execute(MagentoFrameworkEventObserver $observer)
  27.     {
  28.         if ($this->customerSession->isLoggedIn()) {
  29.             $collection = $observer->getEvent()->getCollection();
  30.             $cId = $this->customerSession->getCustomerId();
  31.  
  32.             foreach ($collection as $product) {
  33.                 $finalPrice = min($product->getData('final_price'), $this->getmyPrice( $product,$cId));
  34. $_product->setMinimalPrice($finalPrice)
  35.                   ->setPrice($finalPrice)
  36.                   ->setFinalPrice($finalPrice);            
  37.                 }
  38.  
  39.             return $this;
  40.         }
  41.  
  42.  
  43.         return $this;
  44.     }
  45.     public function getmyPrice($product,$cid)
  46.     {
  47.  
  48.         $price=2;
  49.  
  50.         return price;
  51.  
  52.     }
  53. }
  54.    
  55. afterGetPrice(MagentoCatalogModelProduct $subject, $result)
  56.    
  57. <?php
  58. /**
  59.  * @author      Schasiepen
  60.  * @category    Prommerce
  61.  * @package     Prommerce_Resellerdiscount
  62.  */
  63.  
  64. namespace PrommerceResellerdiscountPlugin;
  65.  
  66.  
  67.  
  68. class Tierprice
  69. {
  70.  
  71.  
  72.     public $customerSession;
  73.     protected $customerRepository;
  74.     public $kunde;
  75.  
  76.  
  77.     public function __construct(
  78.   MagentoCustomerModelSession $customerSession, MagentoCustomerApiCustomerRepositoryInterface $customerRepository
  79. ) {
  80.    $this->customerSession = $customerSession;
  81.    $this->customerRepository = $customerRepository;
  82.    $this->kunde =$this->customerSession->isLoggedIn();
  83.    $this->cid = $this->customerSession->getCustomerId();
  84.  
  85. }
  86.  
  87.  
  88.     public function afterGetPrice(MagentoCatalogModelProduct $subject, $result)
  89.     {
  90.  
  91.  
  92.         $id=$subject->getId();
  93.         $sku=$subject->getSku();
  94.         $brand_id=substr($sku, 0, 2);
  95.         $result=$this->calculate($result,$subject,$id,$brand_id);
  96.                 return $result;
  97.     }
  98.  
  99.  
  100.  
  101.     public function calculate($price,$subject,$id,$brand_id)
  102.     {
  103.  
  104.         if ($this->customerSession->isLoggedIn()) {
  105.             $this->kunde = true;
  106.  
  107.             ...do some calulation here based on $this->cid ....
  108.  
  109.                 return $price;  
  110.  
  111.  
  112.         }
  113.         else {
  114.  
  115.             //echo "<pre> kein kunde</pre>";
  116.             return $price;
  117.  
  118.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top