سؤال

I am trying to run the priceCalculation test from Ecomdev_PHPUnit manual (http://www.ecomdev.org/wp-content/uploads/2011/05/EcomDev_PHPUnit-0.2.0-Manual.pdf) but I get the following error:

PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`project-XXXX_phpunit`.`catalog_product_entity`, CONSTRAINT `FK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID` FOREIGN KEY (`attribute_set_id`) REFERENCES `eav_attribute_set` (`attribu)' in /var/www/XXXX/public_html/lib/Zend/Db/Statement/Pdo.php:228

I've tried changing

eav:
  catalog_product:
    - entity_id: 1
      type_id: simple
      sku: book
      name: Book
      short_description: Book
      description: Book
      url_key: book

to:

eav:
  catalog_product:
    - entity_id: 1
      attribute_set_id: 1
      type_id: simple
      sku: book
      name: Book
      short_description: Book
      description: Book
      url_key: book

but then $product->getPrice() returns NULL and $product->getFinalPrice() returns 0.

Does anyone have any idea what I could be doing wrong or might point me in the right direction? Any help would be very much appreciated.

هل كانت مفيدة؟

المحلول

In a default Magento installation, the attribute set 1 is a customer attribute set.

mysql> SELECT attribute_set_id, entity_type_code FROM eav_attribute_set INNER JOIN eav_entity_type USING (entity_type_id);
+------------------+------------------+
| attribute_set_id | entity_type_code |
+------------------+------------------+
|                1 | customer         |
|                2 | customer_address |
|                3 | catalog_category |
|                4 | catalog_product  |
|                5 | order            |
|                6 | invoice          |
|                7 | creditmemo       |
|                8 | shipment         |
+------------------+------------------+

Changing the fixture to attribute_set_id: 4 sorted it out for me.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top