Guest User

Untitled

a guest
Oct 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. <?php
  2. namespace NamespaceInventoryManagementHelperProduct;
  3.  
  4. /**
  5. * Created by PhpStorm.
  6. * User: abbas
  7. * Date: 17. 7. 14
  8. * Time: 오후 4:02
  9. */
  10.  
  11. use MagentoFrameworkAppHelperAbstractHelper;
  12.  
  13. class Inventory extends AbstractHelper
  14. {
  15.  
  16. /**
  17. * @var MagentoCatalogModelProductFactory
  18. */
  19. protected $_productFactory;
  20.  
  21. /**
  22. * Store manager
  23. *
  24. * @var MagentoStoreModelStoreManagerInterface
  25. */
  26. protected $_storeManager;
  27.  
  28.  
  29. /**
  30. * Status constructor.
  31. * @param MagentoFrameworkAppHelperContext $context
  32. * @param MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
  33. */
  34. public function __construct(
  35. MagentoFrameworkAppHelperContext $context,
  36. MagentoCatalogModelProductFactory $productFactory,
  37. MagentoStoreModelStoreManagerInterface $storeManager
  38. )
  39. {
  40. parent::__construct($context);
  41. $this->_productFactory = $productFactory;
  42. $this->_storeManager = $storeManager;
  43. }
  44.  
  45. /**
  46. * @return Store
  47. */
  48. protected function _getStore()
  49. {
  50. $storeId = 2;//(int)$this->getRequest()->getParam('store', 0);
  51. return $this->_storeManager->getStore($storeId);
  52. }
  53.  
  54.  
  55.  
  56. public function getInventory($storeCode){
  57. try {
  58. $result = array();
  59.  
  60. $store = $this->_getStore();
  61.  
  62. $collection = $this->_productFactory->create()->getCollection()->addAttributeToSelect(
  63. 'sku'
  64. )->addAttributeToSelect(
  65. 'name'
  66. )->addAttributeToSelect(
  67. 'attribute_set_id'
  68. )->addAttributeToSelect(
  69. 'type_id'
  70. )->setStore(
  71. $store
  72. );
  73.  
  74. $collection->addStoreFilter($store);
  75.  
  76. $i = 0;
  77. /**
  78. * @var MagentoCatalogModelProduct $product
  79. */
  80. foreach ($collection as $product){
  81. if($product->getData('transferred'))
  82. {
  83. continue;
  84. }
  85. $result[] = $i;
  86. $i++;
  87. }
  88. }
  89. catch (Exception $e){
  90. $success = false;
  91. if($product) {
  92. $result = $e->getMessage() . ' == ' . $product->getSku();
  93. }else{
  94. $result = $e->getMessage();
  95. }
  96. }
  97.  
  98. return $result;
  99.  
  100. }
  101.  
  102.  
  103. }
  104.  
  105. public function getProducts(){
  106. return $this->collection->addStoreFilter($this->_storeManager->getStore());
  107. }
  108.  
  109. $storeId = 2;
  110. $collection->addStoreFilter($storeId);
  111.  
  112. $collection->addStoreFilter($store);
Add Comment
Please, Sign In to add comment