Git Product home page Git Product logo

module-example-giftitem's Introduction

Example GiftItem

This module is a basic example implementation of a gift item module. By default it simply adds a water bottle to the cart when the customer adds a product from the sample data Bags attribute set.

This module is not intended for production use, it is only example code for my presentations at MageTestFest.

Magento 2 Total Model Kata

Check out the tag beginning-of-kata to start.
Then TDD your way through the creation of the free gift item total model.

Target collect() behavior:

  • Subtract gift item row totals sum from subtotal
  • Subtract gift item base row totals sum from base subtotal
  • Set calculation_price of every gift item to 0
  • Set base_calculation_price of every gift item to 0
  • Call calcRowTotal on each item

Suggested TDD Steps

  1. Create test class
    \Example\GiftItem\Test\Unit\Model\Totals\GiftItemAddressTotalTest
  2. Rename namespace to Example\GiftItem\Model\Totals
  3. Extend \PHPUnit\Framework\TestCase
  4. Test 1: inherits abstract total model
  5. Test 2: returns zero if no items are passed
  6. Test 3: returns zero if non gift item is passed
  7. Test 4: returns gift item row total
  8. Test 5: returns sum of gift item row totals only
  9. Test 6: returns sum of gift item base row totals only
  10. Test 7: subtracts gift item total sums from subtotal
    (for both base row total and row total)
  11. Test 8: zeros gift item calculation_price and base_calculation_price
    and calculates the row total and ignores non gift items

(c) 2017 Vinai Kopp
License: BSD-3-Clause

module-example-giftitem's People

Contributors

vinai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.