コード例 #1
0
ファイル: Grid.php プロジェクト: xiaoguizhidao/ecommerce
 protected function _prepareCollection()
 {
     //--------------------------------
     // Get collection
     //----------------------------
     /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */
     $collection = Mage::getModel('catalog/product')->getCollection();
     $collection->addAttributeToSelect('sku');
     $collection->addAttributeToSelect('name');
     //--------------------------------
     // Join listing product tables
     //----------------------------
     $collection->joinTable(array('lp' => 'M2ePro/Listing_Product'), 'product_id=entity_id', array('id' => 'id', 'status' => 'status'), '{{table}}.listing_id=' . (int) $this->getListing()->getId());
     $collection->joinTable(array('elp' => 'M2ePro/Ebay_Listing_Product'), 'listing_product_id=id', array('listing_product_id' => 'listing_product_id', 'template_category_id' => 'template_category_id', 'template_other_category_id' => 'template_other_category_id', 'template_payment_mode' => 'template_payment_mode', 'template_shipping_mode' => 'template_shipping_mode', 'template_return_mode' => 'template_return_mode', 'template_description_mode' => 'template_description_mode', 'template_selling_format_mode' => 'template_selling_format_mode', 'template_synchronization_mode' => 'template_synchronization_mode', 'end_date' => 'end_date', 'start_date' => 'start_date', 'online_title' => 'online_title', 'online_sku' => 'online_sku', 'available_qty' => new Zend_Db_Expr('(online_qty - online_qty_sold)'), 'ebay_item_id' => 'ebay_item_id', 'online_category' => 'online_category', 'online_qty_sold' => 'online_qty_sold', 'online_buyitnow_price' => 'online_buyitnow_price'));
     $collection->joinTable(array('ei' => 'M2ePro/Ebay_Item'), 'id=ebay_item_id', array('item_id' => 'item_id'), NULL, 'left');
     $collection->joinTable(array('etc' => 'M2ePro/Ebay_Template_Category'), 'id=template_category_id', array('category_main_mode' => 'category_main_mode', 'category_main_id' => 'category_main_id', 'category_main_path' => 'category_main_path', 'category_main_attribute' => 'category_main_attribute'), NULL, 'left');
     $collection->joinTable(array('etoc' => 'M2ePro/Ebay_Template_OtherCategory'), 'id=template_other_category_id', array('category_secondary_mode' => 'category_secondary_mode', 'category_secondary_id' => 'category_secondary_id', 'category_secondary_path' => 'category_secondary_path', 'category_secondary_attribute' => 'category_secondary_attribute', 'store_category_main_mode' => 'store_category_main_mode', 'store_category_main_id' => 'store_category_main_id', 'store_category_main_path' => 'store_category_main_path', 'store_category_main_attribute' => 'store_category_main_attribute', 'store_category_secondary_mode' => 'store_category_secondary_mode', 'store_category_secondary_id' => 'store_category_secondary_id', 'store_category_secondary_path' => 'store_category_secondary_path', 'store_category_secondary_attribute' => 'store_category_secondary_attribute'), NULL, 'left');
     if ($this->motorsSpecificsAttribute) {
         $collection->addAttributeToSelect($this->motorsSpecificsAttribute->getAttributeCode());
         $collection->joinTable(array('eea' => Mage::getSingleton('core/resource')->getTableName('eav_entity_attribute')), 'attribute_set_id=attribute_set_id', array('is_motors_attribute_in_product_attribute_set' => 'entity_attribute_id'), '{{table}}.attribute_id = ' . $this->motorsSpecificsAttribute->getAttributeId(), 'left');
     }
     //----------------------------
     //        exit($collection->getSelect()->__toString());
     // Set collection to grid
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
コード例 #2
0
 protected function _prepareCollection()
 {
     $listingProductIds = $this->getListing()->getData('product_add_ids');
     $listingProductIds = array_filter((array) json_decode($listingProductIds));
     $listingProductIds = empty($listingProductIds) ? 0 : implode(',', $listingProductIds);
     // ---------------------------------------
     // Get collection
     // ---------------------------------------
     /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */
     $collection = Mage::getModel('catalog/product')->getCollection();
     $collection->addAttributeToSelect('sku');
     $collection->addAttributeToSelect('name');
     // ---------------------------------------
     // Join listing product tables
     // ---------------------------------------
     $collection->joinTable(array('lp' => 'M2ePro/Listing_Product'), 'product_id=entity_id', array('id' => 'id'), '{{table}}.id IN (' . $listingProductIds . ')');
     $collection->joinTable(array('elp' => 'M2ePro/Ebay_Listing_Product'), 'listing_product_id=id', array('listing_product_id' => 'listing_product_id', 'template_category_id' => 'template_category_id', 'template_payment_mode' => 'template_payment_mode', 'template_shipping_mode' => 'template_shipping_mode', 'template_return_mode' => 'template_return_mode', 'template_description_mode' => 'template_description_mode', 'template_selling_format_mode' => 'template_selling_format_mode', 'template_synchronization_mode' => 'template_synchronization_mode'));
     // ---------------------------------------
     // Set collection to grid
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
コード例 #3
0
ファイル: Grid.php プロジェクト: ReeceCrossland/essua-m2epro
 protected function _prepareCollection()
 {
     // ---------------------------------------
     // Get collection
     // ---------------------------------------
     /* @var $collection Ess_M2ePro_Model_Mysql4_Magento_Product_Collection */
     $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection', Mage::getModel('catalog/product')->getResource());
     $collection->addAttributeToSelect('sku');
     $collection->addAttributeToSelect('name');
     // ---------------------------------------
     // Join listing product tables
     // ---------------------------------------
     $collection->joinTable(array('lp' => 'M2ePro/Listing_Product'), 'product_id=entity_id', array('id' => 'id', 'ebay_status' => 'status'), '{{table}}.listing_id=' . (int) $this->getListing()->getId());
     $collection->joinTable(array('elp' => 'M2ePro/Ebay_Listing_Product'), 'listing_product_id=id', array('listing_product_id' => 'listing_product_id', 'template_category_id' => 'template_category_id', 'template_other_category_id' => 'template_other_category_id', 'template_payment_mode' => 'template_payment_mode', 'template_shipping_mode' => 'template_shipping_mode', 'template_return_mode' => 'template_return_mode', 'template_description_mode' => 'template_description_mode', 'template_selling_format_mode' => 'template_selling_format_mode', 'template_synchronization_mode' => 'template_synchronization_mode', 'end_date' => 'end_date', 'start_date' => 'start_date', 'online_title' => 'online_title', 'online_sku' => 'online_sku', 'available_qty' => new Zend_Db_Expr('(online_qty - online_qty_sold)'), 'ebay_item_id' => 'ebay_item_id', 'online_category' => 'online_category', 'online_qty_sold' => 'online_qty_sold', 'online_start_price' => 'online_start_price', 'online_current_price' => 'online_current_price', 'online_reserve_price' => 'online_reserve_price', 'online_buyitnow_price' => 'online_buyitnow_price', 'min_online_price' => 'IF(
                 (`t`.`variation_min_price` IS NULL),
                 `elp`.`online_current_price`,
                 `t`.`variation_min_price`
             )', 'max_online_price' => 'IF(
                 (`t`.`variation_max_price` IS NULL),
                 `elp`.`online_current_price`,
                 `t`.`variation_max_price`
             )'));
     $collection->joinTable(array('ei' => 'M2ePro/Ebay_Item'), 'id=ebay_item_id', array('item_id' => 'item_id'), NULL, 'left');
     $collection->joinTable(array('etc' => 'M2ePro/Ebay_Template_Category'), 'id=template_category_id', array('category_main_mode' => 'category_main_mode', 'category_main_id' => 'category_main_id', 'category_main_path' => 'category_main_path', 'category_main_attribute' => 'category_main_attribute'), NULL, 'left');
     $collection->joinTable(array('etoc' => 'M2ePro/Ebay_Template_OtherCategory'), 'id=template_other_category_id', array('category_secondary_mode' => 'category_secondary_mode', 'category_secondary_id' => 'category_secondary_id', 'category_secondary_path' => 'category_secondary_path', 'category_secondary_attribute' => 'category_secondary_attribute', 'store_category_main_mode' => 'store_category_main_mode', 'store_category_main_id' => 'store_category_main_id', 'store_category_main_path' => 'store_category_main_path', 'store_category_main_attribute' => 'store_category_main_attribute', 'store_category_secondary_mode' => 'store_category_secondary_mode', 'store_category_secondary_id' => 'store_category_secondary_id', 'store_category_secondary_path' => 'store_category_secondary_path', 'store_category_secondary_attribute' => 'store_category_secondary_attribute'), NULL, 'left');
     if ($this->motorsAttribute) {
         $collection->addAttributeToSelect($this->motorsAttribute->getAttributeCode());
         $collection->joinTable(array('eea' => Mage::getSingleton('core/resource')->getTableName('eav_entity_attribute')), 'attribute_set_id=attribute_set_id', array('is_motors_attribute_in_product_attribute_set' => 'entity_attribute_id'), '{{table}}.attribute_id = ' . $this->motorsAttribute->getAttributeId(), 'left');
     }
     $collection->getSelect()->joinLeft(new Zend_Db_Expr('(
             SELECT
                 `mlpv`.`listing_product_id`,
                 MIN(`melpv`.`online_price`) as variation_min_price,
                 MAX(`melpv`.`online_price`) as variation_max_price
             FROM `' . Mage::getResourceModel('M2ePro/Listing_Product_Variation')->getMainTable() . '` AS `mlpv`
             INNER JOIN `' . Mage::getResourceModel('M2ePro/Ebay_Listing_Product_Variation')->getMainTable() . '` AS `melpv`
                 ON (`mlpv`.`id` = `melpv`.`listing_product_variation_id`)
             WHERE `melpv`.`status` != ' . Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED . '
             GROUP BY `mlpv`.`listing_product_id`
         )'), 'elp.listing_product_id=t.listing_product_id', array('variation_min_price' => 'variation_min_price', 'variation_max_price' => 'variation_max_price'));
     // ---------------------------------------
     // Set collection to grid
     $this->setCollection($collection);
     parent::_prepareCollection();
     if ($this->isMotorsAvailable()) {
         $this->prepareExistingMotorsData();
     }
     return $this;
 }