Created
July 28, 2014 15:32
-
-
Save ceckoslab/4e60422bff99e314d8cc to your computer and use it in GitHub Desktop.
Example snippet of helper class, that checks if the order items are owned by the current customer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @author Tsvetan Stoychev <tsvetan.stoychev@jarlssen.de> | |
| * @website http://www.jarlssen.de | |
| */ | |
| class MyCompany_MyModule_Helper_Data extends Mage_Core_Helper_Abstract | |
| { | |
| /** @var Varien_Db_Adapter_Interface $readConnection */ | |
| protected $_readConnection; | |
| /** | |
| * @param array $itemIds | |
| * @return bool | |
| */ | |
| public function canModifyOrderItems($itemIds) | |
| { | |
| $select = $this->_getReadConnection()->select() | |
| ->from(array('oi' => $this->_getResource()->getTableName('sales/order_item')), array('item_id')) | |
| ->where($this->_getReadConnection()->quoteInto('oi.item_id IN (?)', implode(',', $itemIds))); | |
| $select->joinRight( | |
| array('o' => $this->_getResource()->getTableName('sales/order'), array('customer_id')), | |
| $this->_getReadConnection()->quoteInto('oi.order_id = o.entity_id and o.customer_id != ?', $this->_getCustomerId()), | |
| array('customer_id') | |
| ); | |
| $result = $this->_getReadConnection()->fetchRow($select); | |
| return empty($result) ? true : false; | |
| } | |
| /** | |
| * Getter for the read connection | |
| * | |
| * @return Varien_Db_Adapter_Interface | |
| */ | |
| protected function _getReadConnection() | |
| { | |
| if(null === $this->_readConnection) { | |
| $this->_readConnection = $this->_getResource()->getConnection(Mage_Core_Model_Resource::DEFAULT_READ_RESOURCE); | |
| } | |
| return $this->_readConnection; | |
| } | |
| /** | |
| * Getter of the resource model | |
| * | |
| * @return Mage_Core_Model_Resource | |
| */ | |
| protected function _getResource() | |
| { | |
| return Mage::getSingleton('core/resource'); | |
| } | |
| protected function _getCustomerId() | |
| { | |
| return (int) $this->_getSession()->getCustomerId(); | |
| } | |
| /** | |
| * Get checkout session model instance | |
| * | |
| * @return Mage_Customer_Model_Session | |
| */ | |
| protected function _getSession() | |
| { | |
| return Mage::getSingleton('customer/session'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment