ShippingCategory.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Cpcommerce\ShippingNotifications\Block;
  3. use Magento\Catalog\Block\Product\View\Description;
  4. use Magento\Framework\View\Element\Template;
  5. use Magento\Framework\View\Element\Template\Context;
  6. use \Magento\Framework\App\Config\ScopeConfigInterface;
  7. class ShippingCategory extends Template
  8. {
  9. private $description;
  10. private $context;
  11. private $data;
  12. private $scopeConfig;
  13. public function __construct(
  14. Description $description,
  15. Context $context,
  16. array $data = [],
  17. ScopeConfigInterface $scopeConfig
  18. ) {
  19. $this->description = $description;
  20. $this->scopeConfig = $scopeConfig;
  21. return parent::__construct($context, $data);
  22. }
  23. public function getShippingCategory(){
  24. $_product = $this->description->getProduct();
  25. $attributeCode = $this->scopeConfig->getValue('cpcommerce_shipping_notifications/general/attribute',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  26. $option_id = $_product->getData($attributeCode);
  27. return $option_id;
  28. }
  29. public function getDelayedShippingCategories(){
  30. $delayedShipCategs = $this->scopeConfig->getValue('cpcommerce_shipping_notifications/general/shipping_categories',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  31. if(isset($delayedShipCategs)){
  32. $delayedShipCategsArray = explode(",",$delayedShipCategs);
  33. return $delayedShipCategsArray;
  34. }
  35. return null;
  36. }
  37. public function getBlock(){
  38. $notifBlock = $this->scopeConfig->getValue('cpcommerce_shipping_notifications/general/shipping_notification_block',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  39. if(!isset($notifBlock)){
  40. return null;
  41. }
  42. return $notifBlock;
  43. }
  44. }