monsoonconsulting / magento2-hyva-ajax-add-to-cart

Adds Ajax Add to Cart functionality to Hyva themes
Open Software License 3.0
40 stars 5 forks source link

Block missing function for feature enabled #23

Open vchiriacmoldoweb opened 9 months ago

vchiriacmoldoweb commented 9 months ago

Describe the bug

Expected behavior

So this becomes a problem when you are trying to call the window.setAjaxCart(); based on ajax related results, you need to create a new block that extends AddToCart in order to include that function, all this just in order to have the check if the feature is enabled.

vchiriacmoldoweb commented 8 months ago

@callanzimmermann

any chance you can include these functions changes in the block:

private $storeManager;

    /**
     * AddToCart constructor
     *
     * @param Template\Context $context
     * @param ConfigInterface $config
     * @param array $data
     */
    public function __construct(
        Template\Context $context,
        private readonly ConfigInterface $config,
        array $data = []
    ) {
        parent::__construct($context, $config, $data);
        $this->storeManager = $context->getStoreManager();
    }

    /**
     * @return StoreManagerInterface
     */
    public function getStoreManager()
    {
        return $this->storeManager;
    }

    /**
     * If the cart should open after adding to cart
     *
     * @param null $scopeCode
     * @return bool
     */
    public function isAjaxAddToCartEnabled($scopeCode = null): bool
    {
        return $this->config->isAjaxAddToCartEnabled($scopeCode);
    }