<?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>DEV Community: Dev-Sandbox</title>
    <description>The latest articles on DEV Community by Dev-Sandbox (@devlaravel).</description>
    <link>https://dev.to/devlaravel</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%2F1062171%2F25ad556f-ab0e-4496-b4b0-9d00d151a0a2.png</url>
      <title>DEV Community: Dev-Sandbox</title>
      <link>https://dev.to/devlaravel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devlaravel"/>
    <language>en</language>
    <item>
      <title>Bigcommerce Widget Migration</title>
      <dc:creator>Dev-Sandbox</dc:creator>
      <pubDate>Sun, 31 Dec 2023 10:17:00 +0000</pubDate>
      <link>https://dev.to/devlaravel/bigcommerce-widget-migration-50ib</link>
      <guid>https://dev.to/devlaravel/bigcommerce-widget-migration-50ib</guid>
      <description>&lt;p&gt;Hi Everyone,&lt;br&gt;
In BigCommerce, currently there is no option to move the widgets from one store to another store. This will be a big problem in the case of having the staging and production account.&lt;/p&gt;

&lt;p&gt;I am having a partial automated and partial manual solution for this.&lt;/p&gt;

&lt;p&gt;The below is a postman script which needs the below inputs. These inputs can be set in the environment variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Env Variables&lt;/strong&gt;&lt;br&gt;
source_widget_template_id&lt;br&gt;
source_template_file&lt;br&gt;
source_store_hash&lt;br&gt;
source_access_token&lt;br&gt;
destination_widget_template_id&lt;br&gt;
destination_template_file&lt;br&gt;
destination_store_hash&lt;br&gt;
destination_access_token&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code(Put in the "Tests" tab in Postman).&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Get Source Placement
const sourceWidgetRequest = {
  url: 'https://api.bigcommerce.com/stores/'+pm.environment.get('source_store_hash')+'/v3/content/placements?template_file='+pm.environment.get('source_template_file')+'&amp;amp;widget_template_uuid='+pm.environment.get('source_widget_template_id'),
  method: 'GET',
  header: {
    'Content-Type': 'application/json',
    'X-AUTH-TOKEN': pm.environment.get('source_access_token')
  }
};

const destinationWidgetRequest = {
  url: 'https://api.bigcommerce.com/stores/'+pm.environment.get('destination_store_hash')+'/v3/content/placements?template_file='+pm.environment.get('destination_template_file')+'&amp;amp;widget_template_uuid='+pm.environment.get('destination_widget_template_id'),
  method: 'GET',
  header: {
    'Content-Type': 'application/json',
    'X-AUTH-TOKEN': pm.environment.get('destination_access_token')
  }
};

let widgetUpdateRequest = {
  url: 'https://api.bigcommerce.com/stores/'+pm.environment.get('destination_store_hash')+'/v3/content/widgets',
  method: 'PUT',
  header: {
    'Content-Type': 'application/json',
    'X-AUTH-TOKEN': pm.environment.get('destination_access_token')
  }
};


pm.sendRequest(sourceWidgetRequest, (srcError, srcResponse) =&amp;gt; {
    if(srcError){
        console.log("srcError", srcError);
    }else{
        // Get the widget configuration.
        let srcWidgetResponse = srcResponse.json();
        console.log(srcWidgetResponse.data);
        if(srcWidgetResponse.data.length &amp;gt; 0){
            let srcWidgetConfiguration = srcWidgetResponse.data[0].widget.widget_configuration;
            console.log("source_widget_configuration",srcWidgetConfiguration);

            // Get Destination Placement.
            pm.sendRequest(destinationWidgetRequest, (destError, destResponse) =&amp;gt; {
                if(destError){
                    console.log("destError", destError);
                }else{

                    let destWidgetResponse = destResponse.json();
                    console.log(destWidgetResponse.data);
                    if(destWidgetResponse.data.length &amp;gt; 0){
                        let destWidgetConfiguration = destWidgetResponse.data[0].widget.widget_configuration;
                        console.log("destination_widget_configuration_id",destWidgetConfiguration._.id);
                        widgetUpdateRequest.url = widgetUpdateRequest.url+"/"+destWidgetConfiguration._.id;
                        delete srcWidgetConfiguration._;
                        widgetUpdateRequest.body= {
                            mode: 'raw',
                            raw: JSON.stringify({ "widget_configuration": srcWidgetConfiguration,"upgrade": true })
                        };
                        console.log("final_update", widgetUpdateRequest);

                        pm.sendRequest(widgetUpdateRequest, (finalError, finalResponse) =&amp;gt; {
                            if(finalError){
                                console.log("finalError",finalError);
                            }else{
                                console.log("update_done", finalResponse);
                            }
                        });
                    }
                }
            });

        }
    }
});

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

