A relative clause, in normal circumstances goes directly after the noun phrase that it is modifying. If that noun phrase has a smaller noun phrase inside it at the end, then there is no grammatical way to distinguish which noun phrase it is modifying:
- ... [ the window of [ Mary's car] ], which was bought just two weeks ago
In the example above we see that there are two candidate noun phrases. Firstly there is the large one the window of Mary's car and then there is the smaller one nested inside it Mar's car. The relative clause which was bought just two weeks ago could be modifying either one. It is not possible for the reader to tell.
There is no getting round this rule, so the best strategy to disambiguate the sentence, if you don't want to change the general structure, is to change the verb. If the Original Poster used the verb replace instead of bought here, the reader would be inclined to read the relative clause as applying to the window instead of the car (just because bits of cars are more often replaced than cars themselves):
- John inadvertently broke the window of Mary's car, which had been replaced just two weeks ago.
Although this sentence does not state that Mary had to buy the window, it would be tacitly assumed by most readers that the replacement involved some kind of cost.