Adding Widgets to Magento
In "Manage Widgets", you can modify the current configuration of each widget by clicking on them.
Required parameters
1. Username - The username with which the Photoslurp dashboard is accessed.
2. Widget Id - This is the ID of the widget that you have previously created in the Photoslurp dashboard.
3. Page Type - The type of page that you want to embed this widget on. There's 4 options: home, product, category and lookbook.
For widgets whose Page Type has been set to "Product" or "Category" further options to customize the behaviour of the widget exist, in addition to the settings that can be found in the widget editor within the Photoslurp platform:
- Website - If you have multiple websites configured in your Magento store, here you would need to choose which website you would like the widget to be installed in.
- Position - This parameter allows you to choose where on the product or category page you would like the widget to be placed.
- Only Show Media From Product Category – When enabled, this parameter will ensure the widget only returns media linked to other products of the same category when no media is available for the current product.
Product widgets will automatically be added to your product pages. For custom positioning on the product page, please refer to the "Custom Product Page Positioning" below, under Magento 1.
To set the display location of all other widgets head to CMS -> Pages (Magento 1) or Content ->Pages (Magento 2) and select the page that you want to edit. From here, select your platform and choose one of the following options to add our widgets:
Magento 1
Content Field
Click on the Content tab in the left vertical menu. There, you can paste the following code wherever you would like the widget to appear, remembering to replace the ID with the actual ID of the widget as assigned by our module:
{{block type="pswidget/widget" id="7"}}
Page Design
Another method would be to click on the Design tab in the left vertical menu, and insert the following block in the position you would like the widget to show up:
<reference name="content">
<block type="pswidget/widget" name="block-name">
<action method="setId"><value>8</value></action>
</block>
</reference>
Where ‘block-name’ is a unique name you give to this block, and the setId value is the ID of the specific widget you had created earlier (This ID is generated by our Magento module and is unique for each widget created).
Template File
You can also add the widget directly into your template file instead, where you would use the following PHP code to show the specific widget:
<?php echo $this->getLayout()->createBlock('pswidget/widget')->setId('8')->toHtml(); ?>
Where the "id" is the id of the specific widget you had created in our module earlier.
Custom Product Page Positioning
To position widgets in a custom position on the product page, paste the following code into a new file, name it local.xml, and place it in the layout folder of your template (app/frontend/default/your-theme/layout):
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_product_view>
<remove name="pswidget"/>
<reference name="NEW.LOCATION.BLOCK">
<block type="pswidget/widget" template="pswidget/widget.phtml" name="pswidget_custom">
<action method="setId"><value>6</value></action>
</block>
</reference>
</catalog_product_view>
</layout>
Where NEW.LOCATION.BLOCK is the name of the block you would like to move the widget to, and the numeric value for the setId action is the ID of the widget you are moving.
Magento 2
Content Field
Click on the Content tab in the left vertical menu. There, you can paste the following code wherever you would like the widget to appear, remembering to replace the ID with the actual ID of the widget as assigned by our module:
{{block class="Photoslurp\Pswidget\Block\Widget" widget_id="1"}}
Template File
You can also add the widget directly into your template file instead, where you would use the following PHP code to show the specific widget:
<?php echo $block->getLayout()->createBlock('Photoslurp\Pswidget\Block\Widget',
'', ['data' => ['widget_id' => 1,]])->toHtml(); ?>
Where the "id" is the id of the specific widget you had created in our module earlier.