Breakdown of Oye, es una pena que te hayan vendido algo defectuoso.
ser
to be
un
a, an, some
que
that (relative pronoun, conjunction)
algo
something
Questions & Answers about Oye, es una pena que te hayan vendido algo defectuoso.
Why is hayan vendido in the subjunctive here?
The phrase es una pena que expresses an emotional reaction or value judgment (it is a shame that). When you express an emotion about an action involving a different subject, Spanish requires the subjunctive in the following clause.
Why use the present perfect subjunctive (hayan vendido) rather than the present subjunctive (vendan)?
The present perfect subjunctive is used because the action of selling has already been completed, but the speaker is reacting to it right now in the present. If the speaker had used vendan, it would mean they are reacting to a habitual action (it is a shame that they always sell you defective things).
Who is the subject of hayan vendido if nobody was mentioned before this?
Could the pronoun te be attached to the end of the verb instead of going before hayan?
No. In compound tenses like this one, object pronouns like te must always go immediately before the conjugated auxiliary verb (hayan). You can never attach a pronoun to a past participle like vendido.