Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Magecomp/Savecartpro/Block/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Magecomp/Savecartpro/Block/Customerviewcart.php
<?php
namespace Magecomp\Savecartpro\Block;

use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\View\Element\Template;
use Magecomp\Savecartpro\Model\SavecartproFactory;
use Magecomp\Savecartpro\Model\SavecartprodetailFactory;
use Magento\Catalog\Model\ProductFactory;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Serialize\Serializer\Json;

class Customerviewcart extends Template
{
	protected $_request;
	protected $modelsavecart;
	protected $modelsavecartdetail;
	protected $product;
	protected $_productFactory;
    protected $serialize;
	
	public function __construct(Context $context,
		SavecartproFactory $modelsavecart,
		ProductFactory $productFactory,
		SavecartprodetailFactory $modelsavecartdetail,
        JsonFactory $jsonFactory,
        Json $serialize,
        array $data = []

        )
    {
		$this->modelsavecart = $modelsavecart;
		$this->modelsavecartdetail = $modelsavecartdetail;
		$this->_productFactory = $productFactory;
        $this->jsonFactory=$jsonFactory;
        $this->serialize = $serialize;
        parent::__construct($context, $data);
    }
	
	public function getMainCartData()
	{
		$data = $this->_request->getParams();
		$quoteid = $data['qid'];
		if($quoteid != '' && $quoteid > 0)
		{
			return $this->modelsavecart->create()->load($quoteid);	
		}
	}
	
	public function getDetailCartData()
	{
		$data = $this->_request->getParams();
		$quoteid = $data['qid'];
		if($quoteid != '' && $quoteid > 0)
		{
			$quotedetailCollection = $this->modelsavecartdetail->create()
							 ->getCollection()
							 ->addFieldToFilter('savecart_id',$quoteid);
							 
			$filtercollection = array();
			$products = array();
			foreach($quotedetailCollection as $quotedetail)
			{
				if(!in_array($quotedetail->getQuotePrdId(), $products))
				{
					$filtercollection[] = $quotedetail;
					$products[] =  $quotedetail->getQuotePrdId();
				}
			}
			return $quotedetailCollection;
		}
	}
	
	public function getProductName($productid)
	{
        $om = \Magento\Framework\App\ObjectManager::getInstance();
		$product = $om->create('Magento\Catalog\Model\Product')->load($productid);
        return $product->getName();
	}

    public function getAllOptions($productid,$alloption)
    {
        $html = '';
        $om = \Magento\Framework\App\ObjectManager::getInstance();
        $product = $this->_productFactory->create()->load($productid);
        $itemOptions = $this->serialize->unserialize($alloption);

        if (array_key_exists('options',$itemOptions)) {
            $c_opt = $itemOptions['options'];

            $customOptions = $om->create('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product);
            foreach ($customOptions as $co) {
                foreach ($c_opt as $ckey => $cvalue) {
                    if ($ckey == $co['option_id']) {
                        if ($co->getType() == "field" || $co->getType() == "area") {
                            $html .= "<b>" . $co['title'] . "</b> :";
                            foreach ($co as $value) {
                                $html .= $cvalue . "<br>";
                            }
                        }
                    }
                }
            }

            foreach($customOptions as $option) {
                if ($option->getType() == "field" || $option->getType() == "area" || $option->getType() == "date" || $option->getType() == "date_time" || $option->getType() == "time") {
                    continue;
                }
                $html .= "<b>" . $option['title'] . "</b> :";
                $values = $option->getValues();
                if (empty($values)) {
                    continue;
                }

                foreach($values as $value) {
                    $valueTitle = $value->getTitle();
                    $html .= $valueTitle. "<br>";
                }
            }
        }

        if (array_key_exists('super_attribute', $itemOptions)) {
            $super_att = $itemOptions['super_attribute'];
            foreach ($super_att as $key => $value) {
                $attributeId = $key;
                $eavModel = $om->create('Magento\Catalog\Model\ResourceModel\Eav\Attribute');
                $eavModel->load($attributeId);
                $attLabel = $eavModel->getFrontendLabel();
                $attributeCode = $eavModel->getAttributeCode();

                $optionId = $value;
                $attribute = $product->getResource()->getAttribute($attributeCode);
                if ($attribute->usesSource()) {
                    $optionText = $attribute->getSource()->getOptionText($optionId);
                }
                $html .= "<b>" . $attLabel . '</b> : ' . $optionText . '</br>';
            }
        }
        if (array_key_exists('bundle_option', $itemOptions)) {
            $super_att = $itemOptions['bundle_option'];
            $om = \Magento\Framework\App\ObjectManager::getInstance();
			
			$selectionCollection = $product->getTypeInstance(true)
            							->getSelectionsCollection(
					                $product->getTypeInstance(true)->getOptionsIds($product),
               				 $product
			            );
		      $optionsCollection = $product->getTypeInstance(true)
                    ->getOptionsCollection($product);
			 
            foreach ($super_att as $key => $value) {
				 
                foreach ($selectionCollection as $selctopt) {
                    if ($selctopt['option_id'] == $key and $selctopt['selection_id'] == $value) {
                        foreach ($optionsCollection as $options) {
                            if ($options['option_id'] == $key) {
                                $product = $om->create('Magento\Catalog\Model\Product')->load($selctopt['entity_id']);
                                $html .= "<b>" . $options['title'] . '</b> : ' . $product->getName() . '</br>';
                            }
                        }
                    }
                }
            }
        }
        return $html;
    }
	public function getUnitPriceFormat($price)
	{
		$om = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of Object Manager
    	$priceHelper = $om->create('Magento\Framework\Pricing\Helper\Data'); // Instance of Pricing Helper
    	return $priceHelper->currency($price, true, false);
	}
	
}

Spamworldpro Mini