/**
  * @param string $entityType
  * @param array $entityData
  * @return array
  * @throws \Exception
  */
 public function execute($entityType, $entityData)
 {
     $linkField = $this->metadataPool->getMetadata($entityType)->getLinkField();
     $entityId = $entityData[$linkField];
     $entityData['customer_group_ids'] = $this->ruleResource->getCustomerGroupIds($entityId);
     $entityData['website_ids'] = $this->ruleResource->getWebsiteIds($entityId);
     return $entityData;
 }
 /**
  * @magentoDataFixture Magento/CatalogRule/_files/attribute.php
  * @magentoDataFixture Magento/CatalogRule/_files/rule_by_attribute.php
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  * @magentoAppArea adminhtml
  */
 public function testReindexAfterSuitableProductSaving()
 {
     /** @var \Magento\Catalog\Model\ProductRepository $productRepository */
     $productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\ProductRepository');
     $product = $productRepository->get('simple');
     $product->setData('test_attribute', 'test_attribute_value')->save();
     $this->assertEquals(9.800000000000001, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $product->getId()));
 }
示例#3
0
 /**
  * @magentoDbIsolation enabled
  * @magentoAppIsolation enabled
  * @magentoDataFixture Magento/CatalogRule/_files/attribute.php
  * @magentoDataFixture Magento/CatalogRule/_files/rule_by_attribute.php
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testReindexFull()
 {
     $this->prepareProducts();
     $this->indexerBuilder->reindexFull();
     $this->assertEquals(9.800000000000001, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $this->product->getId()));
     $this->assertEquals(9.800000000000001, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $this->productSecond->getId()));
     $this->assertFalse($this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $this->productThird->getId()));
 }
 /**
  * @magentoDataFixture Magento/CatalogRule/_files/attribute.php
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testReindexAfterRuleCreation()
 {
     $this->product->load(1)->setData('test_attribute', 'test_attribute_value')->save();
     $this->assertFalse($this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1));
     $this->saveRule();
     // apply all rules
     $this->indexBuilder->reindexFull();
     $this->assertEquals(9.800000000000001, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1));
 }
 /**
  * {@inheritdoc}
  */
 public function delete(Data\RuleInterface $rule)
 {
     try {
         $this->ruleResource->delete($rule);
         unset($this->rules[$rule->getId()]);
     } catch (\Exception $e) {
         throw new CouldNotDeleteException(__('Unable to remove rule %1', $rule->getRuleId()));
     }
     return true;
 }
 /**
  * @magentoDbIsolation enabled
  * @dataProvider dataProvider
  */
 public function testPriceForSmallBatch($batchCount, $price, $expectedPrice)
 {
     $productIds = $this->prepareProducts($price);
     /**
      * @var IndexBuilder $indexerBuilder
      */
     $indexerBuilder = Bootstrap::getObjectManager()->create('Magento\\CatalogRule\\Model\\Indexer\\IndexBuilder', ['batchCount' => $batchCount]);
     $indexerBuilder->reindexFull();
     foreach ([0, 1] as $customerGroupId) {
         foreach ($productIds as $productId) {
             $this->assertEquals($expectedPrice, $this->resourceRule->getRulePrice(new \DateTime(), 1, $customerGroupId, $productId));
         }
     }
 }
示例#7
0
 /**
  * @param string $entityType
  * @param array $entityData
  * @param array $arguments
  * @return array
  * @throws \Exception
  */
 public function execute($entityType, $entityData, $arguments = [])
 {
     $linkField = $this->metadataPool->getMetadata($entityType)->getLinkField();
     if (isset($entityData['website_ids'])) {
         $websiteIds = $entityData['website_ids'];
         if (!is_array($websiteIds)) {
             $websiteIds = explode(',', (string) $websiteIds);
         }
         $this->ruleResource->bindRuleToEntity($entityData[$linkField], $websiteIds, 'website');
     }
     if (isset($entityData['customer_group_ids'])) {
         $customerGroupIds = $entityData['customer_group_ids'];
         if (!is_array($customerGroupIds)) {
             $customerGroupIds = explode(',', (string) $customerGroupIds);
         }
         $this->ruleResource->bindRuleToEntity($entityData[$linkField], $customerGroupIds, 'customer_group');
     }
     return $entityData;
 }
 public function testGetAmountNoBaseAmount()
 {
     $this->catalogRuleResourceMock->expects($this->once())->method('getRulePrice')->will($this->returnValue(false));
     $result = $this->object->getValue();
     $this->assertFalse($result);
 }
 /**
  * @magentoDataFixture Magento/CatalogRule/_files/attribute.php
  * @magentoDataFixture Magento/CatalogRule/_files/rule_by_attribute.php
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  * @magentoAppArea adminhtml
  */
 public function testReindexAfterSuitableProductSaving()
 {
     $this->product->load(1)->setData('test_attribute', 'test_attribute_value')->save();
     $this->assertEquals(9.800000000000001, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1));
 }