&lt;/div&gt;



&lt;p&gt;Once setting up the script and the environment variables the widget configuration will be copied from source to the destination store.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before running the script,&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Widget template must be created in the destination store.&lt;/li&gt;
&lt;li&gt;Wherever needed, the widget template must be dragged and dropped in the page and published from page builder.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;CORE ALGORITHM FOR SCRIPT&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Get the placements using source widget template id and the source template file.&lt;/li&gt;
&lt;li&gt;In this, we will get the widget configuration configured for the widget template file in that specific template.&lt;/li&gt;
&lt;li&gt;Get the placements using destination widget template id and the destination template file.&lt;/li&gt;
&lt;li&gt;In this get the destination widget id.&lt;/li&gt;
&lt;li&gt;Update the source widget configuration in destination widget.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Open for any suggestions for upgradation or any ideas. Thanks.&lt;br&gt;
Happy Hacking :)&lt;/p&gt;

</description>
      <category>bigcommerce</category>
      <category>widget</category>
      <category>pagebuilder</category>
      <category>migration</category>
    </item>
    <item>
      <title>FPUTCSV Custom Function</title>
      <dc:creator>Dev-Sandbox</dc:creator>
      <pubDate>Wed, 24 May 2023 07:10:12 +0000</pubDate>
      <link>https://dev.to/devlaravel/fputcsv-custom-function-522h</link>
      <guid>https://dev.to/devlaravel/fputcsv-custom-function-522h</guid>
      <description>&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;br&gt;
Values Surrounded by Double Quotes Always.&lt;br&gt;
Escape Character is &lt;strong&gt;"&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;CR+LF&lt;/strong&gt; is the newline&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fputcsv_custom($stream, $fields, $delimiter = ",", $enclosure = '"', $escape_char = '\"', $eol = "\r\n") {
    $field_arr = [];

    foreach($fields as $field) {
        $field_arr[] = $enclosure . stripslashes(str_replace($enclosure, $escape_char . $enclosure, $field)) . $enclosure;
    }

    fwrite($stream, implode($delimiter, $field_arr) . $eol);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ref: &lt;a href="https://stackoverflow.com/questions/16942531/alternative-to-fputcsv/66682050#66682050"&gt;https://stackoverflow.com/questions/16942531/alternative-to-fputcsv/66682050#66682050&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>fputcsv</category>
    </item>
    <item>
      <title>Analytics/ Tracking</title>
      <dc:creator>Dev-Sandbox</dc:creator>
      <pubDate>Thu, 18 May 2023 05:31:43 +0000</pubDate>
      <link>https://dev.to/devlaravel/analytics-tracking-26ae</link>
      <guid>https://dev.to/devlaravel/analytics-tracking-26ae</guid>
      <description>&lt;p&gt;&lt;strong&gt;Scenario Needed&lt;/strong&gt;: Get Order, Customer Details on Order Confirmation Page&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We don't have separated firstname and lastname in stencil.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
If &lt;strong&gt;customerId: 0&lt;/strong&gt;&lt;br&gt;
    Get the customer details from Billing address&lt;br&gt;
        &lt;strong&gt;2 scenarios&lt;/strong&gt;&lt;br&gt;
        - &lt;strong&gt;Already customer present&lt;/strong&gt;, he chose to have the first name.&lt;br&gt;
        - &lt;strong&gt;New customer&lt;/strong&gt;, we only have his info via the Billing address. So we will get this from Billing Address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If Customer is logged in&lt;/strong&gt; - Get via Graphql.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query Customer {
  customer {
    firstName
    lastName
    email
    entityId
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>bigcommerce</category>
    </item>
    <item>
      <title>BigCommerce New Store</title>
      <dc:creator>Dev-Sandbox</dc:creator>
      <pubDate>Mon, 10 Apr 2023 05:05:31 +0000</pubDate>
      <link>https://dev.to/devlaravel/bigcommerce-new-store-1hjd</link>
      <guid>https://dev.to/devlaravel/bigcommerce-new-store-1hjd</guid>
      <description>&lt;p&gt;Hey guys,&lt;br&gt;
We are going to look into a super simple task of creating &lt;a href="https://manage.bigcommerce.com/account/stores/new"&gt;New Store&lt;/a&gt;. It can be super easy by filling all the details here. And boom, we now have the new store and an confirmation email that the store has been created.&lt;/p&gt;

&lt;p&gt;Enjoy Folks.&lt;/p&gt;

</description>
      <category>bigcommerce</category>
      <category>ownerseries</category>
      <category>howto</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
