Exemple #1
0
 /**
  * Update attribute values for entity list per store
  *
  * @param array $entityIds
  * @param array $attrData
  * @param int $storeId
  * @return $this
  * @throws \Exception
  */
 public function updateAttributes($entityIds, $attrData, $storeId)
 {
     $object = new \Magento\Framework\Object();
     $object->setIdFieldName('entity_id')->setStoreId($storeId);
     $this->_getWriteAdapter()->beginTransaction();
     try {
         foreach ($attrData as $attrCode => $value) {
             $attribute = $this->getAttribute($attrCode);
             if (!$attribute->getAttributeId()) {
                 continue;
             }
             $i = 0;
             foreach ($entityIds as $entityId) {
                 $i++;
                 $object->setId($entityId);
                 // collect data for save
                 $this->_saveAttributeValue($object, $attribute, $value);
                 // save collected data every 1000 rows
                 if ($i % 1000 == 0) {
                     $this->_processAttributeValues();
                 }
             }
             $this->_processAttributeValues();
         }
         $this->_getWriteAdapter()->commit();
     } catch (\Exception $e) {
         $this->_getWriteAdapter()->rollBack();
         throw $e;
     }
     return $this;
 }
Exemple #2
0
 /**
  * Retrieve Product Emulator (Magento Object)
  *
  * @param string $typeId
  * @return \Magento\Framework\Object
  */
 protected function getProductEmulator($typeId)
 {
     if (!isset($this->productEmulators[$typeId])) {
         $productEmulator = new \Magento\Framework\Object();
         $productEmulator->setIdFieldName('entity_id')->setTypeId($typeId);
         $this->productEmulators[$typeId] = $productEmulator;
     }
     return $this->productEmulators[$typeId];
 }
Exemple #3
0
 /**
  * Retrieve table status
  *
  * @param string $tableName
  * @return \Magento\Framework\Object|bool
  */
 public function getTableStatus($tableName)
 {
     $row = $this->_write->showTableStatus($tableName);
     if ($row) {
         $statusObject = new \Magento\Framework\Object();
         $statusObject->setIdFieldName('name');
         foreach ($row as $field => $value) {
             $statusObject->setData(strtolower($field), $value);
         }
         $cntRow = $this->_write->fetchRow($this->_write->select()->from($tableName, 'COUNT(1) as rows'));
         $statusObject->setRows($cntRow['rows']);
         return $statusObject;
     }
     return false;
 }
Exemple #4
0
 /**
  * Retrieve Product data objects
  *
  * @param int|array $productIds
  * @param int $storeId
  * @param int $entityId
  * @param int &$lastEntityId
  * @return array
  */
 protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId)
 {
     $products = array();
     $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
     $adapter = $this->_getReadAdapter();
     if ($productIds !== null) {
         if (!is_array($productIds)) {
             $productIds = array($productIds);
         }
     }
     $bind = array('website_id' => (int) $websiteId, 'entity_id' => (int) $entityId);
     $select = $adapter->select()->useStraightJoin(true)->from(array('e' => $this->getTable('catalog_product_entity')), array('entity_id'))->join(array('w' => $this->getTable('catalog_product_website')), 'e.entity_id = w.product_id AND w.website_id = :website_id', array())->where('e.entity_id > :entity_id')->order('e.entity_id')->limit($this->_productLimit);
     if ($productIds !== null) {
         $select->where('e.entity_id IN(?)', $productIds);
     }
     $rowSet = $adapter->fetchAll($select, $bind);
     foreach ($rowSet as $row) {
         $product = new \Magento\Framework\Object($row);
         $product->setIdFieldName('entity_id');
         $product->setCategoryIds(array());
         $product->setStoreId($storeId);
         $products[$product->getId()] = $product;
         $lastEntityId = $product->getId();
     }
     unset($rowSet);
     if ($products) {
         $select = $adapter->select()->from($this->getTable('catalog_category_product'), array('product_id', 'category_id'))->where('product_id IN(?)', array_keys($products));
         $categories = $adapter->fetchAll($select);
         foreach ($categories as $category) {
             $productId = $category['product_id'];
             $categoryIds = $products[$productId]->getCategoryIds();
             $categoryIds[] = $category['category_id'];
             $products[$productId]->setCategoryIds($categoryIds);
         }
         foreach (array('name', 'url_key', 'url_path') as $attributeCode) {
             $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId);
             foreach ($attributes as $productId => $attributeValue) {
                 $products[$productId]->setData($attributeCode, $attributeValue);
             }
         }
     }
     return $products;
 }