Magento2 addtocart button in the phtml file inside magento

I have a website based on Magento2.2.9 and a cms page created that called in a phtml file.

In that phtml file, I want to have a button to add to the cart for a specific product. However, clicking on the button does not seem to add the item to my cart. I wonder if anyone could suggest changes in the code to make it work.

        get('MagentoCatalogModelProductRepository');
            $product = $productRepository->get($sku);
            $productid = $product->getId();
            $cartHelper = $this->helper('MagentoCheckoutHelperCart');
            $addToCartUrl = $cartHelper->getAddUrl($product);

            $postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
            $postData = $postDataHelper->getPostData($block->getAddToCartUrl($product), ('product' => $productid))
        ?>

    
getBlockHtml('formkey')?>

magento2: the image is not shown in the interface when we call the phtml file on the CMS page

My requirement is to create a slider without using the extension. So I created a phtml file with the html code and the slider script and called this phtml file on a cms page. But in the interface the images are not shown although the script works.

enter the description of the image here

Could anyone help me, please?

Phtml page adding buttons and pop-up models

Is it possible to add some buttons and once the clicks are used, the popup model created by magento 2 appears?
I want to allow the user to click on a button and show a popup window
I was thinking of adding 2/3 buttons and different content for each popup window

magento2 – Magento 2 setCollection in phtml?

In Magento 1.9, if I want to call another phtml file in current phtml, I could use something like the following.

            /** @var Mage_Catalog_Block_Product_List $productsBlock */
            $productsBlock = $this->getLayout()->createBlock('catalog/product_list');
            $productsBlock->setTemplate('catalog/product/list/summary.phtml');
            $productsBlock->setCollection($itemsByCategory($_category->getId()));
            echo $productsBlock->toHtml();

I wonder if setCollection Are you working on Magento 2?

Because when I use the same code in Magento 2, I receive an error,

Call to a member function count() on null

for the function $_productCollection->count() in the summary.pthml that I am including.

any ideas?

magento2 – How to send data from the cart page (phtml) to the payment page (html) in Magento 2 knockout

I'm doing some calculation for final sale on the cart page that is phtmland I have a show final sale on the payment page as well.

app / design / frontend / Mgs / yx_theme / Magento_Weee / templates / item / price / unit.phtml

The code on the cart page.

getPrice () * $ cartQty) - $ item-> getDiscountAmount ()) / ($ item-> getProduct () -> getPrice () * $ cartQty)) < 0.5): ?>

and I want to send this logic to my payment page.
The problem is the checkout where we show the data is HTML.

app / design / frontend / Mgs / yx_theme / Magento_Checkout / web / template / summary / item / details.html

And the checkout is knockoutjs.
How can I send this logical data to paid html?

Magento 2 Calling widget / template_filter in .phtml

Where is the equivalent way to write the following Magento 1 code to call a custom widget in Magento 2.3.1?

Mage :: getSingleton (& # 39; widget / template_filter & # 39;) -> filter ($ _ product-> getData (& # 39; variants & # 39;))

magento2 – How can I get my driver to return JSON to my PHTML template?

Controller:

resultJsonFactory = $ resultJsonFactory;
}

/ **
* @return  Magento  Framework  Controller  Result  Json
* /
public function run ()
{
/ * Create matrix for return value * /
$ answer['value1'] = "Value one";
$ answer['value2'] = "Value Two";
$ answer['value3'] = "Value Three";

$ resultJson = $ this-> resultFactory-> create (ResultFactory :: TYPE_JSON); // create Json type return object
$ resultJson-> setData ($ response); // array of array values ​​in the Json result data set

returns $ resultJson; // return the json object
}
}

Calling from PHTML:

fetch (& # 39; http: // localhost: 8888 / magento2 / rest / V1 / integration / admin / token & # 39 ;, {
method: & # 39; POST & # 39 ;,
mode: & # 39; cors & # 39 ;,
cache: & # 39; no-cache & # 39 ;,
credentials: & # 39; same origin & # 39 ;,
headers: {
& # 39; Content-Type & # 39 ;: & # 39; application / json & # 39 ;,
}
redirect: & # 39; keep & # 39 ;,
Referent: & # 39; no-referrer & # 39 ;,
body: JSON.stringify ({
"username": "admin",
"password": "admin1@admin.com"
}),
})
.then (response => response.json ())
.then (token => {
(function ($) {
$ .ajax ({
type: "POST",
url: "getUrl (& # 39; * / product & # 39;); ?> ",
Data: dataBody,
Data type: "json",
contentType: "application / json",
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Carrier" + token);
xhr.setRequestHeader ("Content-Type", "application / json");
if (xhr && xhr.overrideMimeType) {
xhr.overrideMimeType ("application / j-son; charset = UTF-8");
}
}
success: function (html) {
console.log ("success:", html);
}
});
}) (jQuery);
});

However, when I try to do this, I can see that the URL is correct but it returns 401 Not authorized

Request URL: http: // localhost: 8888 / magento2 / admin / exampleadminnewpage / product / index / key / bfa7629e0c8323d434158ed68e5dd61f9e0d8ca428f859eb916412c740c89d72 /
Application method: POST
Status code: 401 not authorized

And I can see this error in the debug logs

main.DEBUG: Request validation error for the action "Magento  Framework  App  Action  Forward  Interceptor" [] []

Any idea of ​​what's happening here? I'm new to Magento and PHP.

magento2 – Magento 2 passes data from the html template to the phtml file

file So far I have created MyModule / ProductAlert / view / frontend / email / stock.html






{{template config_path = "design / email / header_template"}}

{{var alertGrid | raw}

{{template config_path = "design / email / footer_template"}}

And I would like to transmit my variables email a .phtml file in
MyModule / ProductAlert / view / frontend / templates / email / stock.phtml and call it there

    

    getProducts ()):?>
        
            

Your e-mail: getData (& # 39; email & # 39;)?>

// Email should be here

Currently, he returns nothing to me. How can I achieve that? Thank you!

magento2 – Unable to find the phtml file of the registration link

I have enabled the suggestion for the route template and it does not show the route for the "Create an account" link.
Reading the source of the html homepage I have seen these tags:


This is the path to the greeting block:

/var/www/vhosts/mysite/httpdocs/vendor/magento/module-theme/view/frontend/templates/html/header.phtml

For the login block:

/var/www/vhosts/mysite/httpdocs/vendor/magento/module-customer/view/frontend/templates/account/link/authorization.phtml

Where is the phtml file & # 39; create an account & # 39; which contains the & # 39; li & # 39 ;?

magento2 – The change in PHTML in the Provider Folder does not affect the interface

I changed the subscribe.phtml in vendor / magento / module-newsletter / view / frontend / templates / subscribe.phtml.
I just changed escapeHtml (__ (& # 39; Subscribe & # 39;))?> A
Test

I clarified everything with:

sudo rm -rf pub / static
sudo rm -rf var / cache
sudo rm -rf var / composer_home
sudo rm -rf var / generation
sudo rm -rf var / page_cache
sudo rm -rf var / view_preprocessed

and then I started installing php bin / magento: static-content: deploy. But nothing changed. Why ? Please help