public function testGetAttributeById()
 {
     $this->productResource->expects($this->any())->method('loadAllAttributes')->will($this->returnValue($this->productResource));
     $this->productResource->expects($this->any())->method('getSortedAttributes')->will($this->returnValue([$this->attribute]));
     $this->attribute->setId(1);
     $this->assertEquals($this->attribute, $this->model->getAttributeById(1, $this->product));
     $this->assertNull($this->model->getAttributeById(0, $this->product));
 }
 public function testGetValue()
 {
     $this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo('regular_price'))->will($this->returnValue($this->regularPrice));
     $this->regularPrice->expects($this->once())->method('getValue')->will($this->returnValue(100));
     $this->productMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(null));
     $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(3));
     $this->productMock->expects($this->once())->method('getResource')->will($this->returnValue($this->productResourceMock));
     $this->productResourceMock->expects($this->once())->method('getAttribute')->with($this->equalTo('group_price'))->will($this->returnValue($this->attributeMock));
     $this->attributeMock->expects($this->once())->method('getBackend')->will($this->returnValue($this->backendMock));
     $this->backendMock->expects($this->once())->method('afterLoad')->with($this->equalTo($this->productMock))->will($this->returnValue($this->backendMock));
     $this->priceCurrencyMock->expects($this->never())->method('convertAndRound');
     $this->productMock->expects($this->once())->method('getData')->with($this->equalTo('group_price'), $this->equalTo(null))->will($this->returnValue([['cust_group' => 3, 'website_price' => 80]]));
     $this->assertEquals(20, $this->groupPrice->getValue());
     $this->assertEquals(20, $this->groupPrice->getValue());
 }
 /**
  * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
  */
 public function testUpdateConfigurableProductLinks()
 {
     $productId1 = 10;
     $productId2 = 20;
     $response = $this->createConfigurableProduct();
     $options = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options'];
     //leave existing option untouched
     unset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options']);
     $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links'] = [$productId1];
     $response = $this->saveProduct($response);
     $this->assertTrue(isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_options"]));
     $resultConfigurableProductOptions = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_options"];
     $this->assertEquals(1, count($resultConfigurableProductOptions));
     //Since one product is removed, the available values for the option is reduced
     $this->assertEquals(1, count($resultConfigurableProductOptions[0]['values']));
     $this->assertTrue(isset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_links"]));
     $resultConfigurableProductLinks = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]["configurable_product_links"];
     $this->assertEquals(1, count($resultConfigurableProductLinks));
     $this->assertEquals([$productId1], $resultConfigurableProductLinks);
     //adding back the product links, the option value should be restored
     unset($response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options']);
     $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_links'] = [$productId1, $productId2];
     //set the value for required attribute
     $response["custom_attributes"][] = ["attribute_code" => $this->configurableAttribute->getAttributeCode(), "value" => $resultConfigurableProductOptions[0]['values'][0]['value_index']];
     $response = $this->saveProduct($response);
     $currentOptions = $response[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['configurable_product_options'];
     $this->assertEquals($options, $currentOptions);
 }
Example #4
0
 /**
  * test get group price, customer group in session
  */
 public function testGroupPriceCustomerGroupInProduct()
 {
     $this->productMock->expects($this->exactly(2))->method('getCustomerGroupId')->will($this->returnValue(3));
     $this->productMock->expects($this->once())->method('getResource')->will($this->returnValue($this->productResourceMock));
     $this->productResourceMock->expects($this->once())->method('getAttribute')->with($this->equalTo('group_price'))->will($this->returnValue($this->attributeMock));
     $this->attributeMock->expects($this->once())->method('getBackend')->will($this->returnValue($this->backendMock));
     $this->backendMock->expects($this->once())->method('afterLoad')->with($this->equalTo($this->productMock))->will($this->returnValue($this->backendMock));
     $this->productMock->expects($this->once())->method('getData')->with($this->equalTo('group_price'), $this->equalTo(null))->will($this->returnValue([['cust_group' => 3, 'website_price' => 80]]));
     $this->assertEquals(80, $this->groupPrice->getValue());
 }
 /**
  * test get group price, customer group in session
  *
  * @param int $customerGroup
  * @dataProvider dataProviderGroupPriceCustomerGroupInProduct
  */
 public function testGroupPriceCustomerGroupInProduct($customerGroup)
 {
     $groupPrice = 80;
     $convertedPrice = 56.23;
     $this->productMock->expects($this->exactly(2))->method('getCustomerGroupId')->will($this->returnValue($customerGroup));
     $this->productMock->expects($this->once())->method('getResource')->will($this->returnValue($this->productResourceMock));
     $this->productResourceMock->expects($this->once())->method('getAttribute')->with($this->equalTo('group_price'))->will($this->returnValue($this->attributeMock));
     $this->attributeMock->expects($this->once())->method('getBackend')->will($this->returnValue($this->backendMock));
     $this->backendMock->expects($this->once())->method('afterLoad')->with($this->equalTo($this->productMock))->will($this->returnValue($this->backendMock));
     $this->productMock->expects($this->once())->method('getData')->with($this->equalTo('group_price'), $this->equalTo(null))->will($this->returnValue([['cust_group' => $customerGroup, 'website_price' => $groupPrice]]));
     $this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($groupPrice)->will($this->returnValue($convertedPrice));
     $this->assertEquals($convertedPrice, $this->groupPrice->getValue());
 }
Example #6
0
 /**
  * Check attributes has options and searchable
  *
  * @param \Magento\Catalog\Model\Entity\Attribute $attribute
  * @return boolean
  */
 protected function _hasAttributeOptionsAndSearchable($attribute)
 {
     if ($attribute->getIsSearchable() && in_array($attribute->getFrontendInput(), ['select', 'multiselect'])) {
         return true;
     }
     return false;
 }
Example #7
0
 public function testAfterSaveEavCache()
 {
     $this->configMock->expects($this->once())->method('clear');
     $this->attribute->afterSave();
 }
Example #8
0
 /**
  * Is Attribute Filterable as Term
  *
  * @param \Magento\Catalog\Model\Entity\Attribute $attribute
  * @return bool
  */
 private function isTermFilterableAttribute($attribute)
 {
     return ($attribute->getIsVisibleInAdvancedSearch() || $attribute->getIsFilterable() || $attribute->getIsFilterableInSearch()) && in_array($attribute->getFrontendInput(), ['select', 'multiselect']);
 }
 /**
  * Check whether attribute reserved or not
  *
  * @param \Magento\Catalog\Model\Entity\Attribute $attribute
  * @return boolean
  */
 public function isReservedAttribute($attribute)
 {
     return $attribute->getIsUserDefined() && in_array($attribute->getAttributeCode(), $this->_reservedAttributes);
 }
Example #10
0
 /**
  * Compare attributes sorting
  *
  * @param \Magento\Catalog\Model\Entity\Attribute $attributeOne
  * @param \Magento\Catalog\Model\Entity\Attribute $attributeTwo
  * @return int
  */
 public function attributesCompare($attributeOne, $attributeTwo)
 {
     $sortOne = $attributeOne->getGroupSortPath() * 1000 + $attributeOne->getSortPath() * 0.0001;
     $sortTwo = $attributeTwo->getGroupSortPath() * 1000 + $attributeTwo->getSortPath() * 0.0001;
     if ($sortOne > $sortTwo) {
         return 1;
     } elseif ($sortOne < $sortTwo) {
         return -1;
     }
     return 0;
 }