0

I have created a module who I create too table for alternate group price & alternate client price :

id | client_id | product_id | price
 5 |    24     |    84      | 45

id | group_id | product_id  | price
 0 |    1     |    20       |  20

My table are full but I fail to display the value on product front view I don't know who to process. I understand I need to override the phtml and maybe the controller but I always found for create a new controller not for override existent.

<?php 
namespace miaou\CreateTable\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;

class InstallSchema implements InstallSchemaInterface
{
    /**
     * Installs DB schema for a module
     *
     * @param SchemaSetupInterface $setup
     * @param ModuleContextInterface $context
     * @return void
     */
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;

        $installer->startSetup();

        $table = $installer->getConnection()
            ->newTable($installer->getTable('prix_client_conseil'))
            ->addColumn(
                'entity_id',
                Table::TYPE_INTEGER,
                null,
                ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                'ID'
            )
              ->addColumn(
                'user_id',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false, 'default' => ''],
                'User ID'
            )
              ->addColumn(
                'product_id',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false, 'default' => ''],
                'Product ID'
            )
            ->addColumn(
                'prix',
                Table::TYPE_DECIMAL,
                null,
                ['nullable' => false, 'default' => '0'],
                'prix'

            )
            ->setComment('Prix conseillé pour un article par client');
        $installer->getConnection()->createTable($table);

        $table2 = $installer->getConnection()
            ->newTable($installer->getTable('prix_groupe_conseil'))
            ->addColumn(
                'entity_id',
                Table::TYPE_INTEGER,
                null,
                ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                'ID'
            )
              ->addColumn(
                'groupe_id',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false, 'default' => ''],
                'Proupe ID'
            )
              ->addColumn(
                'product_id',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false, 'default' => ''],
                'Product ID'
            )
            ->addColumn(
                'prix',
                Table::TYPE_DECIMAL,
                null,
                ['nullable' => false, 'default' => '0'],
                'prix'

            )
            ->setComment('Prix conseillé pour un article par groupe');
        $installer->getConnection()->createTable($table2);        

        $installer->endSetup();
    }

}

I have also created the Collection file and Model Resource

Thanks in advanced!

0

Solution founded,

Need a complete functional module.

RootName/ModuleName/view/frontend/layout/catalog_product_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="product.info.social">            
            <block class="RootName/ModuleName\Block\Features" name="RootName_Features" after="-" template="RootName_ModuleName::textblock.phtml" />
        </referenceContainer>
    </body>
</page>

RootName/ModuleName/view/frontend/templates/textblock.phtml

<?php
$features = $block->getFeatures();

?>
<div>
    <pre>
        <?php
        var_dump($features);       
        ?>
    </pre>
</div>

RootName/ModuleName/Block/Features.php

<?php

namespace RootName\ModuleName\Block;

class Features extends \Magento\Framework\View\Element\Template {

    protected $_product = null;
    protected $_registry;
    protected $_productFactory;
    protected $_helper;

    /**
     * @param \Magento\Framework\View\Element\Template\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param array $data
     */
    public function __construct(
    \Magento\Framework\View\Element\Template\Context $context, 
            \Magento\Framework\Registry $registry,
            \Magento\Catalog\Model\ProductFactory $productFactory,
            \Magento\Customer\Model\ResourceModel\Group\Collection $customerGroup,
            array $data = []
    ) {
        $this->_registry = $registry;
        $this->_productFactory = $productFactory;        
        $this->_customerGroup = $customerGroup;       
        parent::__construct($context, $data);
    }

    public function _prepareLayout() {
        return parent::_prepareLayout();
    }

    public function getFeatures() {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
        $connection = $resource->getConnection();
        $result = array();

            $table = $resource->getTableName('');

            $sql = "";
            $result[] = $connection->fetchAll($sql); 

        }
        return $result;
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.