public function testBindCustomerLogin() { $customer = new \Magento\Framework\DataObject(['id' => '1']); $observer = new \Magento\Framework\DataObject(['event' => new \Magento\Framework\DataObject(['customer' => $customer])]); $this->visitor->bindCustomerLogin($observer); $this->assertTrue($this->visitor->getDoCustomerLogin()); $this->assertEquals($customer->getId(), $this->visitor->getCustomerId()); $this->visitor->unsetData(); $this->visitor->setCustomerId('2'); $this->visitor->bindCustomerLogin($observer); $this->assertNull($this->visitor->getDoCustomerLogin()); $this->assertEquals('2', $this->visitor->getCustomerId()); }
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)); }
/** * 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; }
/** * Prepare product * * @param array $productRow * @param int $storeId * @return \Magento\Framework\DataObject */ protected function _prepareProduct(array $productRow, $storeId) { $product = new \Magento\Framework\DataObject(); $product['id'] = $productRow[$this->getIdFieldName()]; if (empty($productRow['url'])) { $productRow['url'] = 'catalog/product/view/id/' . $product->getId(); } $product->addData($productRow); $this->_loadProductImages($product, $storeId); return $product; }
/** * 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; }