ماجنتو 2 :إضافة بيجر في الشبكة المخصصة في الواجهة الأمامية

magento.stackexchange https://magento.stackexchange.com/questions/115116

  •  29-09-2020
  •  | 
  •  

سؤال

لقد أضفت شبكة واحدة في حساب العميل وحصلت على التحصيل أيضًا. ولكن عندما أرغب في إضافة جهاز النداء في تلك الشبكة، تظهر لي رسالة خطأ مثل:

SQLSTATE [42S22]:لم يتم العثور على العمود:1054 عمود غير معروف "main_table.attribute_id" في "قائمة الحقول"، كان الاستعلام:حدد COUNT(DISTINCT main_table.attribute_id) من custommodule_test مثل main_table أين (customer_id='2') {"is_exception":false} []

في الواقع لا يوجد أي ملف attribute_id موجود في الجدول الخاص بي ولا أقوم بالتصفية بحثًا عن اسم الملف هذا كما ترى.

ألق نظرة من فضلك :

test.phtml

<?php if ($block->getPagerHtml()): ?>
    <div class="order-products-toolbar toolbar bottom"><?php echo $block->getPagerHtml(); ?></div>
<?php endif; ?>

كتلة/test.php

protected function _prepareLayout()
{
    parent::_prepareLayout();
    if ($this->getCollection()) {
        $pager = $this->getLayout()->createBlock(
            'Magento\Theme\Block\Html\Pager',
            'custom.collection.test'
        )->setCollection(
            $this->getCollection()
        );
        $this->setChild('pager', $pager);
        $this->getCollection()->load();
    }
    return $this;
}
public function getPagerHtml()
{
    return $this->getChildHtml('pager');
}

public function getCollection()
{
    if (!$this->getData('collection')) {
        $this->setCollection(
            $this->_objectMangaer->get('Namespace\Modulename\Model\Test')->getCollection()->addFieldToFilter('customer_id',2)
        );
    }
    return $this->getData('collection');
}

يرجى الملاحظة :إذا اتصلت مباشرة

 $this->getCollection() ;
من ملف phtml ثم حصلت على المجموعة الصحيحة.

هل كانت مفيدة؟

المحلول

للوفاء بالمتطلبات، اتبعنا العديد من الأساليب ووجدنا أفضل حل لترقيم الصفحات على مجموعة Magento2 المخصصة.سنقوم هنا بشرح أفضل طريقة، يرجى اتباع الخطوات.

ملحوظة:على افتراض أنك قمت بإنشاء وحدة أساسية في Magento2.هنا Ipragmatech هي الحزمة الخاصة بنا وIpreward هي الوحدة الخاصة بنا.من فضلك قم بتغيير اسم الفصل الخاص بك وفقا لذلك.

الخطوة 1:قم بإنشاء وحدة تحكم باسم Myrewad، وفهرس الإجراء (Myreward/Index.php) وأضف الكود التالي لأسلوب التنفيذ

<?php
  namespace Ipragmatech\Ipreward\Controller\Myreward;
  class Index extends \Magento\Framework\App\Action\Action
     {
        public function execute()
           {
               $this->_view->loadLayout();
               $this->_view->renderLayout();
           }
    }

الخطوة 2:إنشاء كتلة (على افتراض أنك قمت بالفعل بإنشاء نموذج لجدولك.هنا لدينا جدول مخصص وقمنا بإنشاء النموذج كمكافأة) قم بتسمية Reward.php وأضف الكود التالي.في هذا الكود، أضفنا جهاز النداء إلى مجموعتنا المخصصة.

<?php
namespace Ipragmatech\Ipreward\Block\Myreward;

use Ipragmatech\Ipreward\Block\BaseBlock;

class Reward extends BaseBlock
  {
/**
 * @var \Ipragmatech\Ipreward\Model\Reward
 */
protected $_rewardCollection;

/**
 * Reward constructor.
 * @param \Magento\Framework\App\Action\Context $context
 * @param \Ipragmatech\Ipreward\Model\Reward $rewardCollection
 */
public function __construct(
    \Ipragmatech\Ipreward\Block\Context $context,
    \Ipragmatech\Ipreward\Model\Reward $rewardCollection,
){
    $this->_rewardCollection = $rewardCollection;
    parent::__construct($context);
}

protected function _prepareLayout()
{

    parent::_prepareLayout();
    $this->pageConfig->getTitle()->set(__('My Reward History'));

    if ($this->getRewardHistory()) {
        $pager = $this->getLayout()->createBlock(
            'Magento\Theme\Block\Html\Pager',
            'reward.history.pager'
        )->setAvailableLimit(array(5=>5,10=>10,15=>15,20=>20))
            ->setShowPerPage(true)->setCollection(
            $this->getRewardHistory()
        );
        $this->setChild('pager', $pager);
        $this->getRewardHistory()->load();
    }
    return $this;
}

public function getPagerHtml()
{
    return $this->getChildHtml('pager');
}
/**
 * function to get rewards point transaction of customer
 *
 * @return reward transaction collection
 */
Public function getRewardHistory()
{
    //get values of current page
    $page=($this->getRequest()->getParam('p'))? $this->getRequest()->getParam('p') : 1;
    //get values of current limit
    $pageSize=($this->getRequest()->getParam('limit'))? $this->getRequest
    ()->getParam('limit') : 5;


    $collection = $this->_rewardCollection->getCollection();
    $collection->setPageSize($pageSize);
    $collection->setCurPage($page);
    $logger->info("Here reward collection: ".$collection->getSelect());
    $logger->info("Here reward collection: Page:".$page." Page size :"
        .$pageSize);
    return $collection;
}

} الخطوه 3:تمت إضافة/تعديل الكود التالي في ملف التخطيط app/code/Ipragmatech/Ipreward/view/frontend/layout/ipreward_myreward_index.xml

  <?xml version="1.0"?>
  <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"               layout="2columns-left" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <update handle="customer_account"/>
      <body>
        <referenceContainer name="content">          
        <block class="Ipragmatech\Ipreward\Block\Myreward\Reward" name="myreward_reward" template="myreward/reward.phtml">
        </block>
       </referenceContainer>      
   </body>
 </page>

الخطوة 4:أضف ملف phtml الخاص بك كـ app/code/Ipragmatech/Ipreward/view/frontend/templates/myreward/reward.phtml وأضف الكود التالي

enter image description here

وسيكون الإخراج مثل هذا

enter image description here

في بعض الأحيان نواجه بعض مشكلات CSS حيث لا يتم عرض حد الصفحات، لذا استخدم CSS التالي إذا كانت لديك نفس المشكلة.

 .custom-pager .limiter{
      display: block !important;
  }

نأمل أن يكون هذا سوف يساعدك كثيرا.يرجى إعلامنا إذا كان لديك أي مشكلة بخصوص تخصيص Magento.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top