/** * Reports category size to the database reporting_counts table * * @return void */ protected function reportCategorySize() { $categoryCount = $this->categoryManagement->getCount(); /** @var \Magento\NewRelicReporting\Model\Counts $model */ $model = $this->countsFactory->create()->load(Config::CATEGORY_SIZE, 'type'); $this->updateCount($categoryCount, $model, Config::CATEGORY_SIZE); }
/** * Test case when module is enabled * * @return void */ public function testReportCountsTest() { $this->configMock->expects($this->once())->method('isNewRelicEnabled')->willReturn(true); $this->productManagementMock->expects($this->exactly(2))->method('getCount')->willReturn(2); $this->configurableManagementMock->expects($this->once())->method('getCount')->willReturn(2); $this->categoryManagementMock->expects($this->once())->method('getCount')->willReturn(2); $this->countsModelMock->expects($this->any())->method('getCount')->willReturn(1); $this->countsModelMock->expects($this->any())->method('setEntityId')->willReturnSelf(); $this->countsModelMock->expects($this->any())->method('setType')->willReturnSelf(); $this->countsModelMock->expects($this->any())->method('setCount')->willReturnSelf(); $this->countsModelMock->expects($this->any())->method('setUpdatedAt')->willReturnSelf(); $this->countsModelMock->expects($this->any())->method('save')->willReturnSelf(); $this->assertSame($this->model, $this->model->report()); }
/** * @param array $categoryPath * @param string $ruleType * @return array|null */ protected function getConditionFromCategory($categoryPath, $ruleType = 'Rule') { $categoryId = null; $tree = $this->categoryReadService->getTree(); foreach ($categoryPath as $categoryName) { $categoryId = null; foreach ($tree->getChildrenData() as $child) { if ($child->getName() == $categoryName) { $tree = $child; /** @var \Magento\Catalog\Api\Data\CategoryTreeInterface $child */ $categoryId = $child->getId(); break; } } } if (!$categoryId) { return null; } $types = ['Rule' => 'Magento\\TargetRule\\Model\\Rule\\Condition\\Product\\Attributes', 'Actions' => 'Magento\\TargetRule\\Model\\Actions\\Condition\\Product\\Attributes']; if (empty($types[$ruleType])) { return null; } return ['type' => $types[$ruleType], 'attribute' => 'category_ids', 'operator' => '==', 'value' => $categoryId]; }
/** * Get product category ids from array * * @param array $categories * @return array */ protected function getCategoryIds($categories) { $ids = []; $tree = $this->categoryReadService->getTree(); foreach ($categories as $name) { foreach ($tree->getChildrenData() as $child) { if ($child->getName() == $name) { /** @var \Magento\Catalog\Api\Data\CategoryTreeInterface $child */ $tree = $child; $ids[] = $child->getId(); if (!$tree->getChildrenData()) { $tree = $this->categoryReadService->getTree(); } break; } } } return $ids; }
/** * Get count of categories, minus one which is the root category * * @return int */ public function getCategoryCount() { $count = $this->categoryManagement->getCount(); return (int) $count; }
/** * Tests categories count will return int * * @return void */ public function testGetCategoryCount() { $this->categoryManagement->expects($this->once())->method('getCount')->willReturn(1); $this->assertInternalType('int', $this->model->getCategoryCount()); }