Beispiel #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\DataObject();
     $object->setStoreId($storeId);
     $this->getConnection()->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);
                 $object->setEntityId($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->getConnection()->commit();
     } catch (\Exception $e) {
         $this->getConnection()->rollBack();
         throw $e;
     }
     return $this;
 }
 /**
  * Prepare page object
  *
  * @param array $data
  * @return \Magento\Framework\DataObject
  */
 protected function _prepareObject(array $data)
 {
     $object = new \Magento\Framework\DataObject();
     $object->setId($data[$this->getIdFieldName()]);
     $object->setUrl($data['url']);
     $object->setUpdatedAt($data['updated_at']);
     return $object;
 }
Beispiel #3
0
 /**
  * @covers \Magento\Email\Block\Adminhtml\Template\Grid\Renderer\Action::render
  */
 public function testRender()
 {
     $this->columnMock->expects($this->once())->method('setActions');
     $this->columnMock->expects($this->once())->method('getActions')->willReturn(['url', 'popup', 'caption']);
     $this->action->setColumn($this->columnMock);
     $row = new \Magento\Framework\DataObject();
     $row->setId(1);
     $this->assertContains('admin__control-select', $this->action->render($row));
 }
 /**
  * Add new massaction item
  *
  * Item array to be passed in looks like:
  * $item = array(
  *      'label'    => string,
  *      'complete' => string, // Only for ajax enabled grid (optional)
  *      'url'      => string,
  *      'confirm'  => string, // text of confirmation of this action (optional)
  *      'additional' => string // (optional)
  * );
  *
  * @param string $itemId
  * @param array|\Magento\Framework\DataObject $item
  * @return $this
  */
 public function addItem($itemId, $item)
 {
     if (is_array($item)) {
         $item = new \Magento\Framework\DataObject($item);
     }
     if ($item instanceof \Magento\Framework\DataObject) {
         $item->setId($itemId);
         $item->setUrl($this->getUrl($item->getUrl()));
         $this->_items[$itemId] = $item;
     }
     return $this;
 }
 public function testGetAffectedFields()
 {
     $valueId = 10;
     $attributeId = 42;
     $attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['getBackendTable', 'isStatic', 'getAttributeId', 'getName', '__wakeup'], [], '', false);
     $attribute->expects($this->any())->method('getAttributeId')->will($this->returnValue($attributeId));
     $attribute->expects($this->any())->method('isStatic')->will($this->returnValue(false));
     $attribute->expects($this->any())->method('getBackendTable')->will($this->returnValue('table'));
     $attribute->expects($this->any())->method('getName')->will($this->returnValue('tear_price'));
     $this->_model->setAttribute($attribute);
     $object = new \Magento\Framework\DataObject();
     $object->setTearPrice([['price_id' => 10]]);
     $object->setId(555);
     $this->assertEquals(['table' => [['value_id' => $valueId, 'attribute_id' => $attributeId, 'entity_id' => $object->getId()]]], $this->_model->getAffectedFields($object));
 }
 public function testGetAffectedFields()
 {
     $valueId = 2345;
     $attributeId = 345345;
     $attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute', ['getBackendTable', 'isStatic', 'getAttributeId', 'getName', '__wakeup'], [], '', false);
     $attribute->expects($this->any())->method('getName')->will($this->returnValue('image'));
     $attribute->expects($this->any())->method('getAttributeId')->will($this->returnValue($attributeId));
     $attribute->expects($this->any())->method('isStatic')->will($this->returnValue(false));
     $attribute->expects($this->any())->method('getBackendTable')->will($this->returnValue('table'));
     $this->attributeRepository->expects($this->once())->method('get')->with('media_gallery')->willReturn($attribute);
     $object = new \Magento\Framework\DataObject();
     $object->setImage(['images' => [['value_id' => $valueId]]]);
     $object->setId(555);
     $this->assertEquals([\Magento\Catalog\Model\ResourceModel\Product\Gallery::GALLERY_TABLE => [['value_id' => $valueId, 'attribute_id' => 345345, 'entity_id' => $object->getId()]]], $this->model->getAffectedFields($object));
 }
Beispiel #7
0
 /**
  * Prepare category
  *
  * @param array $categoryRow
  * @return \Magento\Framework\DataObject
  */
 protected function _prepareCategory(array $categoryRow)
 {
     $category = new \Magento\Framework\DataObject();
     $category->setId($categoryRow[$this->getIdFieldName()]);
     $categoryUrl = !empty($categoryRow['url']) ? $categoryRow['url'] : 'catalog/category/view/id/' . $category->getId();
     $category->setUrl($categoryUrl);
     $category->setUpdatedAt($categoryRow['updated_at']);
     return $category;
 }
Beispiel #8
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 = [];
     $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
     $connection = $this->getConnection();
     if ($productIds !== null) {
         if (!is_array($productIds)) {
             $productIds = [$productIds];
         }
     }
     $bind = ['website_id' => (int) $websiteId, 'entity_id' => (int) $entityId];
     $select = $connection->select()->useStraightJoin(true)->from(['e' => $this->getTable('catalog_product_entity')], ['entity_id'])->join(['w' => $this->getTable('catalog_product_website')], 'e.entity_id = w.product_id AND w.website_id = :website_id', [])->where('e.entity_id > :entity_id')->order('e.entity_id')->limit($this->_productLimit);
     if ($productIds !== null) {
         $select->where('e.entity_id IN(?)', $productIds);
     }
     $rowSet = $connection->fetchAll($select, $bind);
     foreach ($rowSet as $row) {
         $product = new \Magento\Framework\DataObject($row);
         $product->setId($row['entity_id']);
         $product->setEntityId($row['entity_id']);
         $product->setCategoryIds([]);
         $product->setStoreId($storeId);
         $products[$product->getId()] = $product;
         $lastEntityId = $product->getId();
     }
     unset($rowSet);
     if ($products) {
         $select = $connection->select()->from($this->getTable('catalog_category_product'), ['product_id', 'category_id'])->where('product_id IN(?)', array_keys($products));
         $categories = $connection->fetchAll($select);
         foreach ($categories as $category) {
             $productId = $category['product_id'];
             $categoryIds = $products[$productId]->getCategoryIds();
             $categoryIds[] = $category['category_id'];
             $products[$productId]->setCategoryIds($categoryIds);
         }
         foreach (['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;
 }