Skip to content
Snippets Groups Projects
Select Git revision
  • a1543ef9a6aae0803dc7dd7689f0d5f8a1feba58
  • dev default protected
  • prod protected
  • 1.0.58
  • 1.0.57
  • 1.0.52
  • 1.0.56
  • 1.0.51
  • 1.0.50
  • 1.0.33
  • 1.0.32
  • 1.0.31
  • 1.0.30
  • 1.0.29
  • 1.0.28
  • 1.0.27
  • 1.0.26
  • 1.0.25
  • 1.0.24
  • 1.0.23
  • 1.0.22
  • 1.0.21
  • 1.0.20
23 results

PopUpDeliveryDate.php

Blame
  • PopUpDeliveryDate.php 1.29 KiB
    <?php
    
    namespace BobGroup\BobGo\Plugin\Block\Tracking;
    
    use Magento\Shipping\Block\Tracking\Popup;
    use Magento\Shipping\Model\Tracking\Result\Status;
    use Magento\Shipping\Model\Carrier;
    
    /*
     * Plugin to update delivery date value in case if Bob Go is a carrier used
     */
    class PopupDeliveryDate
    {
        /**
         * Show only date for expected delivery in case if Bob Go is a carrier
         *
         * @param Popup $subject
         * @param string $result
         * @param string $date
         * @param string $time
         * @return string
         * @SuppressWarnings(PHPMD.UnusedFormalParameter)
         */
        public function afterFormatDeliveryDateTime(Popup $subject, $result, $date, $time)
        {
            if ($this->getCarrier($subject) === Carrier::CODE) {
                $result = $subject->formatDeliveryDate($date);
            }
            return $result;
        }
    
        /**
         * Retrieve carrier name from tracking info
         *
         * @param Popup $subject
         * @return string
         */
        private function getCarrier(Popup $subject): string
        {
            foreach ($subject->getTrackingInfo() as $trackingData) {
                foreach ($trackingData as $trackingInfo) {
                    if ($trackingInfo instanceof Status) {
                        return $trackingInfo->getCarrier();
                    }
                }
            }
            return '';
        }
    }