Magento फ़िल्टर संग्रह बनाकर बार (आज, कल, सप्ताह, घंटा आदि)


9

मेरे पास एक कस्टम संग्रह है जिसे मैं बनाई गई तिथि और फ़िल्टर की गई प्रविष्टियों द्वारा "कल" बनाना चाहता हूँ

संग्रह प्रविष्टियाँ

//dates are set in controller using
setCreatedTime(Mage::getModel('core/date')->gmtDate()); 

कल बनाया गया (काम नहीं करता है)

//3 products items Yesterday
//below filtering outputs incorrect entries
$collection = Mage::getModel('things/things')->getCollection();

मैंने कोशिश की है, लेकिन गलत प्रविष्टियों को आउटपुट करता है;

//thought strtotime('yesterday') would work..
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('yesterday'))));
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('-1 day'))));
$collection->addFieldToFilter('created_time', array('from'=> strtotime('-1 day', time()),'to'=> time(),'datetime' => true));
$fromDate = date('Y-m-d H:i:s', strtotime($fromDate));
$toDate = date('Y-m-d H:i:s', strtotime($toDate));
$collection->addFieldToFilter('created_time', array('from'=>$fromDate, 'to'=>$toDate));

आज बनाया गया (वर्तमान दिन) (काम करता है)

//5 products items today with timestamp 2016-05-01 05:22:53
//below filtering outputs correct entries
$collection = Mage::getModel('things/things')->getCollection();
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('today'))));

पिछले सप्ताह बनाया गया (काम करता है)

//23 products items with timestamps for this week
//below filtering outputs correct entries
$collection = Mage::getModel('things/things')->getCollection();
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('-1 week'))));

जवाबों:


10

@ अश्विन जवाब में जोड़ने के लिए ..

मुझे पिछले एक घंटे के भीतर प्रविष्टियां मिलीं

$things = Mage::getModel('things/things')->getCollection();
$things->addFieldToFilter('things_type', 'view');
$fromDate = date('Y-m-d H:i:s', strtotime('-1 hour'));
$toDate = date('Y-m-d H:i:s', strtotime(now()));
$things->addFieldToFilter('created_time', array(
    'from' => $fromDate,
    'to' => $toDate,
    'date' => true,
    ));
return count($things);

और मुझे कल की प्रविष्टियाँ कैसे मिलीं;

$now = Mage::getModel('core/date')->timestamp(time());
$dateStart = date('Y-m-d' . ' 00:00:00', $now);
$dateEnd = date('Y-m-d' . ' 23:59:59', $now);
$things = Mage::getModel('things/things')->getCollection();
$things->addFieldToFilter('things_type', 'view');
$things->addFieldToFilter('created_time', array('from' => $dateStart, 'to' => $dateEnd));
return count($things);

5

हम इसे कैसे हल करेंगे? सरल। पिछले 24 घंटों के लिए आदेश ग्रिड में प्रस्तुत किए गए आदेशों की मात्रा को सीमित करना, जब तक कि अन्यथा अनुरोध न किया गया हो।

उदाहरण: - एप्लिकेशन / कोड / कोर / Mage / Adminhtml / ब्लॉक / बिक्री / आदेश / ग्रिड.php फ़ाइल की प्रतिलिपि बनाएँ:

एप्लिकेशन / कोड / स्थानीय / दाना / Adminhtml / ब्लॉक / बिक्री / आदेश / Grid.php

निम्नलिखित फ़ंक्शन को संपादित करें, यहां से कॉपी-पेस्ट करें:

protected function _prepareCollection()    {

$collection = Mage::getResourceModel($this->_getCollectionClass());

######################## FILTER BY LAST DAY ######################
$now = Mage::getModel('core/date')->timestamp(time());
$filter   = $this->getParam($this->getVarNameFilter(), null); //important - check for other requested grid-filters before filtering today's orders

$dateStart = date('Y-m-d' . ' 00:00:00', $now);
$dateEnd = date('Y-m-d' . ' 23:59:59', $now);
$postData = Mage::app()->getRequest()->getPost();
if (empty($filter)) {
$collection->addFieldToFilter('`main_table`.created_at', array('from' => $dateStart, 'to' => $dateEnd));
}
##################################################################



$collection->getSelect()->group('entity_id');
$this->setCollection($collection);

return $this;

}

प्रश्न पूछने के लिए अधिक कोड का उपयोग करें ... (आज, कल, सप्ताह, घंटा आदि)


go0d @ashvin काम करता है
— अमित बेरा

अरे! महान समाधान! मैं इसे कैसे बदल सकता हूं, इसलिए यह केवल दो घंटे पहले के आदेशों को लेता है?
— व्लादिमीर डेस्पोटोविक
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.