<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Bruno</title>
    <description>The latest articles on Forem by Bruno (@elisei).</description>
    <link>https://forem.com/elisei</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F819561%2Fddc1e74f-7498-43a0-bceb-e8e49e5edb42.jpeg</url>
      <title>Forem: Bruno</title>
      <link>https://forem.com/elisei</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/elisei"/>
    <language>en</language>
    <item>
      <title>Personalizando o módulo da Stape.io para Magento 2</title>
      <dc:creator>Bruno</dc:creator>
      <pubDate>Fri, 26 Apr 2024 16:51:08 +0000</pubDate>
      <link>https://forem.com/elisei/personalizando-o-modulo-da-stapeio-para-magento-2-1h9g</link>
      <guid>https://forem.com/elisei/personalizando-o-modulo-da-stapeio-para-magento-2-1h9g</guid>
      <description>&lt;p&gt;Olarf!&lt;/p&gt;

&lt;p&gt;Vou dar o papo de como personalizar esse cara &lt;a href="https://github.com/stape-io/gtm-server-side-magento-module"&gt;aqui&lt;/a&gt; para colocar dados específicos!&lt;/p&gt;

&lt;p&gt;Bom isso foi necessário porque a loja tem atributos muito relevantes para o mkt mas que não são capturados por padrão, o dramalhão é o seguinte:&lt;/p&gt;

&lt;p&gt;O tipo da pedra é muito relevante, além disso o formato do cristal também é essencial.&lt;/p&gt;

&lt;p&gt;Imagina assim, faz mkt de um anel (o formato) para alguém que tá buscando pedra bruta, não vai funfar bem né? então por isso vamos lá, já parando de enrolar!&lt;/p&gt;

&lt;p&gt;A primeira treta é que os gringos do módulo só conhecem funções do tipo privado o.O &lt;/p&gt;

&lt;p&gt;E aí lá vou eu abrir a PR e esperar ela entrar! tranquilis, &lt;a href="https://github.com/stape-io/gtm-server-side-magento-module/pull/14"&gt;aceitaram!&lt;/a&gt; e eu também aproveitei para fazer o módulo parar de quebrar o layout. de nada!&lt;/p&gt;

&lt;p&gt;Mas agora com o módulo atualizado é hora de partir para os plugins o que é doce doce, não vou detalhar todos porque senão vai ter gente me criticando (e vão tbm por não detalhar), mas então pega o que quero dizer:&lt;/p&gt;

&lt;p&gt;1º Informar quais os atributos vão estar visíveis ao catálogo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd"&amp;gt;
    &amp;lt;group name="quote_item"&amp;gt;
        &amp;lt;attribute name="tipo_de_pedra"/&amp;gt;
        &amp;lt;attribute name="formato_do_cristal"/&amp;gt;
    &amp;lt;/group&amp;gt;
    &amp;lt;group name="order_item"&amp;gt;
        &amp;lt;attribute name="tipo_de_pedra"/&amp;gt;
        &amp;lt;attribute name="formato_do_cristal"/&amp;gt;
    &amp;lt;/group&amp;gt;
&amp;lt;/config&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/elisei/extend-stape/blob/main/etc/catalog_attributes.xml"&gt;veja aqui&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2º pegar esse monte de classes para fazer o plugin de fato:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"&amp;gt;

    &amp;lt;type name="Stape\Gtm\ViewModel\Category"&amp;gt;
        &amp;lt;plugin name="add_custom_item_data" type="O2TI\ExtendedStape\Plugin\Stape\ViewModel\CategoryPlugin" sortOrder="1" /&amp;gt;
    &amp;lt;/type&amp;gt;

    &amp;lt;type name="Stape\Gtm\ViewModel\Cart"&amp;gt;
        &amp;lt;plugin name="add_custom_item_data" type="O2TI\ExtendedStape\Plugin\Stape\ViewModel\CartPlugin" sortOrder="1" /&amp;gt;
    &amp;lt;/type&amp;gt;

    &amp;lt;type name="Stape\Gtm\ViewModel\Checkout"&amp;gt;
        &amp;lt;plugin name="add_custom_item_data" type="O2TI\ExtendedStape\Plugin\Stape\ViewModel\CheckoutPlugin" sortOrder="1" /&amp;gt;
    &amp;lt;/type&amp;gt;

    &amp;lt;type name="Stape\Gtm\ViewModel\Product"&amp;gt;
        &amp;lt;plugin name="add_custom_item_data" type="O2TI\ExtendedStape\Plugin\Stape\ViewModel\ProductPlugin" sortOrder="1" /&amp;gt;
    &amp;lt;/type&amp;gt;

    &amp;lt;type name="Stape\Gtm\ViewModel\Success"&amp;gt;
        &amp;lt;plugin name="add_custom_item_data" type="O2TI\ExtendedStape\Plugin\Stape\ViewModel\SuccessPlugin" sortOrder="1" /&amp;gt;
    &amp;lt;/type&amp;gt;

    &amp;lt;preference for="Magento\Checkout\CustomerData\DefaultItem"
            type="O2TI\ExtendedStape\Plugin\Magento\Checkout\CustomerData\DefaultItemPlugin"/&amp;gt;

    &amp;lt;type name="O2TI\ExtendedStape\Plugin\Magento\Checkout\CustomerData\DefaultItemPlugin"&amp;gt;
        &amp;lt;arguments&amp;gt;
            &amp;lt;argument name="attributeRepository" xsi:type="object"&amp;gt;Magento\Catalog\Api\ProductAttributeRepositoryInterface&amp;lt;/argument&amp;gt;
        &amp;lt;/arguments&amp;gt;
    &amp;lt;/type&amp;gt;


