Store.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Model\ResourceModel\Entity;
  7. use Magento\Framework\Model\AbstractModel;
  8. use Magento\Framework\DataObject;
  9. /**
  10. * Eav Entity store resource model
  11. *
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. */
  14. class Store extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  15. {
  16. /**
  17. * Resource initialization
  18. *
  19. * @return void
  20. * @codeCoverageIgnore
  21. */
  22. protected function _construct()
  23. {
  24. $this->_init('eav_entity_store', 'entity_store_id');
  25. }
  26. /**
  27. * Load an object by entity type and store
  28. *
  29. * @param Object|\Magento\Framework\Model\AbstractModel $object
  30. * @param int $entityTypeId
  31. * @param int $storeId
  32. * @return bool
  33. */
  34. public function loadByEntityStore(AbstractModel $object, $entityTypeId, $storeId)
  35. {
  36. $connection = $this->getConnection();
  37. $bind = [':entity_type_id' => $entityTypeId, ':store_id' => $storeId];
  38. $select = $connection->select()->from(
  39. $this->getMainTable()
  40. )->forUpdate(
  41. true
  42. )->where(
  43. 'entity_type_id = :entity_type_id'
  44. )->where(
  45. 'store_id = :store_id'
  46. );
  47. $data = $connection->fetchRow($select, $bind);
  48. if (!$data) {
  49. return false;
  50. }
  51. $object->setData($data);
  52. $this->_afterLoad($object);
  53. return true;
  54. }
  55. }