Commit c0c706fc by halweg

size chart

parent 69ccafdb
<?php
namespace Magepow\Sizechart\Api\Data;
interface SizechartInterface
{
const ENTITY_ID = 'entity_id';
const CATEGORY_ID = 'category_id';
const SUB_CATEGORY_ID = 'sub_category_id';
const TYPE_DISPLAY = 'type_display';
const IS_ACTIVE = 'is_active';
const DESCRIPTION = 'description';
const SIZECHART_INFO = 'sizechart_info';
const UPDATED_AT = 'updated_at';
const CREATED_AT = 'created_at';
const TEMPLATE_CSS = 'template_css';
const CONDITIONS = 'conditions_serialized';
const STORE = 'stores';
public function getEntityId();
public function setEntityId($entityId);
public function getCategoryId();
public function setCategoryId($categoryId);
public function getSubCategoryId();
public function setSubCategoryId($subCategoryId);
public function getIsActive();
public function setIsActive($isActive);
public function getTypeDisplay();
public function setTypeDisplay($typeDisplay);
public function getDescription();
public function setDescription($description);
public function getSizeChartInfo();
public function setSizeChartInfo($sizeChartInfo);
public function getUpdatedAt();
public function setUpdatedAt($updatedAt);
public function getCreatedAt();
public function setCreatedAt($createdAt);
public function getTemplateCss();
public function setTemplateCss($templateCss);
public function getConditions();
public function setConditions($conditions);
public function getStoreView();
public function setStoreView($stores);
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Block\Adminhtml\Sizechart;
class AddRow extends \Magento\Backend\Block\Widget\Form\Container
{
protected $_coreRegistry = null;
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry,
array $data = []
) {
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}
protected function _construct()
{
$this->_objectId = 'row_id';
$this->_blockGroup = 'Magepow_Sizechart';
$this->_controller = 'adminhtml_sizechart';
parent::_construct();
if ($this->_isAllowedAction('Magepow_Sizechart::add_row')) {
$this->buttonList->update('save', 'label', __('Save'));
$this->buttonList->add(
'saveandcontinue',
[
'label' => __('Save and Continue Edit'),
'class' => 'save',
'data_attribute' => [
'mage-init' => [
'button' => [
'event' => 'saveAndContinueEdit',
'target' => '#edit_form'
]
]
]
]
);
} else {
$this->buttonList->remove('save');
}
// $this->buttonList->remove('reset');
}
public function getHeaderText()
{
return __('Add Size Chart Rule');
}
protected function _isAllowedAction($resourceId)
{
return $this->_authorization->isAllowed($resourceId);
}
public function getFormActionUrl()
{
if ($this->hasFormActionUrl()) {
return $this->getData('form_action_url');
}
return $this->getUrl('*/*/save');
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Block\Adminhtml\Sizechart;
use Joshine\Review\Model\Repository\VoteRepository;
use Magento\Framework\View\Element\Template;
use Magepow\Sizechart\Model\SizechartFactory;
class ChartTable extends Template
{
protected $_template = 'Magepow_Sizechart::chartTable.phtml';
/**
* @var SizechartFactory
*/
private $chartFactory;
public function __construct(
Template\Context $context,
SizechartFactory $chartFactory,
array $data = []
) {
$this->chartFactory = $chartFactory;
parent::__construct($context, $data);
}
public function getCustomSizeData()
{
$id = $this->getRequest()->getParam('id');
if (!$id) {
return [];
}
return $this->chartFactory->create()->load($id);
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Block\Adminhtml\Sizechart;
use Magento\Framework\View\Element\Template;
use Magepow\Sizechart\Model\SizechartFactory;
class ColumLabel extends Template
{
protected $_template = 'Magepow_Sizechart::columnLabel.phtml';
/**
* @var SizechartFactory
*/
private $chartFactory;
public function __construct(
Template\Context $context,
SizechartFactory $chartFactory,
array $data = []
) {
$this->chartFactory = $chartFactory;
parent::__construct($context, $data);
}
public function getCustomSizeData()
{
$id = $this->getRequest()->getParam('id');
if (!$id) {
return [];
}
return $this->chartFactory->create()->load($id);
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Block\Adminhtml\Sizechart\Edit;
class Form extends \Magento\Backend\Block\Widget\Form\Generic
{
/**
* Prepare form.
*
* @return $this
*/
protected function _prepareForm()
{
$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
$model = $this->_coreRegistry->registry('row_data');
$form = $this->_formFactory->create(
[
'data' => [
'id' => 'edit_form',
'enctype' => 'multipart/form-data',
'action' => $this->getData('action'),
'method' => 'post'
]
]
);
$form->setValues($model->getData());
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Block\Adminhtml\Sizechart\Edit\Tab;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;
class Condition extends Generic implements TabInterface
{
protected $_renderFieldSet;
protected $_conditions;
protected $_ruleFactory;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Store\Model\System\Store $systemStore,
\Magento\Framework\ObjectManagerInterface $objectManager,
\Magento\Rule\Block\Conditions $conditions,
\Magento\CatalogWidget\Model\RuleFactory $ruleFactory,
\Magento\Backend\Block\Widget\Form\Renderer\Fieldset $rendererFieldset,
array $data = []
) {
$this->_conditions = $conditions;
$this->_ruleFactory = $ruleFactory;
$this->_renderFieldSet = $rendererFieldset;
parent::__construct($context, $registry, $formFactory, $data);
}
protected function _prepareForm()
{
$model = $this->_coreRegistry->registry('row_data');
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('wkgrid_');
$fieldsetId = 'conditions_fieldset';
$formName = 'catalog_rule_form';
$widgetParameters = $model->getParameters();
$modelConditions = $this->_ruleFactory->create();
if (is_array($widgetParameters)) {
$modelConditions->loadPost($widgetParameters);
$modelConditions->getConditions()->setJsFormObject($fieldsetId);
}
$newChildUrl = $this->getUrl(
'catalog_rule/promo_catalog/newConditionHtml/form/' . $fieldsetId,
['form_namespace' => $fieldsetId]
);
$renderer = $this->_renderFieldSet->setTemplate('Magento_CatalogRule::promo/fieldset.phtml')
->setNewChildUrl($newChildUrl)
->setFieldSetId($fieldsetId);
$fieldset = $form->addFieldset(
$fieldsetId,
['legend' => __('Conditions (don\'t add conditions if rule is applied to all products)')]
)->setRenderer($renderer);
$fieldset->addField(
'conditions',
'text',
[
'name' => 'conditions',
'label' => __('Conditions'),
'title' => __('Conditions'),
'required' => false,
'data-form-parts' => $formName
]
)->setRule($modelConditions)->setRenderer($this->_conditions);
$form->setValues($model->getData());
$this->setForm($form);
return parent::_prepareForm();
}
public function getTabLabel()
{
return __('Condition apply for products');
}
public function getTabTitle()
{
return __('Condition apply for products');
}
/**
* Can show tab in tabs
*
* @return boolean
* @api
*/
public function canShowTab()
{
return true;
}
/**
* Tab is hidden
*
* @return boolean
* @api
*/
public function isHidden()
{
return false;
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Block\Adminhtml\Sizechart\Edit\Tab;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magepow\Sizechart\Block\Adminhtml\Sizechart\ChartTable;
use Magepow\Sizechart\Block\Adminhtml\Sizechart\CustomerSize;
use Magepow\Sizechart\Block\Adminhtml\Sizechart\Field\FieldChartTable;
use Magepow\Sizechart\Block\Adminhtml\Sizechart\Field\FieldColumnLabel;
class Main extends Generic implements TabInterface
{
protected $_systemStore;
protected $_objectManager;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Framework\ObjectManagerInterface $objectManager,
\Magepow\Sizechart\Model\Status $options,
\Magento\Store\Model\System\Store $systemStore,
\Magepow\Sizechart\Model\TypeDisplay $typeDisplay,
array $data = []
) {
$this->_systemStore = $systemStore;
$this->_options = $options;
$this->_wysiwygConfig = $wysiwygConfig;
$this->_typeDisplay = $typeDisplay;
$this->_systemStore = $systemStore;
$this->_objectManager = $context->getStoreManager();
parent::__construct($context, $registry, $formFactory, $data);
}
protected function _prepareForm()
{
$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
$model = $this->_coreRegistry->registry('row_data');
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('wkgrid_');
if ($model->getEntityId()) {
$fieldset = $form->addFieldset(
'base_fieldset',
['legend' => __('Edit Size Chart Rule'), 'class' => 'fieldset-wide']
);
// $fieldset->addField('entity_id', 'hidden', ['name' => 'entity_id']); // not use will conflict entity_id ofcondition product
$fieldset->addField('sizechart_id', 'hidden', ['name' => 'sizechart_id']);
} else {
$fieldset = $form->addFieldset(
'base_fieldset',
['legend' => __('Add Size Chart Rule'), 'class' => 'fieldset-wide']
);
}
$fieldset->addField(
'name',
'text',
[
'name' => 'name',
'label' => __('Name'),
'id' => 'name',
'title' => __('Name'),
'class' => 'required_entry',
'required' => true,
]
);
if (!$this->_storeManager->isSingleStoreMode()) {
$field = $fieldset->addField(
'stores',
'multiselect',
[
'name' => 'stores[]',
'label' => __('Store View'),
'title' => __('Store View'),
'required' => true,
'values' => $this->_systemStore->getStoreValuesForForm(false, true)
]
);
$renderer = $this->getLayout()->createBlock(
'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element'
);
$field->setRenderer($renderer);
} else {
$fieldset->addField(
'stores',
'hidden',
['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()]
);
$model->setStoreId($this->_storeManager->getStore(true)->getId());
}
$fieldset->addField(
'description',
'textarea',
[
'name' => 'description',
'label' => __('Description'),
'id' => 'description',
'title' => __('Description'),
'style' => 'height:10em',
'required' => false,
]
);
$wysiwygConfig = $this->_wysiwygConfig->getConfig(['tab_id' => $this->getTabId()]);
$fieldset->addField(
'sizechart_info',
'editor',
[
'name' => 'sizechart_info',
'label' => __('Size Chart Information'),
'required' => true,
'config' => $wysiwygConfig
]
);
$fieldset->addType(
'column_label',
FieldColumnLabel::class
);
$fieldset->addType(
'chart_table',
FieldChartTable::class
);
$fieldset->addField(
'column_label',
'column_label',
[
'name' => 'column_label',
'label' => __('Column Label'),
'id' => 'column_label',
'title' => __('Column Label'),
'required' => true,
]
);
$fieldset->addField(
'chart_table',
'chart_table',
[
'name' => 'chart_table',
'label' => __('Chart Table'),
'id' => 'chart_table',
'title' => __('Chart Table'),
'required' => false,
]
);
$fieldset->addField(
'type_display',
'select',
[
'name' => 'type_display',
'label' => __('Type Display'),
'id' => 'type_display',
'title' => __('Type Display'),
'values' => $this->_typeDisplay->getOptionArray(),
'required' => true,
]
);
$fieldset->addField(
'is_active',
'select',
[
'name' => 'is_active',
'label' => __('Status'),
'id' => 'is_active',
'title' => __('Status'),
'values' => $this->_options->getOptionArray(),
'value' => 1,
'required' => true,
]
);
$form->addValues($model->getData());
$this->setForm($form);
return parent::_prepareForm();
}
public function getTabLabel()
{
return __('General Information');
}
public function getTabTitle()
{
return __('General Information');
}
/**
* Can show tab in tabs
*
* @return boolean
* @api
*/
public function canShowTab()
{
return true;
}
/**
* Tab is hidden
*
* @return boolean
* @api
*/
public function isHidden()
{
return false;
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Block\Adminhtml\Sizechart\Edit;
use Magento\Backend\Block\Widget\Tabs as WidgetTabs;
class Tabs extends WidgetTabs
{
/**
* Class constructor
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('sizechart_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(__('Size Chart Information'));
}
/**
* @return $this
*/
protected function _beforeToHtml()
{
$this->addTab(
'main_section',
[
'label' => __('General Information'),
'title' => __('General Information'),
'content' => $this->getLayout()->createBlock(
'Magepow\Sizechart\Block\Adminhtml\Sizechart\Edit\Tab\Main'
)->toHtml(),
]
);
$this->addTab(
'category',
[
'label' => __('Condition apply for products'),
'title' => __('Condition apply for products'),
'content' => $this->getLayout()->createBlock(
'Magepow\Sizechart\Block\Adminhtml\Sizechart\Edit\Tab\Condition'
)->toHtml(),
]
);
return parent::_beforeToHtml();
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Block\Adminhtml\Sizechart\Field;
use Magento\Framework\Escaper;
use Magepow\Sizechart\Block\Adminhtml\Sizechart\ChartTable;
class FieldChartTable extends \Magento\Framework\Data\Form\Element\AbstractElement
{
protected $_blockFactory;
public function __construct(
\Magento\Framework\Data\Form\Element\Factory $factoryElement,
\Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection,
Escaper $escaper,
\Magento\Framework\View\Element\BlockFactory $_blockFactory,
$data = []
) {
$this->_blockFactory = $_blockFactory;
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
}
/**
* Get the after element html.
*
* @return mixed
*/
public function getElementHtml() {
$customDiv = $this->_blockFactory
->createBlock(ChartTable::class)
->toHtml();
return $customDiv;
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Block\Adminhtml\Sizechart\Field;
use Magento\Framework\Escaper;
use Magepow\Sizechart\Block\Adminhtml\Sizechart\ChartTable;
use Magepow\Sizechart\Block\Adminhtml\Sizechart\ColumLabel;
class FieldColumnLabel extends \Magento\Framework\Data\Form\Element\AbstractElement
{
protected $_blockFactory;
public function __construct(
\Magento\Framework\Data\Form\Element\Factory $factoryElement,
\Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection,
Escaper $escaper,
\Magento\Framework\View\Element\BlockFactory $_blockFactory,
$data = []
) {
$this->_blockFactory = $_blockFactory;
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
}
/**
* Get the after element html.
*
* @return mixed
*/
public function getElementHtml() {
$customDiv = $this->_blockFactory
->createBlock(ColumLabel::class)
->toHtml();
return $customDiv;
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Block\Product;
class Sizechart extends \Magento\Catalog\Block\Product\AbstractProduct
{
/**
* Product collection factory
*
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
*/
protected $_ruleFactory;
/**
* Product collection factory
*
* @var \Magiccart\Magicproduct\Model\Magicproduct
*/
protected $_sizechartFactory;
protected $_limit; // Limit Product
protected $_parameters; // Condition Product
protected $_request;
protected $_abstractProduct;
protected $json;
protected $_filter;
/**
* @param Context $context
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
* @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility
* @param array $data
*/
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\CatalogWidget\Model\RuleFactory $ruleFactory,
\Magepow\Sizechart\Model\SizechartFactory $sizechartFactory,
\Magepow\Sizechart\Serialize\Serializer\Json $json,
\Magento\Cms\Model\Template\FilterProvider $filter,
array $data = []
) {
$this->_ruleFactory = $ruleFactory;
$this->_filter = $filter;
$this->json = $json;
$this->_sizechartFactory = $sizechartFactory;
parent::__construct($context, $data);
}
public function getSizeChartCollection()
{
$store = $this->_storeManager->getStore()->getStoreId();;
$collection = $this->_sizechartFactory->create()->getCollection()
->addFieldToSelect('*')
->addFieldToFilter('is_active', 1)
->addFieldToFilter('stores', array(array('finset' => 0), array('finset' => $store)))
->setOrder('sort_order', 'ASC');
return $collection;
}
public function getSizeChart()
{
if (!$this->hasData('size_chart')) {
$collection = $this->getSizeChartCollection();
$product = $this->getProduct();
$sizeChart = '';
foreach ($collection as $item) {
$config = $item->getConditionsSerialized();
$data = $this->json->unserialize($config);
$parameters = $data['parameters'];
$rule = $this->getRule($parameters);
$validate = $rule->getConditions()->validate($product);
if ($validate) {
$sizeChart = $item;
break;
}
}
$this->setData('size_chart', $sizeChart);
}
return $this->getData('size_chart');
}
public function getContentFromStaticBlock($content)
{
return $this->_filter->getBlockFilter()->filter($content);
}
public function getClass($typeDisplay)
{
$type = 'sizechart-customtab';
if ($typeDisplay == 1) {
$type = 'sizechart-inline';
} elseif ($typeDisplay == 2) {
$type = 'sizechart-popup';
}
return $type;
}
protected function getRule($conditions)
{
$rule = $this->_ruleFactory->create();
if (is_array($conditions)) $rule->loadPost($conditions);
return $rule;
}
public function getMedia($img = null)
{
$urlMedia = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
if ($img) return $urlMedia . "magepow/sizechart/" . $img;
return $urlMedia;
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Controller\Adminhtml;
abstract class Action extends \Magento\Backend\App\Action
{
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $coreRegistry = null;
/**
* @var \Magento\Framework\App\Response\Http\FileFactory
*/
protected $fileFactory;
/**
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
*/
protected $dateFilter;
protected $_sizechartFactory;
/**
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
\Magepow\Sizechart\Model\SizechartFactory $sizechartFactory,
\Psr\Log\LoggerInterface $logger
) {
parent::__construct($context);
$this->coreRegistry = $coreRegistry;
$this->fileFactory = $fileFactory;
$this->dateFilter = $dateFilter;
$this->_sizechartFactory = $sizechartFactory;
$this->logger = $logger;
}
/**
* Initiate rule
*
* @return void
*/
protected function _initRule()
{
$rule = $this->_sizechartFactory->create();
$id = (int)$this->getRequest()->getParam('id');
if (!$id && $this->getRequest()->getParam('entity_id')) {
$id = (int)$this->getRequest()->getParam('entity_id');
}
}
protected function _initAction()
{
$this->_view->loadLayout();
$this->_setActiveMenu('Magepow_Sizechart::magepow_sizechart')
->_addBreadcrumb(__('Magepow Sizechart'), __('Magepow Sizechart'));
return $this;
}
/**
* Returns result of current user permission check on resource and privilege
*
* @return bool
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Magepow_Sizechart::sizechart');
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Controller\Adminhtml\Sizechart;
use Magento\Framework\Controller\ResultFactory;
class AddRow extends \Magento\Backend\App\Action
{
private $coreRegistry;
private $sizechartFactory;
protected $json;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magepow\Sizechart\Model\SizechartFactory $sizechartFactory,
\Magepow\Sizechart\Serialize\Serializer\Json $json
) {
parent::__construct($context);
$this->coreRegistry = $coreRegistry;
$this->sizechartFactory = $sizechartFactory;
$this->json = $json;
}
public function execute()
{
$rowId = (int) $this->getRequest()->getParam('id');
$storeViewId = $this->getRequest()->getParam('stores');
$rowData = $this->sizechartFactory->create();
if ($rowId) {
// $rowData->setStoreViewId($storeViewId)->load($rowId);
$rowData = $rowData->setStoreViewId($storeViewId)->load($rowId);
$rowTitle = $rowData->getTitle();
if (!$rowData->getEntityId()) {
$this->messageManager->addError(__('row data no longer exist.'));
$this->_redirect('magepow_sizechart/sizechart/rowdata');
return;
} else {
$tmp = $this->json->unserialize($rowData->getConditionsSerialized());
if (is_array($tmp)) {
unset($tmp['form_key']);
unset($tmp['entity_id']);
$rowData->addData($tmp);
}
$rowData->setData('sizechart_id', $rowData->getEntityId()); // fix conflict entity_id in product condition
}
}
$this->coreRegistry->register('row_data', $rowData);
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$title = $rowId ? __('Edit Size chart') . $rowTitle : __('Add Size chart');
$resultPage->getConfig()->getTitle()->prepend($title);
return $resultPage;
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Controller\Adminhtml\Sizechart;
class Index extends \Magento\Backend\App\Action
{
protected $resultPageFactory = false;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend((__('Size Chart')));
return $resultPage;
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Controller\Adminhtml\Sizechart;
use Magento\Framework\Controller\ResultFactory;
use Magento\Backend\App\Action\Context;
use Magento\Ui\Component\MassAction\Filter;
use Magepow\Sizechart\Model\ResourceModel\Sizechart\CollectionFactory;
class MassDelete extends \Magento\Backend\App\Action
{
/**
* Massactions filter.
* @var Filter
*/
protected $_filter;
/**
* @var CollectionFactory
*/
protected $_collectionFactory;
public function __construct(
Context $context,
Filter $filter,
CollectionFactory $collectionFactory
) {
$this->_filter = $filter;
$this->_collectionFactory = $collectionFactory;
parent::__construct($context);
}
public function execute()
{
$collection = $this->_filter->getCollection($this->_collectionFactory->create());
$recordDeleted = 0;
foreach ($collection->getItems() as $record) {
$record->setId($record->getEntityId());
$record->delete();
$recordDeleted++;
}
$this->messageManager->addSuccess(__(
'A total of %1 record(s) have been deleted.',
$recordDeleted
));
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/index');
}
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Magepow_Sizechart::row_data_delete');
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Controller\Adminhtml\Sizechart;
class Save extends \Magento\Backend\App\Action
{
protected $_sizechartFactory;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magepow\Sizechart\Model\SizechartFactory $sizechartFactory
) {
parent::__construct($context);
$this->_sizechartFactory = $sizechartFactory;
}
public function serialize($data)
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$serializer = $objectManager->create(\Magento\Framework\Serialize\SerializerInterface::class);
return $serializer->serialize($data);
}
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
// check if data sent
$data = $this->getRequest()->getPostValue();
if ($data) {
$id = $this->getRequest()->getParam('sizechart_id');
if ($id) $data['entity_id'] = $id; // fix conflict entity_id in product condition
$model = $this->_sizechartFactory->create();
$storeViewId = $this->getRequest()->getParam('stores');
$model->load($id);
if (!$model->getId() && $id) {
$this->messageManager->addError(__('This item no longer exists.'));
return $resultRedirect->setPath('*/*/');
}
if (isset($data['category'])) {
$data['category'] = implode(',', $data['category']);
}
$data['conditions_serialized'] = $this->serialize(['parameters' => $data['parameters']]);
if (isset($data['custom_size'])) {
$data['custom_size'] = json_encode($data['custom_size'], true);
}
if (isset($data['stores'])) $data['stores'] = implode(',', $data['stores']);
$model->setData($data)->setStoreViewId($storeViewId);;
// try to save it
try {
$model->save();
// display success message
$this->messageManager->addSuccess(__('You saved the item.'));
if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/addrow', ['id' => $model->getId(), '_current' => true]);
return;
}
// go to grid
return $resultRedirect->setPath('*/*/index');
} catch (\Exception $e) {
// display error message
$this->messageManager->addError($e->getMessage());
// save data in session
$this->_objectManager->get('Magento\Backend\Model\Session')->setFormData($data);
// redirect to edit form
return $resultRedirect->setPath('*/*/addrow', ['id' => $this->getRequest()->getParam('id')]);
}
}
return $resultRedirect->setPath('*/*/index');
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
protected $_sizechartFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory,
\Magepow\Sizechart\Model\SizechartFactory $sizechartFactory
) {
$this->_pageFactory = $pageFactory;
$this->_sizechartFactory = $sizechartFactory;
return parent::__construct($context);
}
public function execute()
{
$page = $this->_pageFactory->create();
$pageFactory = $page->getLayout()->getBlock('Magepow\Sizechart\Block\Product\Sizechart');
//We are using HTTP headers to control various page caches (varnish, fastly, built-in php cache)
$pageFactory->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0', true);
return $pageFactory;
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Cron;
class FlushCache
{
protected $helperCache;
public function __construct(
\Magepow\Sizechart\Helper\Cache $helperCache
) {
$this->helperCache = $helperCache;
}
public function flushCache()
{
$this->helperCache->flushCache();
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Helper;
class Cache extends \Magento\Framework\App\Helper\AbstractHelper
{
protected $cacheTypeList;
protected $cacheFrontendPool;
/**
* Cache constructor.
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
* @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
\Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
) {
parent::__construct($context);
$this->cacheTypeList = $cacheTypeList;
$this->cacheFrontendPool = $cacheFrontendPool;
}
/**
*
* Flush Cache Action
*
*/
public function flushCache()
{
$types = [
'config',
'layout',
'block_html',
'collections',
'reflection',
'db_ddl',
'eav',
'config_integration',
'config_integration_api',
'full_page',
'translate',
'config_webservice'
];
foreach ($types as $type) {
$this->cacheTypeList->cleanType($type);
}
foreach ($this->cacheFrontendPool as $cacheFrontend) {
$cacheFrontend->getBackend()->clean();
}
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\ScopeInterface;
class Data extends AbstractHelper
{
protected $configModule;
protected $_moduleManager;
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\Module\Manager $moduleManager
) {
parent::__construct($context);
$this->configModule = $this->getConfig(strtolower($this->_getModuleName()));
$this->_moduleManager = $moduleManager;
}
public function getConfig($cfg = '')
{
if ($cfg) return $this->scopeConfig->getValue($cfg, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
return $this->scopeConfig;
}
public function getConfigModule($cfg = '', $value = null)
{
$values = $this->configModule;
if (!$cfg) return $values;
$config = explode('/', (string) $cfg);
$end = count($config) - 1;
foreach ($config as $key => $vl) {
if (isset($values[$vl])) {
if ($key == $end) {
$value = $values[$vl];
} else {
$values = $values[$vl];
}
}
}
return $value;
}
public function isModuleEnabled($moduleName)
{
return $this->_moduleManager->isEnabled($moduleName);
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Model;
use Magento\Backend\App\Action\Context;
use Magento\Backend\App\Action;
use Magento\Framework\App\Cache\Manager as CacheManager;
use Magento\Framework\App\Cache\TypeListInterface as CacheTypeListInterface;
class Cron
{
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
\Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
) {
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheFrontendPool = $cacheFrontendPool;
}
public function flushCache()
{
$types = [
'config',
'layout',
'block_html',
'collections',
'reflection',
'db_ddl',
'eav',
'config_integration',
'config_integration_api',
'full_page',
'translate',
'config_webservice'
];
foreach ($types as $type) {
$this->cacheTypeList->cleanType($type);
}
foreach ($this->cacheFrontendPool as $cacheFrontend) {
$cacheFrontend->getBackend()->clean();
}
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Model\ResourceModel;
class Sizechart extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
public function __construct(
\Magento\Framework\Model\ResourceModel\Db\Context $context
) {
parent::__construct($context);
}
protected function _construct()
{
$this->_init('sizechart_management', 'entity_id');
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Model\ResourceModel\Sizechart;
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
protected $_idFieldName = 'entity_id';
/**
* Define resource model
*
* @return void
*/
protected function _construct()
{
$this->_init(
'Magepow\Sizechart\Model\Sizechart',
'Magepow\Sizechart\Model\ResourceModel\Sizechart'
);
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Model;
use Magepow\Sizechart\Api\Data\SizechartInterface;
class Sizechart extends \Magento\Framework\Model\AbstractModel implements SizechartInterface
{
const CACHE_TAG = 'sizechart_management';
protected $_cacheTag = 'sizechart_management';
protected $_eventPrefix = 'sizechart_management';
protected function _construct()
{
$this->_init('Magepow\Sizechart\Model\ResourceModel\Sizechart');
}
public function getIdentities()
{
return [self::CACHE_TAG . '_' . $this->getId()];
}
public function getDefaultValues()
{
$values = [];
return $values;
}
public function getEntityId()
{
return $this->getData(self::ENTITY_ID);
}
public function setEntityId($entityId)
{
return $this->setData(self::ENTITY_ID, $entityId);
}
public function getCategoryId()
{
return $this->getData(self::CATEGORY_ID);
}
public function setCategoryId($categoryId)
{
return $this->setData(self::CATEGORY_ID, $categoryId);
}
public function getSubCategoryId()
{
return $this->getData(self::SUB_CATEGORY_ID);
}
public function setSubCategoryId($subCategoryId)
{
return $this->setData(self::SUB_CATEGORY_ID, $subCategoryId);
}
public function getTypeDisplay()
{
return $this->getData(self::TYPE_DISPLAY);
}
public function setTypeDisplay($typeDisplay)
{
return $this->setData(self::TYPE_DISPLAY, $typeDisplay);
}
public function getDescription()
{
return $this->getData(self::DESCRIPTION);
}
public function setDescription($description)
{
return $this->setData(self::DESCRIPTION, $description);
}
public function getSizeChartInfo()
{
return $this->getData(self::SIZECHART_INFO);
}
public function setSizeChartInfo($sizeChartInfo)
{
return $this->setData(self::SIZECHART_INFO, $sizeChartInfo);
}
public function getUpdatedAt()
{
return $this->getData(self::UPDATED_AT);
}
public function setUpdatedAt($updatedAt)
{
return $this->setData(self::UPDATED_AT, $updatedAt);
}
public function getCreatedAt()
{
return $this->getData(self::CREATED_AT);
}
public function setCreatedAt($createdAt)
{
return $this->setData(self::CREATED_AT, $createdAt);
}
public function getIsActive()
{
return $this->getData(self::IS_ACTIVE);
}
public function setIsActive($isActive)
{
return $this->setData(self::IS_ACTIVE, $isActive);
}
public function getTemplateCss()
{
return $this->getData(self::TEMPLATE_CSS);
}
public function setTemplateCss($templateCss)
{
return $this->setData(self::TEMPLATE_CSS, $templateCss);
}
public function getConditions()
{
return $this->getData(self::CONDITIONS);
}
public function setConditions($conditions)
{
return $this->setData(self::CONDITIONS, $conditions);
}
public function getStoreView()
{
return $this->getData(self::STORES);
}
public function setStoreView($stores)
{
return $this->setData(self::STORES, $stores);
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Model;
use Magento\Framework\Data\OptionSourceInterface;
class Status implements OptionSourceInterface
{
public function getOptionArray()
{
$options = ['1' => __('Enabled'), '0' => __('Disabled')];
return $options;
}
/**
* Get Grid row status labels array with empty value for option element.
*
* @return array
*/
public function getAllOptions()
{
$res = $this->getOptions();
array_unshift($res, ['value' => '', 'label' => '']);
return $res;
}
/**
* Get Grid row type array for option element.
* @return array
*/
public function getOptions()
{
$res = [];
foreach ($this->getOptionArray() as $index => $value) {
$res[] = ['value' => $index, 'label' => $value];
}
return $res;
}
/**
* {@inheritdoc}
*/
public function toOptionArray()
{
return $this->getOptions();
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Model;
use Magento\Framework\Data\OptionSourceInterface;
class TypeDisplay implements OptionSourceInterface
{
public function getOptionArray()
{
$options = ['1' => __('Inline'), '2' => __('Pop Up'), '3' => __('Custom Tab')];
return $options;
}
/**
* Get Grid row status labels array with empty value for option element.
*
* @return array
*/
public function getAllOptions()
{
$res = $this->getOptions();
array_unshift($res, ['value' => '', 'label' => '']);
return $res;
}
/**
* Get Grid row type array for option element.
* @return array
*/
public function getOptions()
{
$res = [];
foreach ($this->getOptionArray() as $index => $value) {
$res[] = ['value' => $index, 'label' => $value];
}
return $res;
}
/**
* {@inheritdoc}
*/
public function toOptionArray()
{
return $this->getOptions();
}
}
\ No newline at end of file
[<img src="https://github.com/magepow/themeforest/blob/master/shopify/shopify_affiliate.jpg" >](https://shopify.pxf.io/VyL446)
## Magento 2 Size Chart
Magento 2 Sizechart is a module allows admin to show their size chart diagram below product images on product page which helps customers choose the most suitable size for them.
Displaying exact product sizes on the website makes it easy for customers to choose the right product for their needs.
Product size will vary depending on the brand, each country. Therefore, adding a product-specific size chart on your e-commerce website is essential.
### Benefits
- Create size chart according to product characteristics: clothes, shoes, electronic devices, furniture, accessories...
- Show size chart inline, custom tab, popup.
- Add linked text, images or labels.
- Save time for the project
- Apply precedence rule to size chart
- Manage size rules in the backend
- Avoid customers returning products due to size problems
- Works well on mobile devices
## How does Site Chart work for Magento
- Detail Description: [Magento 2 Size Chart](https://magepow.com/magento-2-size-chart.html)
- [DOCUMENTATION](https://docs.magepow.com/sizechart/)
[![Latest Stable Version](https://poser.pugx.org/magepow/sizechart/v/stable)](https://packagist.org/packages/magepow/sizechart)
[![Total Downloads](https://poser.pugx.org/magepow/sizechart/downloads)](https://packagist.org/packages/magepow/sizechart)
[![Daily Downloads](https://poser.pugx.org/magepow/sizechart/d/daily)](https://packagist.org/packages/magepow/sizechart)
## Download Magento 2 Sizechart Extension
### Install via composer (recommend)
Run the following commands in Magento 2 root folder:
```
composer require magepow/sizechart
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
```
## Step 2: How to use Magento 2 Sizechart?
### 1. General configuration
Login to magento admin, choose `stores->configuration->magepow->Sizechart`
![Image of magento admin config](https://github.com/magepow/magento2-sizechart/blob/master/media/config.png)
Select `yes` to enable the module
### 2. Details Configuration
In `stores->configuration->magepow->sizechart` we set:
* Display text link : Show text link if user sets popup for displaying size chart.
* Image icon : Select image icon (only using when user sets popup for displaying size chart)
![Image of magento backend](https://github.com/magepow/magento2-sizechart/blob/master/media/config-popup.png)
### 3. Add Sizechart
Choose `Magepow->Size chart Management->Add New Size Chart Rule`.
![Image of magento backend](https://github.com/magepow/magento2-sizechart/blob/master/media/add-content1.png)
![Image of magento backend](https://github.com/magepow/magento2-sizechart/blob/master/media/add-content2.png)
![Image of magento backend](https://github.com/magepow/magento2-sizechart/blob/master/media/add-content3.png)
* Name: Name of your size chart management rule
* Store View : Define which store view you wish to show
* Description : Introduce about your size chart
* Size chart Information : Details about your size chart : you can write your diagram, image as you want
* Sort order : This part is used for the priority. If there is any rule have the same information. then the one which lower number will have the higher priority.
* Type Display : You can choose 3 types of displaying included: Inline, Custom Tab, Popup.
* Status: Select Enable/Disable for turning on/off the size chart rule.
### 4. Edit Sizechart
![Image of magento backend](https://github.com/magepow/magento2-sizechart/blob/master/media/edit.png)
### 5. Delete Sizechart
![Image of magento backend](https://github.com/magepow/magento2-sizechart/blob/master/media/delete.png)
### 6. Product Rule
Choose `Magepow->Size chart Management->Add New Size Chart Rule` and set number for sort order
This part is used for the priority of size chart. The rule on this part will be prioritized to show. This is for prevent the conflict when multiple rule are applied on one product or rally of products.
Run the following command:
```
php bin/magento cache:clean
```
### 3. Result
![Image of magento store front](https://github.com/magepow/magento2-sizechart/blob/master/media/result.png)
## Donation
If this project help you reduce time to develop, you can give me a cup of coffee :)
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/paypalme/alopay)
**[Our Magento 2 Extensions](https://magepow.com/magento-2-extensions.html)**
* [Magento 2 Recent Sales Notification](https://magepow.com/magento-2-recent-order-notification.html)
* [Magento 2 Categories Extension](https://magepow.com/magento-categories-extension.html)
* [Magento 2 Sticky Cart](https://magepow.com/magento-sticky-cart.html)
* [Magento 2 Ajax Contact](https://magepow.com/magento-ajax-contact-form.html)
* [Magento 2 Lazy Load](https://magepow.com/magento-lazy-load.html)
* [Magento 2 Mutil Translate](https://magepow.com/magento-multi-translate.html)
* [Magento 2 Instagram Integration](https://magepow.com/magento-2-instagram.html)
* [Magento 2 Lookbook Pin Products](https://magepow.com/lookbook-pin-products.html)
* [Magento 2 Product Slider](https://magepow.com/magento-product-slider.html)
* [Magento 2 Product Banner](https://magepow.com/magento-2-banner-slider.html)
**[Our Magento 2 services](https://magepow.com/magento-services.html)**
* [PSD to Magento 2 Theme Conversion](https://alothemes.com/psd-to-magento-theme-conversion.html)
* [Magento 2 Speed Optimization Service](https://magepow.com/magento-speed-optimization-service.html)
* [Magento 2 Security Patch Installation](https://magepow.com/magento-security-patch-installation.html)
* [Magento 2 Website Maintenance Service](https://magepow.com/website-maintenance-service.html)
* [Magento 2 Professional Installation Service](https://magepow.com/professional-installation-service.html)
* [Magento 2 Upgrade Service](https://magepow.com/magento-upgrade-service.html)
* [Magento 2 Customization Service](https://magepow.com/customization-service.html)
* [Hire Magento 2 Developer](https://magepow.com/hire-magento-developer.html)
**[Our Magento 2 Themes](https://alothemes.com/)**
* [Expert Multipurpose Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/expert-premium-responsive-magento-2-and-1-support-rtl-magento-2-/21667789)
* [Gecko Premium Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/gecko-responsive-magento-2-theme-rtl-supported/24677410)
* [Milano Fashion Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/milano-fashion-responsive-magento-1-2-theme/12141971)
* [Electro 2 Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/electro2-premium-responsive-magento-2-rtl-supported/26875864)
* [Electro Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/electro-responsive-magento-1-2-theme/17042067)
* [Pizzaro Food responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/pizzaro-food-responsive-magento-1-2-theme/19438157)
* [Biolife organic responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/biolife-organic-food-magento-2-theme-rtl-supported/25712510)
* [Market responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/market-responsive-magento-2-theme/22997928)
* [Kuteshop responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/kuteshop-multipurpose-responsive-magento-1-2-theme/12985435)
* [Bencher - Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/bencher-responsive-magento-1-2-theme/15787772)
* [Supermarket Responsive Magento 2 Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/supermarket-responsive-magento-1-2-theme/18447995)
**[Our Shopify Themes](https://themeforest.net/user/alotheme)**
* [Dukamarket - Multipurpose Shopify Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/dukamarket-multipurpose-shopify-theme/36158349)
* [Ohey - Multipurpose Shopify Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/ohey-multipurpose-shopify-theme/34624195)
* [Flexon - Multipurpose Shopify Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/flexon-multipurpose-shopify-theme/33461048)
**[Our Shopify App](https://apps.shopify.com/partners/maggicart)**
* [Magepow Infinite Scroll](https://apps.shopify.com/magepow-infinite-scroll)
* [Magepow Promotionbar](https://apps.shopify.com/magepow-promotionbar)
* [Magepow Size Chart](https://apps.shopify.com/magepow-size-chart)
**[Our WordPress Theme](https://themeforest.net/user/alotheme/portfolio)**
* [SadesMarket - Multipurpose WordPress Theme](https://1.envato.market/c/1314680/275988/4415?u=https://themeforest.net/item/sadesmarket-multipurpose-wordpress-theme/35369933)
<?php
namespace Magepow\Sizechart\Serialize\Serializer;
class Json extends \Magento\Framework\Serialize\Serializer\Json
{
public function unserialize($string)
{
if ($this->is_serialized($string)) {
$string = $this->serialize($string);
}
$result = json_decode($string, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \InvalidArgumentException('Unable to unserialize value.');
}
return $result;
}
function is_serialized($value, &$result = null)
{
// Bit of a give away this one
if (!is_string($value)) {
return false;
}
// Serialized false, return true. unserialize() returns false on an
// invalid string or it could return false if the string is serialized
// false, eliminate that possibility.
if ($value === 'b:0;') {
$result = false;
return true;
}
$length = strlen($value);
$end = '';
switch ($value[0]) {
case 's':
if ($value[$length - 2] !== '"') {
return false;
}
case 'b':
case 'i':
case 'd':
// This looks odd but it is quicker than isset()ing
$end .= ';';
case 'a':
case 'O':
$end .= '}';
if ($value[1] !== ':') {
return false;
}
switch ($value[2]) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
break;
default:
return false;
}
case 'N':
$end .= ';';
if ($value[$length - 1] !== $end[0]) {
return false;
}
break;
default:
return false;
}
if (($result = json_decode($value)) === false) {
$result = null;
return false;
}
return true;
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Setup;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
class InstallSchema implements InstallSchemaInterface
{
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
if (!$installer->tableExists('sizechart_management')) {
$table = $installer->getConnection()
->newTable($installer->getTable('sizechart_management'));
$table->addColumn(
'entity_id',
Table::TYPE_INTEGER,
null,
[
'identity' => true,
'unsigned' => true,
'nullable' => false,
'primary' => true
],
'ENTITY ID'
)->addColumn(
'name',
Table::TYPE_TEXT,
'2M',
[],
'Name'
)
->addColumn(
'category',
Table::TYPE_TEXT,
null,
[],
'category'
)
->addColumn(
'type_display',
Table::TYPE_INTEGER,
null,
['nullable' => false, 'default' => 1],
'Size chart size display'
)
->addColumn(
'is_active',
Table::TYPE_INTEGER,
null,
[
'nullable' => false,
'default' => '1',
],
'Is Active status'
)
->addColumn(
'description',
Table::TYPE_TEXT,
'64k',
[],
'Description'
)
->addColumn(
'sizechart_info',
Table::TYPE_TEXT,
'2M',
[],
'Size Chart Information'
)->addColumn(
'conditions_serialized',
Table::TYPE_TEXT,
'2M',
[],
'Conditions Serialized'
)
->addColumn(
'sort_order',
Table::TYPE_INTEGER,
null,
['nullable' => false, 'default' => '0'],
'Sort Order'
)
->addColumn(
'updated_at',
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
null,
['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
'Updated At'
)
->addColumn(
'created_at',
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
null,
['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
'Creation Time'
);
$installer->getConnection()->createTable($table);
$installer->getConnection()->addIndex(
$installer->getTable('sizechart_management'),
$setup->getIdxName(
$installer->getTable('sizechart_management'),
['name', 'description', 'sizechart_info'],
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT
),
['name', 'description', 'sizechart_info'],
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT
);
}
$installer->endSetup();
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Setup;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$tableName = $setup->getTable('sizechart_management');
if (version_compare($context->getVersion(), '2.0.0', '<')) {
if ($setup->getConnection()->isTableExists($tableName) == true) {
$connection = $setup->getConnection();
$connection->addColumn(
$setup->getTable($tableName),
'template_css',
[
'type' => Table::TYPE_TEXT,
'length' => '2M',
'nullable' => true,
'comment' => 'template css'
]
);
}
}
if (version_compare($context->getVersion(), '2.3.0', '<')) {
if ($setup->getConnection()->isTableExists($tableName) == true) {
$connection = $setup->getConnection();
$connection->addColumn(
$setup->getTable($tableName),
'stores',
[
'type' => Table::TYPE_TEXT,
'length' => '2M',
'nullable' => false,
'comment' => 'Store Views'
]
);
}
}
if (version_compare($context->getVersion(), '2.5.2', '<')) {
if ($setup->getConnection()->isTableExists($tableName) == true) {
$connection = $setup->getConnection();
$connection->addColumn(
$setup->getTable($tableName),
'custom_size',
[
'type' => Table::TYPE_TEXT,
'nullable' => false,
'comment' => 'custom size'
]
);
$connection->addColumn(
$setup->getTable($tableName),
'column_label',
[
'type' => Table::TYPE_TEXT,
'nullable' => false,
'comment' => 'column label'
]
);
}
}
}
}
\ No newline at end of file
<?php
namespace Magepow\Sizechart\Ui\Component\Listing\Sizechart\Column;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
use Magento\Framework\UrlInterface;
class Action extends Column
{
/** Url path */
const ROW_EDIT_URL = 'magepow_sizechart/sizechart/addrow';
/** @var UrlInterface */
protected $_urlBuilder;
/**
* @var string
*/
private $_editUrl;
/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
* @param string $editUrl
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlInterface $urlBuilder,
array $components = [],
array $data = [],
$editUrl = self::ROW_EDIT_URL
) {
$this->_urlBuilder = $urlBuilder;
$this->_editUrl = $editUrl;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
/**
* Prepare Data Source.
*
* @param array $dataSource
*
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$item) {
$name = $this->getData('name');
if (isset($item['entity_id'])) {
$item[$name]['edit'] = [
'href' => $this->_urlBuilder->getUrl(
$this->_editUrl,
['id' => $item['entity_id']]
),
'label' => __('Edit'),
];
}
}
}
return $dataSource;
}
}
{
"name": "magepow/sizechart",
"description": "Size chart extension for Magento helps you create size charts for products on your website.",
"require": {
"magepow/core": "^1.0.0"
},
"type": "magento2-module",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"authors": [
{
"name": "Magepow",
"email": "support@magepow.com",
"homepage": "https://magepow.com",
"role": "Technical Support"
}
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magepow\\Sizechart\\": ""
}
}
}
\ No newline at end of file
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Magepow_Sizechart::magepow" title="Size Chart" sortOrder="10">
<resource id="Magepow_Sizechart::sizechart" title="Size Chart Management" sortOrder="50" />
</resource>
<resource id="Magento_Backend::stores">
<resource id="Magento_Backend::stores_settings">
<resource id="Magento_Config::config">
<resource id="Magepow_Sizechart::config" title="Size Chart"/>
</resource>
</resource>
</resource>
</resource>
</resources>
</acl>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<update id="magepow" title="Magepow" module="Magepow_Sizechart" sortOrder="10" resource="Magepow_Sizechart::magepow" />
<add id="Magepow_Sizechart::magepow" title="Size Chart" module="Magepow_Sizechart" sortOrder="10" parent="magepow" resource="Magepow_Sizechart::magepow" />
<add id="Magepow_Sizechart::sizechart" title="Size Chart Management" module="Magepow_Sizechart" parent="Magepow_Sizechart::magepow" sortOrder="20" action="magepow_sizechart/sizechart" resource="Magepow_Sizechart::sizechart"/>
<add id="Magepow_Sizechart::config" title="Configuration" module="Magepow_Sizechart" parent="Magepow_Sizechart::magepow" sortOrder="30" action="adminhtml/system_config/edit/section/magepow_sizechart" resource="Magepow_Sizechart::sizechart_configuration"/>
</menu>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="magepow_sizechart" frontName="magepow_sizechart">
<module name="Magepow_Sizechart"/>
</route>
</router>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="magepow" translate="label" sortOrder="10">
<label>Magepow</label>
</tab>
<section id="magepow_sizechart" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Size Chart</label>
<tab>magepow</tab>
<resource>Magepow_Sizechart::config</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label><![CDATA[General]]></label>
<field id="enabled" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="1" canRestore="1">
<label>Module Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="display_text" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="1" canRestore="1">
<label>Display Text Link</label>
<comment>This text will display the link for showing popup sizechart</comment>
<depends>
<field id="enabled">1</field>
</depends>
</field>
<field id="image_icon" translate="label" type="image" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Image Icon</label>
<comment>This section will display the icon for showing popup sizechart</comment>
<backend_model>Magento\Config\Model\Config\Backend\Image</backend_model>
<upload_dir config="system/filesystem/media" scope_info="1">magepow/sizechart</upload_dir>
<base_url type="media" scope_info="1">magepow/sizechart</base_url>
<depends>
<field id="enabled">1</field>
</depends>
</field>
</group>
</section>
</system>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<magepow_sizechart>
<general>
<enabled>1</enabled>
<display_text>Size Chart</display_text>
</general>
</magepow_sizechart>
</default>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
<group id="default">
<job name="magepow_sizechart" instance="Magepow\Sizechart\Model\Cron" method="flushCache">
<schedule>*/2 * * * *</schedule>
</job>
</group>
</config>
\ No newline at end of file
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magepow\Sizechart\Api\Data\SizechartInterface" type="Magepow\Sizechart\Model\Sizechart" />
<preference for="Magento\Framework\Serialize\Serializer\Json" type="Magepow\Sizechart\Serialize\Serializer\Json" />
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="magepow_sizechart_sizechart_listing_data_source" xsi:type="string">Magepow\Sizechart\Model\ResourceModel\Sizechart\Grid\Collection</item>
</argument>
</arguments>
</type>
<virtualType name="Magepow\Sizechart\Model\ResourceModel\Sizechart\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">sizechart_management</argument>
<argument name="resourceModel" xsi:type="string">Magepow\Sizechart\Model\ResourceModel\Sizechart</argument>
</arguments>
</virtualType>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="sizechart" frontName="sizechart">
<module name="Magepow_Sizechart"/>
</route>
</router>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 ExtensionsMall All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magepow_Sizechart" setup_version="2.5.2"/>
<sequence>
<module name="Magento_Catalog"/>
</sequence>
</config>
\ No newline at end of file
<?php
/**
* Copyright © 2016 ExtensionsMall. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magepow_Sizechart',
__DIR__
);
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="left">
<block class="Magepow\Sizechart\Block\Adminhtml\Sizechart\Edit\Tabs" name="tabs"/>
</referenceContainer>
<referenceContainer name="content">
<block class="Magepow\Sizechart\Block\Adminhtml\Sizechart\AddRow" name="add_row" />
</referenceContainer>
</body>
</page>
\ No newline at end of file
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="styles"/>
<body>
<referenceContainer name="content">
<uiComponent name="magepow_sizechart_sizechart_listing"/>
</referenceContainer>
</body>
</page>
\ No newline at end of file
<?php
/**
* @var $block \Magepow\Sizechart\Block\Adminhtml\Sizechart\ChartTable
*/
?>
<div class="admin__control-wysiwig" id="content_single_field">
<input id="content" name="column_label" data-ui-id="adminhtml-sizechart-edit-tab-main-0-fieldset-element-text-name"
value="<?= $block->getCustomSizeData()['column_label'] ?? '' ?>" title="Name" class="required_entry input-text admin__control-text required-entry _required"
type="text" aria-required="true">
<p class="note">
<span>The sizechart table head</span>
<br>
<span id="comment"></span>
</p>
<input class="btn btn-info pull-left add-record" id="register" name="register" value="Add Data" type="button">
<input class="pull-right add-record" id="csvfile" name="csvfile" value="Add Data" type="file" style="display: none;">
</div>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">magepow_sizechart_sizechart_listing.magepow_sizechart_sizechart_listing_data_source</item>
<item name="deps" xsi:type="string">magepow_sizechart_sizechart_listing.magepow_sizechart_sizechart_listing_data_source</item>
</item>
<item name="spinner" xsi:type="string">spinner_columns</item>
<item name="buttons" xsi:type="array">
<item name="add" xsi:type="array">
<item name="name" xsi:type="string">add</item>
<item name="label" xsi:type="string" translate="true">Add New Size Chart Rule </item>
<item name="class" xsi:type="string">primary</item>
<item name="url" xsi:type="string">magepow_sizechart/sizechart/addrow</item>
</item>
</item>
</argument>
<dataSource name="magepow_sizechart_sizechart_listing_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider</argument>
<argument name="name" xsi:type="string">magepow_sizechart_sizechart_listing_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">entity_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">entity_id</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<listingToolbar name="listing_top">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sticky" xsi:type="boolean">true</item>
</item>
</argument>
<bookmark name="bookmarks"/>
<columnsControls name="columns_controls"/>
<exportButton name="export_button"/>
<filters name="listing_filters" />
<filterSearch name="fulltext"/>
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
</item>
</argument>
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="magepow_sizechart/sizechart/massdelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete Size Chart Rule</item>
<item name="message" xsi:type="string" translate="true">Are you sure you want to delete selected items?</item>
</item>
</item>
</argument>
</action>
</massaction>
<paging name="listing_paging"/>
</listingToolbar>
<columns name="spinner_columns">
<selectionsColumn name="ids">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="resizeEnabled" xsi:type="boolean">false</item>
<item name="resizeDefaultWidth" xsi:type="string">55</item>
<item name="indexField" xsi:type="string">entity_id</item>
</item>
</argument>
</selectionsColumn>
<column name="entity_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="label" xsi:type="string" translate="true">ID</item>
</item>
</argument>
</column>
<column name="name">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="label" xsi:type="string" translate="true">Name</item>
</item>
</argument>
</column>
<column name="sort_order">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="label" xsi:type="string" translate="true">Sort Order</item>
</item>
</argument>
</column>
<column name="description">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="label" xsi:type="string" translate="true">Description</item>
</item>
</argument>
</column>
<column name="is_active" >
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Magepow\Sizechart\Model\Status</item>
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">select</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
<item name="dataType" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Is Active</item>
</item>
</argument>
</column>
<column name="type_display" >
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Magepow\Sizechart\Model\TypeDisplay</item>
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">select</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
<item name="dataType" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Type Display</item>
</item>
</argument>
</column>
<column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">dateRange</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
<item name="dataType" xsi:type="string">date</item>
<item name="label" xsi:type="string" translate="true">Created</item>
</item>
</argument>
</column>
<column name="updated_at" class="Magento\Ui\Component\Listing\Columns\Date">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">dateRange</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
<item name="dataType" xsi:type="string">date</item>
<item name="label" xsi:type="string" translate="true">Modified</item>
</item>
</argument>
</column>
<actionsColumn name="actions" class = "Magepow\Sizechart\Ui\Component\Listing\Sizechart\Column\Action">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="resizeEnabled" xsi:type="boolean">false</item>
<item name="resizeDefaultWidth" xsi:type="string">107</item>
<item name="indexField" xsi:type="string">id</item>
</item>
</argument>
</actionsColumn>
</columns>
</listing>
\ No newline at end of file
...@@ -75,7 +75,127 @@ ...@@ -75,7 +75,127 @@
'description' 'description'
); );
$chartBlock = $objectManager->create(\Magepow\Sizechart\Block\Product\Sizechart::class);
$sizeChart = $chartBlock->getSizeChart();
$chartTableArray = [];
$chartInfo = '';
$chartEnabled = 1;
if ($sizeChart != null) {
$chartTable = $sizeChart->getData('custom_size');
$chartTableArray = json_decode($chartTable, true);
$chartInfo = $sizeChart->getData('sizechart_info');
}
?> ?>
#chart-image {
margin: 0 0 0 0;
border-collapse: collapse;
width: 30%;
float: left;
}
#chart-details {
border-collapse: collapse;
width: 100%;
overflow: auto;
}
#chart-details .tbody .td:first-child {
font-weight: bold;
}
#fme_sizechart_table {
margin: 0 0 0 0;
border-collapse: collapse;
width: 100%;
}
#fme_sizechart_table_th {
background: #111;
border: 1px solid #111;
font-size:16px;
padding:8px 0;
color: #fff;
font-weight: 600 !important;
}
#fme_sizechart_table .td {
border: 1px solid #f8f8f8;
}
#fme_sizechart_table .td.bold {
font-weight:600 !important;
}
#fme_sizechart_table .th, .table .td {
padding: .5rem !important;
text-align: center;
}
#fme_sizechart_table .tr:nth-child(2n) {
background: #f8f8f8 ;
}
.scrollable_content {
width:100%;
overflow:auto;
}
@media only screen and (max-width:768px){
#chart-image {
margin: 0 0 0 0;
border-collapse: collapse;
width: 100%;
}
#chart-details {
margin: 0 0 0 0;
border-collapse: collapse;
width: 100%;
overflow: auto;
}
}
.sizechart_icon{
width: 30px;
display: inline-block;
margin-bottom: 0;
font-weight: normal;
text-align: center;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
white-space: nowrap;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
border-radius: 4px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.chart-details {
margin-top: 20px;
}
.chart-size-switch {
margin: 10px 10px 10px 0;
}
.chart-size-switch .chart-size-switch-item{
display: inline-block;
padding: 0 0.9rem;
line-height: 1.99rem;
font-size: 1.15rem;
height: 2rem;
border: 1px solid #f3f3f3;
color: #666;
cursor: pointer;
}
.chart-size-switch-item.-active {
background-color: #111;
color: white;
}
</style> </style>
<script> <script>
...@@ -171,10 +291,29 @@ ...@@ -171,10 +291,29 @@
} }
return mobile_flag; return mobile_flag;
} }
$('.chart-size-switch-item').click(function(data) {
if ($(this).hasClass('-active')) {
return;
}
$(this).addClass('-active').siblings().removeClass('-active');
var type = $(this).data('size-type');
var percent = 2.54;
$.each($(".size-item"), function (x) {
var current = $(this).data('size-item-cm');
console.log(current);
if (type == 'inc') {
var data = (current / percent - 0).toFixed(2);
} else {
var data = $(this).data('size-item-cm');
}
$(this).html(data);
});
});
}); });
</script> </script>
<li class="lis" style="display: none;"> <li class="lis" style="display: none;">
<section id="areaLayer" class="express-area-box"> <section id="areaLayer" style="z-index: 996;" class="express-area-box">
<article id="areaBox"> <article id="areaBox">
<ul class="remen" id="remen"> <ul class="remen" id="remen">
<li class="lastli lastli-left"></li> <li class="lastli lastli-left"></li>
...@@ -182,12 +321,51 @@ ...@@ -182,12 +321,51 @@
</ul> </ul>
<div class="area-content"> <div class="area-content">
<div id="size-chart" style="display: none;"> <div id="size-chart" style="display: none;">
<?php if (count($chartTableArray) > 1): ?>
<div id="chart-details">
<div class="chart-size-switch ">
<input type="hidden" value="">
<span class="chart-size-switch-item -active" data-size-type="cm"><?= __('cm'); ?></span><span data-size-type="inc" class="chart-size-switch-item"><?= __('Inch'); ?></span>
</div>
<!--全局table已被污染,请使用div模拟表格-->
<div class="table" id="fme_sizechart_table" style="display: table;">
<div style="display: table-header-group;" class="thead">
<?php if(isset($chartTableArray[0])): ?>
<div id="fme_sizechart_table_th" class="tr" style="display: table-row;">
<?php foreach ($chartTableArray[0] as $head): ?>
<div style="display: table-cell;" class="th"><?= $head ?></div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div style="display: table-row-group" class="tbody">
<?php if(isset($chartTableArray)): ?>
<?php foreach ($chartTableArray as $key => $body): ?>
<?php
if ($key == 0) {
continue;
}
?>
<div style="display: table-row" class="tr">
<?php foreach ($body as $key2 => $item): ?>
<div style="display: table-cell" class="td" <?php if($key2 != 0) { echo 'class=size-item'; } ?> data-size-item-cm="<?= $item ?>"><?= $item ?> </div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
<?php echo $chartBlock->getContentFromStaticBlock($chartInfo);?>
<?php else: ?>
<?php <?php
$productCharTemplate = $block->getProduct()->getAttributeText("sizeTemplate"); $productCharTemplate = $block->getProduct()->getAttributeText("sizeTemplate");
if (empty($block->getProduct()->getAttributeText("sizeTemplate"))){ if (empty($block->getProduct()->getAttributeText("sizeTemplate"))){
$productCharTemplate = "product-size-chart-default"; $productCharTemplate = "product-size-chart-default";
} }
echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId($productCharTemplate)->toHtml();?> echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId($productCharTemplate)->toHtml();
?>
<? endif; ?>
</div> </div>
<div id="free-return" style="display: none;"> <div id="free-return" style="display: none;">
<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('product-intro-free-return')->toHtml();?> <?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('product-intro-free-return')->toHtml();?>
...@@ -213,7 +391,7 @@ ...@@ -213,7 +391,7 @@
display: revert; display: revert;
color: #2d68a; color: #2d68a;
float: right; float: right;
margin-top: 0px; margin-top: 0;
font-size: .9em; font-size: .9em;
text-decoration: underline; text-decoration: underline;
} }
...@@ -242,13 +420,13 @@ ...@@ -242,13 +420,13 @@
height: auto; height: auto;
background-color: #fff; background-color: #fff;
position: fixed; position: fixed;
left: 0px; left: 0;
bottom: 0px; bottom: 0;
z-index: 100; z-index: 100;
padding: 5px; padding: 5px;
display: list-item; display: list-item;
list-style: none; list-style: none;
box-shadow: 0px 0px 16px; box-shadow: 0 0 16px;
} }
.lastli-right{ .lastli-right{
width: 20%; width: 20%;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment