Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace NamespaceInventoryManagementHelperProduct;
- /**
- * Created by PhpStorm.
- * User: abbas
- * Date: 17. 7. 14
- * Time: 오후 4:02
- */
- use MagentoFrameworkAppHelperAbstractHelper;
- class Inventory extends AbstractHelper
- {
- /**
- * @var MagentoCatalogModelProductFactory
- */
- protected $_productFactory;
- /**
- * Store manager
- *
- * @var MagentoStoreModelStoreManagerInterface
- */
- protected $_storeManager;
- /**
- * Status constructor.
- * @param MagentoFrameworkAppHelperContext $context
- * @param MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory
- */
- public function __construct(
- MagentoFrameworkAppHelperContext $context,
- MagentoCatalogModelProductFactory $productFactory,
- MagentoStoreModelStoreManagerInterface $storeManager
- )
- {
- parent::__construct($context);
- $this->_productFactory = $productFactory;
- $this->_storeManager = $storeManager;
- }
- /**
- * @return Store
- */
- protected function _getStore()
- {
- $storeId = 2;//(int)$this->getRequest()->getParam('store', 0);
- return $this->_storeManager->getStore($storeId);
- }
- public function getInventory($storeCode){
- try {
- $result = array();
- $store = $this->_getStore();
- $collection = $this->_productFactory->create()->getCollection()->addAttributeToSelect(
- 'sku'
- )->addAttributeToSelect(
- 'name'
- )->addAttributeToSelect(
- 'attribute_set_id'
- )->addAttributeToSelect(
- 'type_id'
- )->setStore(
- $store
- );
- $collection->addStoreFilter($store);
- $i = 0;
- /**
- * @var MagentoCatalogModelProduct $product
- */
- foreach ($collection as $product){
- if($product->getData('transferred'))
- {
- continue;
- }
- $result[] = $i;
- $i++;
- }
- }
- catch (Exception $e){
- $success = false;
- if($product) {
- $result = $e->getMessage() . ' == ' . $product->getSku();
- }else{
- $result = $e->getMessage();
- }
- }
- return $result;
- }
- }
- public function getProducts(){
- return $this->collection->addStoreFilter($this->_storeManager->getStore());
- }
- $storeId = 2;
- $collection->addStoreFilter($storeId);
- $collection->addStoreFilter($store);
Add Comment
Please, Sign In to add comment