| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace Cpcommerce\ShippingNotifications\Block;
- use Magento\Catalog\Block\Product\View\Description;
- use Magento\Catalog\Model\Product\Attribute\Repository;
- use Magento\Framework\View\Element\Template;
- use Magento\Framework\View\Element\Template\Context;
- use Cpcommerce\ShippingNotifications\Model\ShippingCategory AS DelayedShippingCategory;
- use Cpcommerce\ShippingNotifications\Model\ResourceModel\ShippingCategory\Collection;
- use Magento\Framework\App\ResourceConnection;
- class ShippingCategory extends Template
- {
- protected $resource;
- public function __construct(
- Description $description,
- Repository $attribute,
- Context $context,
- array $data = [],
- DelayedShippingCategory $delayedShippingCategory,
- Collection $delayedCollection,
- ResourceConnection $resource
- ) {
- $this->description = $description;
- $this->attribute = $attribute;
- $this->delayedShippingCategory = $delayedShippingCategory;
- $this->delayedCollection = $delayedCollection;
- $this->resource = $resource;
- return parent::__construct($context, $data);
- }
- public function getAttributeData($attribute_code){
- return $this->attribute->get($attribute_code);
- }
- public function getShippingCategory(){
- $_product = $this->description->getProduct();
- $option_id = $_product->getShippingCategory();
- return $option_id;
- }
- public function getDelayedShippingCategories(){
- $this->delayedCollection->getSelect()->where("is_delayed = '1'");
- return $this->delayedCollection->load();
- }
- public function toOptionArray(){
- $options = $this->attribute->get($attribute_code)->getOptions;
- $options_array = [];
- foreach($options as $option){
- $options_array[] = [
- 'label' => $options->getTitle(),
- 'value' => $options->getId()
- ];
- }
- }
- }
|