* * @category Unirgy * @package Unirgy_Dropship * @copyright Copyright (c) 2008-2009 Unirgy LLC (http://www.unirgy.com) * @license http:///www.unirgy.com/LICENSE-M1.txt */ $this->startSetup(); $conn = $this->_conn; if (Mage::helper('udropship')->isSalesFlat()) { $searchSelect = $conn->select()->from(array('po' => $this->getTable('sales/shipment')), array('entity_id'))->joinLeft(array('vs' => $this->getTable('udropship/vendor_statement')), 'vs.statement_id=po.statement_id', array())->where("po.statement_id is not null and po.statement_id!='' and vs.statement_id is null"); $updateSelect = $conn->select()->join(array('_orp' => $searchSelect), '_orp.entity_id=_po.entity_id', array())->columns(array('statement_id' => new Zend_Db_Expr('NULL'))); $updateSql = $updateSelect->crossUpdateFromSelect(array('_po' => $this->getTable('sales/shipment'))); //print $updateSql."\n\n\n"; $conn->raw_query($updateSql); $updateSql = $updateSelect->crossUpdateFromSelect(array('_po' => $this->getTable('sales/shipment_grid'))); //print $updateSql."\n\n\n"; $conn->raw_query($updateSql); } else { $eav = new Mage_Sales_Model_Mysql4_Setup('sales_setup'); $poAttr = $eav->getAttribute('shipment', 'statement_id'); $sET = $eav->getEntityType('shipment'); $searchSelect = $conn->select()->from(array('orp' => $this->getTable($sET['entity_table']) . '_' . $poAttr['backend_type']), array('entity_id'))->joinLeft(array('vs' => $this->getTable('udropship/vendor_statement')), 'vs.statement_id=orp.value', array())->where("orp.value is not null and orp.value!='' and vs.statement_id is null")->where('orp.attribute_id=?', $poAttr['attribute_id']); //print $searchSelect."\n\n\n"; $poIds = $conn->fetchCol($searchSelect); //print_r($poIds); if (!empty($poIds)) { $conn->delete($this->getTable($sET['entity_table']) . '_' . $poAttr['backend_type'], $conn->quoteInto('entity_id in (?) ', $poIds) . $conn->quoteInto(' and attribute_id=?', $poAttr['attribute_id'])); } } //throw new Exception('test'); $this->endSetup();
<?php require_once 'app/Mage.php'; Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID)); $installer = new Mage_Sales_Model_Mysql4_Setup(); //Mage_Eav_Model_Entity_Setup,Mage_Catalog_Model_Resource_Setup, $installer->startSetup(); if (!$installer->getAttribute('catalog_category', 'sw_product_staticblock_tab_1', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_staticblock_tab_1', array('group' => 'Product Custom Tabs', 'label' => 'CMS Block Tab #1', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); } if (!$installer->getAttribute('catalog_category', 'sw_product_staticblock_tab_2', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_staticblock_tab_2', array('group' => 'Product Custom Tabs', 'label' => 'CMS Block Tab #2', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); } if (!$installer->getAttribute('catalog_category', 'sw_product_staticblock_tab_3', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_staticblock_tab_3', array('group' => 'Product Custom Tabs', 'label' => 'CMS Block Tab #3', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); } if (!$installer->getAttribute('catalog_category', 'sw_product_staticblock_tab_4', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_staticblock_tab_4', array('group' => 'Product Custom Tabs', 'label' => 'CMS Block Tab #4', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); } if (!$installer->getAttribute('catalog_category', 'sw_product_staticblock_tab_5', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_staticblock_tab_5', array('group' => 'Product Custom Tabs', 'label' => 'CMS Block Tab #5', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); } if (!$installer->getAttribute('catalog_category', 'sw_product_attribute_tab_1', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_attribute_tab_1', array('group' => 'Product Custom Tabs', 'label' => 'Attribute Tab #1', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); } if (!$installer->getAttribute('catalog_category', 'sw_product_attribute_tab_2', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_attribute_tab_2', array('group' => 'Product Custom Tabs', 'label' => 'Attribute Tab #2', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); } if (!$installer->getAttribute('catalog_category', 'sw_product_attribute_tab_3', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_attribute_tab_3', array('group' => 'Product Custom Tabs', 'label' => 'Attribute Tab #3', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); }
<?php require_once 'app/Mage.php'; Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID)); $installer = new Mage_Sales_Model_Mysql4_Setup(); //Mage_Eav_Model_Entity_Setup,Mage_Catalog_Model_Resource_Setup, $installer->startSetup(); if (!$installer->getAttribute('catalog_category', 'sw_product_staticblock_tab_6', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_staticblock_tab_6', array('group' => 'Product Custom Tabs', 'label' => 'CMS Block Tab #6', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); } if (!$installer->getAttribute('catalog_category', 'sw_product_staticblock_tab_7', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_staticblock_tab_7', array('group' => 'Product Custom Tabs', 'label' => 'CMS Block Tab #7', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); } if (!$installer->getAttribute('catalog_category', 'sw_product_staticblock_tab_8', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_staticblock_tab_8', array('group' => 'Product Custom Tabs', 'label' => 'CMS Block Tab #8', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); } if (!$installer->getAttribute('catalog_category', 'sw_product_staticblock_tab_9', 'attribute_id')) { $installer->addAttribute('catalog_category', 'sw_product_staticblock_tab_9', array('group' => 'Product Custom Tabs', 'label' => 'CMS Block Tab #9', 'note' => "", 'type' => 'varchar', 'input' => 'select', 'source' => 'porto/category_attribute_source_tab_mode', 'visible' => true, 'required' => false, 'backend' => '', 'frontend' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'user_defined' => true, 'visible_on_front' => true, 'wysiwyg_enabled' => false, 'is_html_allowed_on_front' => false, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE)); } $installer->endSetup();
$vendor->afterLoad(); if ('shipment' == $vendor->getStatementPoType()) { $stPoStatuses = $vendor->getData('statement_po_status'); if (!is_array($stPoStatuses)) { $stPoStatuses = explode(',', $stPoStatuses); } $sdInsSelect = sprintf("INSERT INTO %s (entity_id,statement_date) %s ON DUPLICATE KEY UPDATE statement_date=values(statement_date)", $this->getTable('sales_flat_shipment'), $this->_conn->select()->from(array('st' => $this->getTable('sales_flat_shipment')), array())->where('st.udropship_vendor=?', $vendor->getId())->where('st.udropship_status in (?)', $stPoStatuses)->columns(array('entity_id', 'statement_date' => 'st.created_at'))); $this->_conn->query($sdInsSelect); $sdInsSelect = sprintf("INSERT INTO %s (entity_id,statement_date) %s ON DUPLICATE KEY UPDATE statement_date=values(statement_date)", $this->getTable('sales_flat_shipment_grid'), $this->_conn->select()->from(array('st' => $this->getTable('sales_flat_shipment')), array())->join(array('stg' => $this->getTable('sales_flat_shipment_grid')), 'stg.entity_id=st.entity_id', array())->where('st.udropship_vendor=?', $vendor->getId())->where('st.udropship_status in (?)', $stPoStatuses)->columns(array('entity_id', 'statement_date' => 'st.created_at'))); $this->_conn->query($sdInsSelect); } } } else { $eav = new Mage_Sales_Model_Mysql4_Setup('sales_setup'); $eav->addAttribute('shipment', 'statement_date', array('type' => 'datetime')); $sdAttr = $eav->getAttribute('shipment', 'statement_date'); $vAttr = $eav->getAttribute('shipment', 'udropship_vendor'); $udsAttr = $eav->getAttribute('shipment', 'udropship_status'); $sET = $eav->getEntityType('shipment'); $sTbl = $this->getTable($sET['entity_table']); $sdTbl = $sTbl . '_' . $sdAttr['backend_type']; $vTbl = $sTbl . '_' . $vAttr['backend_type']; $udsTbl = $sTbl . '_' . $udsAttr['backend_type']; $vJoinCond = implode(' and ', array('vt.entity_id=st.entity_id', $this->_conn->quoteInto('vt.attribute_id=?', $vAttr['attribute_id']), $this->_conn->quoteInto('vt.entity_type_id=?', $sET['entity_type_id']))); $udsJoinCond = implode(' and ', array('udst.entity_id=st.entity_id', $this->_conn->quoteInto('udst.attribute_id=?', $udsAttr['attribute_id']), $this->_conn->quoteInto('udst.entity_type_id=?', $sET['entity_type_id']))); $vendors = Mage::getResourceModel('udropship/vendor_collection'); foreach ($vendors as $vendor) { $vendor->afterLoad(); if ('shipment' == $vendor->getStatementPoType()) { $stPoStatuses = $vendor->getData('statement_po_status'); if (!is_array($stPoStatuses)) {