&amp;lt;/config&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/elisei/extend-stape/blob/main/etc/di.xml"&gt;Veja aqui&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3º E então lá  vai um around nesse trem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace O2TI\ExtendedStape\Plugin\Stape\ViewModel;

use Stape\Gtm\ViewModel\Cart as ViewModelCart;
use O2TI\ExtendedStape\Helper\Data;

class CartPlugin
{
    /**
     * @var Data
     */
    protected $helper;

    /**
     * Define class dependencies
     *
     * @param Data $helper
     */
    public function __construct(
        Data $helper
    ) {
        $this-&amp;gt;helper = $helper;
    }

    /**
     * Plugin method to enhance prepareItems functionality
     *
     * @param ViewModelCart $subject
     * @param callable $proceed
     * @param \Magento\Quote\Model\Quote $quote
     * @return array
     */
    public function aroundPrepareItems(ViewModelCart $subject, callable $proceed, \Magento\Quote\Model\Quote $quote)
    {
        $items = $proceed($quote);

        $itemData = [];

        /** @var \Magento\Quote\Model\Quote\Item $item */
        foreach ($quote-&amp;gt;getAllVisibleItems() as $item) {

            $tipoPedraValue = $item-&amp;gt;getProduct()-&amp;gt;getTipoDePedra();
            $tipoPedraLabel = $this-&amp;gt;helper-&amp;gt;getAttributeOptions('tipo_de_pedra', $tipoPedraValue);

            $formatoValue = $item-&amp;gt;getProduct()-&amp;gt;getFormatoDoCristal();
            $formatoLabel = $this-&amp;gt;helper-&amp;gt;getAttributeOptions('formato_do_cristal', $formatoValue);

            $itemData[$item-&amp;gt;getProductId()] = [
                'item_tipo_de_pedra' =&amp;gt; $tipoPedraLabel,
                'item_formato_do_cristal' =&amp;gt; $formatoLabel,
            ];
        }

        foreach ($items as $key =&amp;gt; $item) {
            $itemId = $item['item_id'];

            if (isset($itemData[$itemId])) {
                $items[$key] = array_merge($item, $itemData[$itemId]);
            }
        }

        return $items;
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/elisei/extend-stape/tree/main/Plugin"&gt;Melhor ver todos as classes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Detalhando:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/elisei/extend-stape/blob/main/Plugin/Stape/ViewModel/CartPlugin.php#L36"&gt;pega a saída original com os outros detalhes dos itens&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/elisei/extend-stape/blob/main/Plugin/Stape/ViewModel/CartPlugin.php#L41-L53"&gt;faz um laço para pegar os nossos atributos especiais e coloca no array&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/elisei/extend-stape/blob/main/Plugin/Stape/ViewModel/CartPlugin.php#L58"&gt;agora é só achar o item do original e pronto!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;prontinho?&lt;/p&gt;

&lt;p&gt;Sim, agora o amadinho do cara de mkt tem os dados necessários para ser um pokémon!&lt;/p&gt;

&lt;p&gt;Página de produto:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fti165jk90p831kqkq3ag.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fti165jk90p831kqkq3ag.png" alt="Image description" width="800" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Página de categoria:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjf1wu7twcvlh5b5nf7n9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjf1wu7twcvlh5b5nf7n9.png" alt="Image description" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Página de sucesso:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fur1mmtryv6pfpxptowe5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fur1mmtryv6pfpxptowe5.png" alt="Image description" width="800" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;e tem outras mas eu cansei, adeus!&lt;/p&gt;

</description>
      <category>pt</category>
      <category>braziliandevs</category>
      <category>magento</category>
    </item>
  </channel>
</rss>
