Exemplo n.º 1
0
 /**
  * Creates a collection item that represents a customer for the customer Grid.
  *
  * @param CustomerDetails $customerDetail Input data for creating the item.
  * @return \Magento\Framework\Object Collection item that represents a customer
  */
 protected function createCustomerDetailItem(CustomerDetails $customerDetail)
 {
     $customer = $customerDetail->getCustomer();
     $customerNameParts = array($customer->getPrefix(), $customer->getFirstname(), $customer->getMiddlename(), $customer->getLastname(), $customer->getSuffix());
     $customerItem = new \Magento\Framework\Object();
     $customerItem->setId($customer->getId());
     $customerItem->setEntityId($customer->getId());
     // All parts of the customer name must be displayed in the name column of the grid
     $customerItem->setName(implode(' ', array_filter($customerNameParts)));
     $customerItem->setEmail($customer->getEmail());
     $customerItem->setWebsiteId($customer->getWebsiteId());
     $customerItem->setCreatedAt($customer->getCreatedAt());
     $customerItem->setGroupId($customer->getGroupId());
     $billingAddress = null;
     foreach ($customerDetail->getAddresses() as $address) {
         if ($address->isDefaultBilling()) {
             $billingAddress = $address;
             break;
         }
     }
     if ($billingAddress !== null) {
         $customerItem->setBillingTelephone($billingAddress->getTelephone());
         $customerItem->setBillingPostcode($billingAddress->getPostcode());
         $customerItem->setBillingCountryId($billingAddress->getCountryId());
         $region = is_null($billingAddress->getRegion()) ? '' : $billingAddress->getRegion()->getRegion();
         $customerItem->setBillingRegion($region);
     }
     return $customerItem;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 /**
  * Prepare page object
  *
  * @param array $data
  * @return \Magento\Framework\Object
  */
 protected function _prepareObject(array $data)
 {
     $object = new \Magento\Framework\Object();
     $object->setId($data[$this->getIdFieldName()]);
     $object->setUrl($data['url']);
     $object->setUpdatedAt($data['updated_at']);
     return $object;
 }
Exemplo n.º 4
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\Object();
     $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\Object $item
  * @return $this
  */
 public function addItem($itemId, $item)
 {
     if (is_array($item)) {
         $item = new \Magento\Framework\Object($item);
     }
     if ($item instanceof \Magento\Framework\Object) {
         $item->setId($itemId);
         $item->setUrl($this->getUrl($item->getUrl()));
         $this->_items[$itemId] = $item;
     }
     return $this;
 }
Exemplo n.º 6
0
 public function testGetAffectedFields()
 {
     $valueId = 2345;
     $attributeId = 345345;
     $attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['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->model->setAttribute($attribute);
     $object = new \Magento\Framework\Object();
     $object->setImage(['images' => [['value_id' => $valueId]]]);
     $object->setId(555);
     $this->assertEquals(['table' => [['value_id' => $valueId, 'attribute_id' => $attributeId, 'entity_id' => $object->getId()]]], $this->model->getAffectedFields($object));
 }
Exemplo n.º 7
0
 public function testGetAffectedFields()
 {
     $valueId = 10;
     $attributeId = 42;
     $attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', array('getBackendTable', 'isStatic', 'getAttributeId', 'getName', '__wakeup'), array(), '', 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('group_price'));
     $this->_model->setAttribute($attribute);
     $object = new \Magento\Framework\Object();
     $object->setGroupPrice(array(array('price_id' => 10)));
     $object->setId(555);
     $this->assertEquals(array('table' => array(array('value_id' => $valueId, 'attribute_id' => $attributeId, 'entity_id' => $object->getId()))), $this->_model->getAffectedFields($object));
 }
Exemplo n.º 8
0
 /**
  * @return void
  */
 public function execute()
 {
     $response = new \Magento\Framework\Object();
     $id = $this->getRequest()->getParam('id');
     if (intval($id) > 0) {
         $product = $this->productRepository->getById($id);
         $response->setId($id);
         $response->addData($product->getData());
         $response->setError(0);
     } else {
         $response->setError(1);
         $response->setMessage(__('We can\'t get the product ID.'));
     }
     $this->getResponse()->representJson($response->toJSON());
 }
Exemplo n.º 9
0
 /**
  * @return void
  */
 public function execute()
 {
     $response = new \Magento\Framework\Object();
     $id = $this->getRequest()->getParam('id');
     if (intval($id) > 0) {
         $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->load($id);
         $response->setId($id);
         $response->addData($product->getData());
         $response->setError(0);
     } else {
         $response->setError(1);
         $response->setMessage(__('We can\'t get the product ID.'));
     }
     $this->getResponse()->representJson($response->toJSON());
 }
Exemplo n.º 10
0
 /**
  * Prepare category
  *
  * @param array $categoryRow
  * @return \Magento\Framework\Object
  */
 protected function _prepareCategory(array $categoryRow)
 {
     $category = new \Magento\Framework\Object();
     $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;
 }
Exemplo n.º 11
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();
     $adapter = $this->_getReadAdapter();
     if ($productIds !== null) {
         if (!is_array($productIds)) {
             $productIds = [$productIds];
         }
     }
     $bind = ['website_id' => (int) $websiteId, 'entity_id' => (int) $entityId];
     $select = $adapter->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 = $adapter->fetchAll($select, $bind);
     foreach ($rowSet as $row) {
         $product = new \Magento\Framework\Object($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 = $adapter->select()->from($this->getTable('catalog_category_product'), ['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 (['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;
 }